Lines 38-43
Link Here
|
38 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
38 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
39 |
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
39 |
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
40 |
import org.eclipse.jdt.internal.compiler.ast.*; |
40 |
import org.eclipse.jdt.internal.compiler.ast.*; |
|
|
41 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
41 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; |
42 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; |
42 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; |
43 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; |
43 |
import org.eclipse.jdt.internal.compiler.env.*; |
44 |
import org.eclipse.jdt.internal.compiler.env.*; |
Lines 396-431
Link Here
|
396 |
} |
397 |
} |
397 |
return this.basicParser; |
398 |
return this.basicParser; |
398 |
} |
399 |
} |
399 |
/** |
|
|
400 |
* Add the possibleMatch to the loop |
401 |
* -> build compilation unit declarations, their bindings and record their results. |
402 |
*/ |
403 |
protected void parseAndBuildBindings(PossibleMatch possibleMatch, boolean mustResolve) { |
404 |
if (this.progressMonitor != null && this.progressMonitor.isCanceled()) |
405 |
throw new OperationCanceledException(); |
406 |
|
407 |
try { |
408 |
if (BasicSearchEngine.VERBOSE) |
409 |
System.out.println("Parsing " + possibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ |
410 |
|
411 |
this.parser.nodeSet = possibleMatch.nodeSet; |
412 |
CompilationResult unitResult = new CompilationResult(possibleMatch, 1, 1, this.options.maxProblemsPerUnit); |
413 |
CompilationUnitDeclaration parsedUnit = this.parser.dietParse(possibleMatch, unitResult); |
414 |
if (parsedUnit != null) { |
415 |
if (mustResolve && !parsedUnit.isEmpty()) |
416 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
417 |
|
418 |
// add the possibleMatch with its parsedUnit to matchesToProcess |
419 |
possibleMatch.parsedUnit = parsedUnit; |
420 |
int size = this.matchesToProcess.length; |
421 |
if (this.numberOfMatches == size) |
422 |
System.arraycopy(this.matchesToProcess, 0, this.matchesToProcess = new PossibleMatch[size == 0 ? 1 : size * 2], 0, this.numberOfMatches); |
423 |
this.matchesToProcess[this.numberOfMatches++] = possibleMatch; |
424 |
} |
425 |
} finally { |
426 |
this.parser.nodeSet = null; |
427 |
} |
428 |
} |
429 |
/* |
400 |
/* |
430 |
* Caches the given binary type in the lookup environment and returns it. |
401 |
* Caches the given binary type in the lookup environment and returns it. |
431 |
* Returns the existing one if already cached. |
402 |
* Returns the existing one if already cached. |
Lines 711-717
Link Here
|
711 |
protected IType getFocusType() { |
682 |
protected IType getFocusType() { |
712 |
return this.scope instanceof HierarchyScope ? ((HierarchyScope) this.scope).focusType : null; |
683 |
return this.scope instanceof HierarchyScope ? ((HierarchyScope) this.scope).focusType : null; |
713 |
} |
684 |
} |
714 |
protected void getMethodBodies(CompilationUnitDeclaration unit) { |
685 |
protected void getMethodBodies(CompilationUnitDeclaration unit, MatchingNodeSet nodeSet) { |
715 |
if (unit.ignoreMethodBodies) { |
686 |
if (unit.ignoreMethodBodies) { |
716 |
unit.ignoreFurtherInvestigation = true; |
687 |
unit.ignoreFurtherInvestigation = true; |
717 |
return; // if initial diet parse did not work, no need to dig into method bodies. |
688 |
return; // if initial diet parse did not work, no need to dig into method bodies. |
Lines 730-736
Link Here
|
730 |
char[] contents = compilationResult.compilationUnit.getContents(); |
701 |
char[] contents = compilationResult.compilationUnit.getContents(); |
731 |
this.parser.javadocParser.scanner.setSource(contents); |
702 |
this.parser.javadocParser.scanner.setSource(contents); |
732 |
} |
703 |
} |
733 |
this.parser.nodeSet = this.currentPossibleMatch.nodeSet; |
704 |
this.parser.nodeSet = nodeSet; |
734 |
this.parser.parseBodies(unit); |
705 |
this.parser.parseBodies(unit); |
735 |
} finally { |
706 |
} finally { |
736 |
this.parser.nodeSet = null; |
707 |
this.parser.nodeSet = null; |
Lines 876-897
Link Here
|
876 |
initialize(javaProject, length); |
847 |
initialize(javaProject, length); |
877 |
|
848 |
|
878 |
// create and resolve binding (equivalent to beginCompilation() in Compiler) |
849 |
// create and resolve binding (equivalent to beginCompilation() in Compiler) |
879 |
boolean mustResolve = ((InternalSearchPattern)this.pattern).mustResolve; |
850 |
boolean mustResolvePattern = ((InternalSearchPattern)this.pattern).mustResolve; |
|
|
851 |
boolean mustResolve = mustResolvePattern; |
852 |
this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5; |
880 |
boolean bindingsWereCreated = mustResolve; |
853 |
boolean bindingsWereCreated = mustResolve; |
881 |
try { |
854 |
try { |
882 |
for (int i = start, maxUnits = start + length; i < maxUnits; i++) { |
855 |
for (int i = start, maxUnits = start + length; i < maxUnits; i++) { |
883 |
PossibleMatch possibleMatch = possibleMatches[i]; |
856 |
PossibleMatch possibleMatch = possibleMatches[i]; |
884 |
try { |
857 |
try { |
885 |
parseAndBuildBindings(possibleMatch, mustResolve); |
858 |
if (!parseAndBuildBindings(possibleMatch, mustResolvePattern)) continue; |
886 |
if (!mustResolve) { |
859 |
// Currently we only need to resolve over pattern flag if there's potential parameterized types |
|
|
860 |
if (this.patternLocator.mayBeGeneric) { |
861 |
// If pattern does not resolve then rely on possible match node set resolution |
862 |
// which may have been modified while locator was adding possible matches to it |
863 |
if (!mustResolvePattern) { |
864 |
mustResolve = possibleMatch.nodeSet.mustResolve; |
865 |
bindingsWereCreated = mustResolve; |
866 |
} |
867 |
} else { |
868 |
// Reset matching node resolution with pattern one if there's no potential parameterized type |
869 |
// to minimize side effect on previous search behavior |
870 |
possibleMatch.nodeSet.mustResolve = mustResolvePattern; |
871 |
} |
872 |
// possible match node resolution has been merged with pattern one, so rely on it to know |
873 |
// whether we need to process compilation unit now or later |
874 |
if (!possibleMatch.nodeSet.mustResolve) { |
887 |
if (this.progressMonitor != null) { |
875 |
if (this.progressMonitor != null) { |
888 |
this.progressWorked++; |
876 |
this.progressWorked++; |
889 |
if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep); |
877 |
if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep); |
890 |
} |
878 |
} |
891 |
process(possibleMatch, bindingsWereCreated); |
879 |
process(possibleMatch, bindingsWereCreated); |
|
|
880 |
if (this.numberOfMatches>0 && this.matchesToProcess[this.numberOfMatches-1] == possibleMatch) { |
881 |
// forget last possible match as it was processed |
882 |
this.numberOfMatches--; |
883 |
} |
892 |
} |
884 |
} |
893 |
} finally { |
885 |
} finally { |
894 |
if (!mustResolve) |
886 |
if (!possibleMatch.nodeSet.mustResolve) |
895 |
possibleMatch.cleanUp(); |
887 |
possibleMatch.cleanUp(); |
896 |
} |
888 |
} |
897 |
} |
889 |
} |
Lines 1073-1079
Link Here
|
1073 |
} |
1065 |
} |
1074 |
previousJavaProject = javaProject; |
1066 |
previousJavaProject = javaProject; |
1075 |
} |
1067 |
} |
1076 |
matchSet.add(new PossibleMatch(this, resource, openable, searchDocument)); |
1068 |
matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, ((InternalSearchPattern) this.pattern).mustResolve)); |
1077 |
} |
1069 |
} |
1078 |
|
1070 |
|
1079 |
// last project |
1071 |
// last project |
Lines 1112-1118
Link Here
|
1112 |
IJavaElement focus = ((InternalSearchPattern) searchPattern).focus; |
1104 |
IJavaElement focus = ((InternalSearchPattern) searchPattern).focus; |
1113 |
if (focus != null) { |
1105 |
if (focus != null) { |
1114 |
SearchDocument document = participant.getDocument(focus.getPath().toString()); |
1106 |
SearchDocument document = participant.getDocument(focus.getPath().toString()); |
1115 |
this.currentPossibleMatch = new PossibleMatch(this, focus.getResource(), null, document); |
1107 |
this.currentPossibleMatch = new PossibleMatch(this, focus.getResource(), null, document, ((InternalSearchPattern) searchPattern).mustResolve); |
1116 |
if (encloses(focus)) { |
1108 |
if (encloses(focus)) { |
1117 |
SearchMatch match = newDeclarationMatch(focus.getAncestor(IJavaElement.PACKAGE_FRAGMENT), null/*no binding*/, SearchMatch.A_ACCURATE, -1, -1); |
1109 |
SearchMatch match = newDeclarationMatch(focus.getAncestor(IJavaElement.PACKAGE_FRAGMENT), null/*no binding*/, SearchMatch.A_ACCURATE, -1, -1); |
1118 |
report(match); |
1110 |
report(match); |
Lines 1153-1159
Link Here
|
1153 |
if (resource == null) // case of a file in an external jar |
1145 |
if (resource == null) // case of a file in an external jar |
1154 |
resource = javaProject.getProject(); |
1146 |
resource = javaProject.getProject(); |
1155 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
1147 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
1156 |
this.currentPossibleMatch = new PossibleMatch(this, resource, null, document); |
1148 |
this.currentPossibleMatch = new PossibleMatch(this, resource, null, document, ((InternalSearchPattern) searchPattern).mustResolve); |
1157 |
try { |
1149 |
try { |
1158 |
if (encloses(pkg)) { |
1150 |
if (encloses(pkg)) { |
1159 |
SearchMatch match = newDeclarationMatch(pkg, null/*no binding*/, SearchMatch.A_ACCURATE, -1, -1); |
1151 |
SearchMatch match = newDeclarationMatch(pkg, null/*no binding*/, SearchMatch.A_ACCURATE, -1, -1); |
Lines 1352-1357
Link Here
|
1352 |
return newTypeReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); |
1344 |
return newTypeReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); |
1353 |
} |
1345 |
} |
1354 |
|
1346 |
|
|
|
1347 |
/** |
1348 |
* Add the possibleMatch to the loop |
1349 |
* -> build compilation unit declarations, their bindings and record their results. |
1350 |
*/ |
1351 |
protected boolean parseAndBuildBindings(PossibleMatch possibleMatch, boolean mustResolve) throws CoreException { |
1352 |
if (this.progressMonitor != null && this.progressMonitor.isCanceled()) |
1353 |
throw new OperationCanceledException(); |
1354 |
|
1355 |
try { |
1356 |
if (BasicSearchEngine.VERBOSE) |
1357 |
System.out.println("Parsing " + possibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ |
1358 |
|
1359 |
this.parser.nodeSet = possibleMatch.nodeSet; |
1360 |
CompilationResult unitResult = new CompilationResult(possibleMatch, 1, 1, this.options.maxProblemsPerUnit); |
1361 |
CompilationUnitDeclaration parsedUnit = this.parser.dietParse(possibleMatch, unitResult); |
1362 |
if (parsedUnit != null) { |
1363 |
if (!parsedUnit.isEmpty()) { |
1364 |
if (mustResolve) { |
1365 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
1366 |
} |
1367 |
if (hasAlreadyDefinedType(parsedUnit)) return false; // skip type has it is hidden so not visible |
1368 |
getMethodBodies(parsedUnit, possibleMatch.nodeSet); |
1369 |
if (this.patternLocator.mayBeGeneric && !mustResolve && possibleMatch.nodeSet.mustResolve) { |
1370 |
// special case: possible match node set force resolution although pattern does not |
1371 |
// => we need to build types for this compilation unit |
1372 |
this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); |
1373 |
} |
1374 |
} |
1375 |
|
1376 |
// add the possibleMatch with its parsedUnit to matchesToProcess |
1377 |
possibleMatch.parsedUnit = parsedUnit; |
1378 |
int size = this.matchesToProcess.length; |
1379 |
if (this.numberOfMatches == size) |
1380 |
System.arraycopy(this.matchesToProcess, 0, this.matchesToProcess = new PossibleMatch[size == 0 ? 1 : size * 2], 0, this.numberOfMatches); |
1381 |
this.matchesToProcess[this.numberOfMatches++] = possibleMatch; |
1382 |
} |
1383 |
} finally { |
1384 |
this.parser.nodeSet = null; |
1385 |
} |
1386 |
return true; |
1387 |
} |
1355 |
/* |
1388 |
/* |
1356 |
* Process a compilation unit already parsed and build. |
1389 |
* Process a compilation unit already parsed and build. |
1357 |
*/ |
1390 |
*/ |
Lines 1370-1378
Link Here
|
1370 |
} |
1403 |
} |
1371 |
if (hasAlreadyDefinedType(unit)) return; // skip type has it is hidden so not visible |
1404 |
if (hasAlreadyDefinedType(unit)) return; // skip type has it is hidden so not visible |
1372 |
|
1405 |
|
1373 |
getMethodBodies(unit); |
1406 |
// Move getMethodBodies to #parseAndBuildings(...) method to allow possible match resolution management |
|
|
1407 |
//getMethodBodies(unit); |
1374 |
|
1408 |
|
1375 |
boolean mustResolve = ((InternalSearchPattern)this.pattern).mustResolve; |
1409 |
boolean mustResolve = ((InternalSearchPattern)this.pattern).mustResolve || possibleMatch.nodeSet.mustResolve; |
1376 |
if (bindingsWereCreated && mustResolve) { |
1410 |
if (bindingsWereCreated && mustResolve) { |
1377 |
if (unit.types != null) { |
1411 |
if (unit.types != null) { |
1378 |
if (BasicSearchEngine.VERBOSE) |
1412 |
if (BasicSearchEngine.VERBOSE) |
Lines 1839-1844
Link Here
|
1839 |
*/ |
1873 |
*/ |
1840 |
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException { |
1874 |
protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException { |
1841 |
MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet; |
1875 |
MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet; |
|
|
1876 |
if (nodeSet.mustResolve) this.patternLocator.mustResolve = true; |
1842 |
if (mustResolve) { |
1877 |
if (mustResolve) { |
1843 |
this.unitScope= unit.scope.compilationUnitScope(); |
1878 |
this.unitScope= unit.scope.compilationUnitScope(); |
1844 |
// move the possible matching nodes that exactly match the search pattern to the matching nodes set |
1879 |
// move the possible matching nodes that exactly match the search pattern to the matching nodes set |