@@ -55,18 +55,16 @@ chrome.runtime.onMessage.addListener(function (msg) {
5555 }
5656 }
5757 } ) ;
58-
5958 for ( var i = 0 ; i < arrayOfBroweseableClasses . length ; i ++ ) {
6059 var clazz = arrayOfBroweseableClasses [ i ] ;
6160 // Skip line number
6261 var el = $ ( 'td[id*=LC]' + ( msg . ext === "java" ? " " : "" ) + ':contains(' + clazz . className + ')' ) ;
6362 for ( var j = 0 ; j < el . length ; j ++ ) {
64- var code = $ ( el [ j ] ) . text ( ) ;
65-
66- // The workaround for Kotlin highlights imports too. Skip them, both Kotlin and Java (faster loop)
67- if ( code . startsWith ( "import " ) ) continue ;
6863
6964 if ( msg . ext === "java" ) {
65+ var code = $ ( el [ j ] ) . text ( ) ;
66+ if ( code . startsWith ( "import " ) ) continue ;
67+
7068 var result = code . match ( REGEX_VALID_USAGE_OF_CLASS_NAME ) ;
7169 if ( result ) {
7270 if ( ~ code . indexOf ( 'List' ) || ~ code . indexOf ( 'ArrayList' ) || ~ code . indexOf ( 'Set' ) || ~ code . indexOf ( 'Iterator' ) ) {
@@ -77,26 +75,34 @@ chrome.runtime.onMessage.addListener(function (msg) {
7775 }
7876 }
7977 } else if ( msg . ext === "kt" ) {
78+ var codeHtml = $ ( el [ j ] ) . html ( ) ;
79+ var codeText = $ ( el [ j ] ) . text ( ) ;
80+
8081 /*
8182 Workaround for Kotlin. It gets the first char of a class (first index); it checks if before the class name there's another char, if true skip this line;
8283 it calculates the used length, adding to the first index, the length of class name, plus a special char (like . ( < >).
8384 At the end it checks if the substring matches with a valid usage of class name, so replace it with the URL
8485 */
85- var index = code . indexOf ( clazz . className ) ;
86- switch ( code . charAt ( index - 1 ) ) {
86+ var indexHtml = codeHtml . indexOf ( clazz . className ) ;
87+ var indexText = codeText . indexOf ( clazz . className ) ;
88+
89+ switch ( codeText . charAt ( indexText - 1 ) ) {
8790 case "<" :
91+ case ">" :
8892 case " " :
8993 case "(" :
9094 break ;
9195 default :
9296 continue ;
9397 }
9498
95- var classUsage = index + clazz . className . length + 1 ;
96- var result = code . substr ( index , classUsage ) . match ( REGEX_VALID_USAGE_OF_CLASS_NAME ) ;
99+ var classUsage = indexHtml + clazz . className . length + 1 ;
100+ if ( codeHtml . charAt ( classUsage - 1 ) >= 'A' || 'Z' <= codeHtml . charAt ( classUsage - 1 ) ) continue ;
101+
102+ var result = codeHtml . substr ( indexHtml , classUsage ) . match ( REGEX_VALID_USAGE_OF_CLASS_NAME ) ;
97103
98104 if ( result ) {
99- $ ( el [ j ] ) . html ( code . replaceBetween ( index , classUsage - 1 , '<a href=\"' + clazz . getLinkedUrl ( ) + '\" target=\"_blank\">' + clazz . className + '</a>' ) ) ;
105+ $ ( el [ j ] ) . html ( codeHtml . replaceBetween ( indexHtml , classUsage - 1 , '<a href=\"' + clazz . getLinkedUrl ( ) + '\" target=\"_blank\">' + clazz . className + '</a>' ) ) ;
100106 }
101107 }
102108 }
0 commit comments