Skip to content

Commit 5af6afe

Browse files
author
jantje
committed
formatting changed
1 parent 55edbe5 commit 5af6afe

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

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

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,90 +17,90 @@
1717
import org.eclipse.core.runtime.NullProgressMonitor;
1818

1919
public class IndexHelper {
20-
/**
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
24-
*
25-
* @param names
26-
* the names provided by the indexer
27-
* @param function
28-
* the name of the function for which we are looking for a
29-
* parameter
30-
* @return the string or defaultValue if no string is found
31-
*/
32-
private static String findParameterInFunction(IIndexName[] names, String function, String defaultValue) {
33-
for (IIndexName name : names) {
34-
String SetupFileName = name.getFileLocation().getFileName();
35-
String SetupFileContent;
36-
try {
37-
SetupFileContent = FileUtils.readFileToString(new File(SetupFileName));
38-
} catch (IOException e) {
39-
return defaultValue;
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();
20+
/**
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
24+
*
25+
* @param names
26+
* the names provided by the indexer
27+
* @param function
28+
* the name of the function for which we are looking for a
29+
* parameter
30+
* @return the string or defaultValue if no string is found
31+
*/
32+
private static String findParameterInFunction(IIndexName[] names, String function, String defaultValue) {
33+
for (IIndexName name : names) {
34+
String SetupFileName = name.getFileLocation().getFileName();
35+
String SetupFileContent;
36+
try {
37+
SetupFileContent = FileUtils.readFileToString(new File(SetupFileName));
38+
} catch (IOException e) {
39+
return defaultValue;
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();
4949

50-
}
50+
}
51+
}
52+
}
5153
}
52-
}
54+
return defaultValue;
55+
5356
}
54-
return defaultValue;
5557

56-
}
58+
/**
59+
* given a project look in the source code for the line of code that sets
60+
* the password;
61+
*
62+
*
63+
*
64+
* return the password string of no_pwd_found_in_code
65+
*
66+
* @param iProject
67+
* @return
68+
*/
69+
public static String findParameterInFunction(IProject project, String parentFunctionName, String childFunctionName,
70+
String defaultValue) {
5771

58-
/**
59-
* given a project look in the source code for the line of code that sets
60-
* the password;
61-
*
62-
*
63-
*
64-
* return the password string of no_pwd_found_in_code
65-
*
66-
* @param iProject
67-
* @return
68-
*/
69-
public static String findParameterInFunction(IProject project, String parentFunctionName, String childFunctionName,
70-
String defaultValue) {
72+
ICProject curProject = CoreModel.getDefault().getCModel().getCProject(project.getName());
7173

72-
ICProject curProject = CoreModel.getDefault().getCModel().getCProject(project.getName());
74+
IIndex index = null;
75+
try {
76+
index = CCorePlugin.getIndexManager().getIndex(curProject);
77+
index.acquireReadLock();
78+
IIndexBinding[] bindings = index.findBindings(parentFunctionName.toCharArray(), IndexFilter.ALL_DECLARED,
79+
new NullProgressMonitor());
80+
ICPPFunction parentFunction = null;
81+
for (IIndexBinding curbinding : bindings) {
82+
if (curbinding instanceof ICPPFunction) {
83+
parentFunction = (ICPPFunction) curbinding;
84+
}
85+
}
7386

74-
IIndex index = null;
75-
try {
76-
index = CCorePlugin.getIndexManager().getIndex(curProject);
77-
index.acquireReadLock();
78-
IIndexBinding[] bindings = index.findBindings(parentFunctionName.toCharArray(), IndexFilter.ALL_DECLARED,
79-
new NullProgressMonitor());
80-
ICPPFunction parentFunction = null;
81-
for (IIndexBinding curbinding : bindings) {
82-
if (curbinding instanceof ICPPFunction) {
83-
parentFunction = (ICPPFunction) curbinding;
84-
}
85-
}
87+
if (parentFunction == null) {
88+
return defaultValue;// that on found binding must be a function
89+
}
8690

87-
if (parentFunction == null) {
88-
return defaultValue;// that on found binding must be a function
89-
}
91+
IIndexName[] names = index.findNames(parentFunction, org.eclipse.cdt.core.index.IIndex.FIND_DEFINITIONS);
9092

91-
IIndexName[] names = index.findNames(parentFunction, org.eclipse.cdt.core.index.IIndex.FIND_DEFINITIONS);
93+
return findParameterInFunction(names, childFunctionName, defaultValue);
9294

93-
return findParameterInFunction(names, childFunctionName, defaultValue);
95+
} catch (CoreException | InterruptedException e) {
96+
e.printStackTrace();
97+
} finally {
98+
if (index != null) {
99+
index.releaseReadLock();
100+
}
101+
}
94102

95-
} catch (CoreException | InterruptedException e) {
96-
e.printStackTrace();
97-
} finally {
98-
if (index != null) {
99-
index.releaseReadLock();
100-
}
103+
return defaultValue;
101104
}
102105

103-
return defaultValue;
104-
}
105-
106106
}

0 commit comments

Comments
 (0)