19
19
public class IndexHelper {
20
20
/**
21
21
* given a list of names from the indexer. Find a function call and return
22
- * the parameter I assume there is only one parameter and it is a string so
23
- * there are quotes
22
+ * the parameter I assume there is only one parameter The parameter is
23
+ * considered everything between the ()
24
24
*
25
25
* @param names
26
26
* the names provided by the indexer
@@ -31,23 +31,36 @@ public class IndexHelper {
31
31
*/
32
32
private static String findParameterInFunction (IIndexName [] names , String function , String defaultValue ) {
33
33
for (IIndexName name : names ) {
34
- String SetupFileName = name .getFileLocation ().getFileName ();
35
- String SetupFileContent ;
34
+ String codeFileName = name .getFileLocation ().getFileName ();
35
+ String rawCodeFileContent ;
36
36
try {
37
- SetupFileContent = FileUtils .readFileToString (new File (SetupFileName ));
37
+ rawCodeFileContent = FileUtils .readFileToString (new File (codeFileName ));
38
38
} catch (IOException e ) {
39
39
return defaultValue ;
40
40
}
41
- SetupFileContent = SetupFileContent .replaceAll ("//.*|/\\ *((.|\\ n)(?!=*/))+\\ */" , "" ); //$NON-NLS-1$ //$NON-NLS-2$
42
- int serialBeginStart = SetupFileContent .indexOf (function );
43
- if (serialBeginStart != -1 ) {
44
- int serialBeginStartbraket = SetupFileContent .indexOf ("(" , serialBeginStart ); //$NON-NLS-1$
45
- if (serialBeginStartbraket != -1 ) {
46
- int serialBeginCloseBraket = SetupFileContent .indexOf (")" , serialBeginStartbraket ); //$NON-NLS-1$
47
- if (serialBeginCloseBraket != -1 ) {
48
- return SetupFileContent .substring (serialBeginStartbraket + 1 , serialBeginCloseBraket ).trim ();
49
-
41
+ String codeFileContent = rawCodeFileContent .replaceAll ("//.*|/\\ *((.|\\ n)(?!=*/))+\\ */" , "" ); //$NON-NLS-1$ //$NON-NLS-2$
42
+ int functionStart = codeFileContent .indexOf (function );
43
+ if (functionStart != -1 ) {
44
+ int parameterStartQuote = codeFileContent .indexOf ("(" , functionStart ); //$NON-NLS-1$
45
+ if (parameterStartQuote != -1 ) {
46
+ char [] functionParams = codeFileContent .substring (parameterStartQuote , parameterStartQuote + 30 )
47
+ .toCharArray ();
48
+ int curbrackets = 1 ;
49
+ int curchar = 1 ;
50
+ while ((curbrackets != 0 ) && (curchar < functionParams .length )) {
51
+ if (functionParams [curchar ] == ')' ) {
52
+ curbrackets --;
53
+ } else {
54
+ if (functionParams [curchar ] == '(' ) {
55
+ curbrackets ++;
56
+ }
57
+ }
58
+ curchar ++;
59
+ }
60
+ if (curbrackets == 0 ) {
61
+ return codeFileContent .substring (parameterStartQuote + 1 , parameterStartQuote + curchar - 1 );
50
62
}
63
+
51
64
}
52
65
}
53
66
}
0 commit comments