|
17 | 17 | import org.eclipse.core.runtime.NullProgressMonitor;
|
18 | 18 |
|
19 | 19 | 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(); |
49 | 49 |
|
50 |
| - } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
51 | 53 | }
|
52 |
| - } |
| 54 | + return defaultValue; |
| 55 | + |
53 | 56 | }
|
54 |
| - return defaultValue; |
55 | 57 |
|
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) { |
57 | 71 |
|
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()); |
71 | 73 |
|
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 | + } |
73 | 86 |
|
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 | + } |
86 | 90 |
|
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); |
90 | 92 |
|
91 |
| - IIndexName[] names = index.findNames(parentFunction, org.eclipse.cdt.core.index.IIndex.FIND_DEFINITIONS); |
| 93 | + return findParameterInFunction(names, childFunctionName, defaultValue); |
92 | 94 |
|
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 | + } |
94 | 102 |
|
95 |
| - } catch (CoreException | InterruptedException e) { |
96 |
| - e.printStackTrace(); |
97 |
| - } finally { |
98 |
| - if (index != null) { |
99 |
| - index.releaseReadLock(); |
100 |
| - } |
| 103 | + return defaultValue; |
101 | 104 | }
|
102 | 105 |
|
103 |
| - return defaultValue; |
104 |
| - } |
105 |
| - |
106 | 106 | }
|
0 commit comments