Skip to content

Commit b37b353

Browse files
author
jantje
committed
Added support to for casted parameters
1 parent 5af6afe commit b37b353

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

io.sloeber.core/src/io/sloeber/core/common/IndexHelper.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
public class IndexHelper {
2020
/**
2121
* 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 ()
2424
*
2525
* @param names
2626
* the names provided by the indexer
@@ -31,23 +31,36 @@ public class IndexHelper {
3131
*/
3232
private static String findParameterInFunction(IIndexName[] names, String function, String defaultValue) {
3333
for (IIndexName name : names) {
34-
String SetupFileName = name.getFileLocation().getFileName();
35-
String SetupFileContent;
34+
String codeFileName = name.getFileLocation().getFileName();
35+
String rawCodeFileContent;
3636
try {
37-
SetupFileContent = FileUtils.readFileToString(new File(SetupFileName));
37+
rawCodeFileContent = FileUtils.readFileToString(new File(codeFileName));
3838
} catch (IOException e) {
3939
return defaultValue;
4040
}
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);
5062
}
63+
5164
}
5265
}
5366
}

0 commit comments

Comments
 (0)