Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 22619 Details for
Bug 96761
[1.5][search] Search for declarations of generic method finds non-overriding method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch implementing fix for both this bug and bug 96763
v02.txt (text/plain), 31.73 KB, created by
Frederic Fusier
on 2005-06-08 12:33:40 EDT
(
hide
)
Description:
Patch implementing fix for both this bug and bug 96763
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2005-06-08 12:33:40 EDT
Size:
31.73 KB
patch
obsolete
>Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v >retrieving revision 1.246 >diff -u -r1.246 MatchLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 18 May 2005 14:45:17 -0000 1.246 >+++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 8 Jun 2005 14:36:15 -0000 >@@ -39,6 +39,7 @@ > import org.eclipse.jdt.internal.compiler.CompilationResult; > import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; > import org.eclipse.jdt.internal.compiler.ast.*; >+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; > import org.eclipse.jdt.internal.compiler.env.*; >@@ -401,36 +402,6 @@ > } > return this.basicParser; > } >-/** >- * Add the possibleMatch to the loop >- * -> build compilation unit declarations, their bindings and record their results. >- */ >-protected void parseAndBuildBindings(PossibleMatch possibleMatch, boolean mustResolve) { >- if (this.progressMonitor != null && this.progressMonitor.isCanceled()) >- throw new OperationCanceledException(); >- >- try { >- if (BasicSearchEngine.VERBOSE) >- System.out.println("Parsing " + possibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ >- >- this.parser.nodeSet = possibleMatch.nodeSet; >- CompilationResult unitResult = new CompilationResult(possibleMatch, 1, 1, this.options.maxProblemsPerUnit); >- CompilationUnitDeclaration parsedUnit = this.parser.dietParse(possibleMatch, unitResult); >- if (parsedUnit != null) { >- if (mustResolve && !parsedUnit.isEmpty()) >- this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); >- >- // add the possibleMatch with its parsedUnit to matchesToProcess >- possibleMatch.parsedUnit = parsedUnit; >- int size = this.matchesToProcess.length; >- if (this.numberOfMatches == size) >- System.arraycopy(this.matchesToProcess, 0, this.matchesToProcess = new PossibleMatch[size == 0 ? 1 : size * 2], 0, this.numberOfMatches); >- this.matchesToProcess[this.numberOfMatches++] = possibleMatch; >- } >- } finally { >- this.parser.nodeSet = null; >- } >-} > /* > * Caches the given binary type in the lookup environment and returns it. > * Returns the existing one if already cached. >@@ -732,7 +703,7 @@ > protected IType getFocusType() { > return this.scope instanceof HierarchyScope ? ((HierarchyScope) this.scope).focusType : null; > } >-protected void getMethodBodies(CompilationUnitDeclaration unit) { >+protected void getMethodBodies(CompilationUnitDeclaration unit, MatchingNodeSet nodeSet) { > if (unit.ignoreMethodBodies) { > unit.ignoreFurtherInvestigation = true; > return; // if initial diet parse did not work, no need to dig into method bodies. >@@ -751,7 +722,7 @@ > char[] contents = compilationResult.compilationUnit.getContents(); > this.parser.javadocParser.scanner.setSource(contents); > } >- this.parser.nodeSet = this.currentPossibleMatch.nodeSet; >+ this.parser.nodeSet = nodeSet; > this.parser.parseBodies(unit); > } finally { > this.parser.nodeSet = null; >@@ -776,31 +747,32 @@ > this.bindings.put(typeKey, typeBinding); > return typeBinding.isValidBinding() ? typeBinding : null; > } >-public MethodBinding getMethodBinding(IMethod method) { >+public MethodBinding getMethodBinding(MethodPattern methodPattern) { > if (this.unitScope == null) return null; > // Try to get binding from cache >- Binding binding = (Binding) this.bindings.get(method); >+ Binding binding = (Binding) this.bindings.get(methodPattern); > if (binding != null) { > if (binding instanceof MethodBinding && binding.isValidBinding()) > return (MethodBinding) binding; > return null; > } > // Get binding from unit scope >- String typeName = method.getDeclaringType().getElementName(); >- TypeBinding declaringTypeBinding = getType(typeName, typeName.toCharArray()); >+ char[] typeName = PatternLocator.qualifiedPattern(methodPattern.declaringSimpleName, methodPattern.declaringQualification); >+ if (typeName == null) { >+ if (methodPattern.declaringType == null) return null; >+ typeName = methodPattern.declaringType.getFullyQualifiedName().toCharArray(); >+ } >+ TypeBinding declaringTypeBinding = getType(typeName, typeName); > if (declaringTypeBinding != null) { > if (declaringTypeBinding.isArrayType()) { > declaringTypeBinding = declaringTypeBinding.leafComponentType(); > } > if (!declaringTypeBinding.isBaseType()) { >- String[] parameterTypes = method.getParameterTypes(); >+ char[][] parameterTypes = methodPattern.parameterSimpleNames; >+ if (parameterTypes == null) return null; > int paramTypeslength = parameterTypes.length; >- char[][] paramTypesChars = new char[paramTypeslength][]; >- for (int i=0; i<paramTypeslength; i++) { >- paramTypesChars[i] = Signature.toCharArray(parameterTypes[i].toCharArray()); >- } > ReferenceBinding referenceBinding = (ReferenceBinding) declaringTypeBinding; >- MethodBinding[] methods = referenceBinding.getMethods(method.getElementName().toCharArray()); >+ MethodBinding[] methods = referenceBinding.getMethods(methodPattern.selector); > int methodsLength = methods.length; > TypeVariableBinding[] refTypeVariables = referenceBinding.typeVariables(); > int typeVarLength = refTypeVariables==null ? 0 : refTypeVariables.length; >@@ -809,42 +781,43 @@ > int paramLength = methodParameters==null ? 0 : methodParameters.length; > TypeVariableBinding[] methodTypeVariables = methods[i].typeVariables; > int methTypeVarLength = methodTypeVariables==null ? 0 : methodTypeVariables.length; >- boolean found = paramLength == paramTypeslength; >- if (found) { >- for (int p=0; found && p<paramLength; p++) { >- if (CharOperation.equals(methodParameters[p].erasure().shortReadableName(), paramTypesChars[p])) { >+ boolean found = false; >+ if (paramLength == paramTypeslength) { >+ for (int p=0; p<paramLength; p++) { >+ if (CharOperation.equals(methodParameters[p].erasure().shortReadableName(), parameterTypes[p])) { > // param erasure match >+ found = true; > } else { > // type variable >- boolean foundVar = true; >- for (int v=0; foundVar && v<typeVarLength; v++) { >- if (!CharOperation.equals(refTypeVariables[v].sourceName, paramTypesChars[p])) { >- foundVar = false; >+ found = false; >+ for (int v=0; v<typeVarLength; v++) { >+ if (!CharOperation.equals(refTypeVariables[v].sourceName, parameterTypes[p])) { >+ found = false; >+ break; > } >+ found = true; > } >- if (!foundVar) { >- foundVar = true; >- for (int v=0; foundVar && v<methTypeVarLength; v++) { >- if (!CharOperation.equals(methodTypeVariables[v].sourceName, paramTypesChars[p])) { >- foundVar = false; >+ if (!found) { >+ for (int v=0; v<methTypeVarLength; v++) { >+ if (!CharOperation.equals(methodTypeVariables[v].sourceName, parameterTypes[p])) { >+ found = false; >+ break; > } >+ found = true; > } >- if (!foundVar) found = false; > } >+ if (!found) break; > } > } > } > if (found) { >- this.bindings.put(method, methods[i]); >+ this.bindings.put(methodPattern, methods[i]); > return methods[i]; > } > } >-// methodBinding = referenceBinding.getExactMethod(method.getElementName().toCharArray(), parameters); >-// this.bindings.put(method, methodBinding); >-// return methodBinding; > } > } >- this.bindings.put(method, new ProblemMethodBinding(method.getElementName().toCharArray(), null, ProblemReasons.NotFound)); >+ this.bindings.put(methodPattern, new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound)); > return null; > } > protected boolean hasAlreadyDefinedType(CompilationUnitDeclaration parsedUnit) { >@@ -897,22 +870,43 @@ > initialize(javaProject, length); > > // create and resolve binding (equivalent to beginCompilation() in Compiler) >- boolean mustResolve = ((InternalSearchPattern)this.pattern).mustResolve; >+ boolean mustResolvePattern = ((InternalSearchPattern)this.pattern).mustResolve; >+ boolean mustResolve = mustResolvePattern; >+ this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5; > boolean bindingsWereCreated = mustResolve; > try { > for (int i = start, maxUnits = start + length; i < maxUnits; i++) { > PossibleMatch possibleMatch = possibleMatches[i]; > try { >- parseAndBuildBindings(possibleMatch, mustResolve); >- if (!mustResolve) { >+ if (!parseAndBuildBindings(possibleMatch, mustResolvePattern)) continue; >+ // Currently we only need to resolve over pattern flag if there's potential parameterized types >+ if (this.patternLocator.mayBeGeneric) { >+ // If pattern does not resolve then rely on possible match node set resolution >+ // which may have been modified while locator was adding possible matches to it >+ if (!mustResolvePattern && !mustResolve) { >+ mustResolve = possibleMatch.nodeSet.mustResolve; >+ bindingsWereCreated = mustResolve; >+ } >+ } else { >+ // Reset matching node resolution with pattern one if there's no potential parameterized type >+ // to minimize side effect on previous search behavior >+ possibleMatch.nodeSet.mustResolve = mustResolvePattern; >+ } >+ // possible match node resolution has been merged with pattern one, so rely on it to know >+ // whether we need to process compilation unit now or later >+ if (!possibleMatch.nodeSet.mustResolve) { > if (this.progressMonitor != null) { > this.progressWorked++; > if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep); > } > process(possibleMatch, bindingsWereCreated); >+ if (this.numberOfMatches>0 && this.matchesToProcess[this.numberOfMatches-1] == possibleMatch) { >+ // forget last possible match as it was processed >+ this.numberOfMatches--; >+ } > } > } finally { >- if (!mustResolve) >+ if (!possibleMatch.nodeSet.mustResolve) > possibleMatch.cleanUp(); > } > } >@@ -1094,7 +1088,7 @@ > } > previousJavaProject = javaProject; > } >- matchSet.add(new PossibleMatch(this, resource, openable, searchDocument)); >+ matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, ((InternalSearchPattern) this.pattern).mustResolve)); > } > > // last project >@@ -1133,7 +1127,7 @@ > IJavaElement focus = ((InternalSearchPattern) searchPattern).focus; > if (focus != null) { > SearchDocument document = participant.getDocument(focus.getPath().toString()); >- this.currentPossibleMatch = new PossibleMatch(this, focus.getResource(), null, document); >+ this.currentPossibleMatch = new PossibleMatch(this, focus.getResource(), null, document, ((InternalSearchPattern) searchPattern).mustResolve); > if (encloses(focus)) { > SearchMatch match = newDeclarationMatch(focus.getAncestor(IJavaElement.PACKAGE_FRAGMENT), null/*no binding*/, SearchMatch.A_ACCURATE, -1, -1); > report(match); >@@ -1174,7 +1168,7 @@ > if (resource == null) // case of a file in an external jar > resource = javaProject.getProject(); > SearchDocument document = participant.getDocument(resource.getFullPath().toString()); >- this.currentPossibleMatch = new PossibleMatch(this, resource, null, document); >+ this.currentPossibleMatch = new PossibleMatch(this, resource, null, document, ((InternalSearchPattern) searchPattern).mustResolve); > try { > if (encloses(pkg)) { > SearchMatch match = newDeclarationMatch(pkg, null/*no binding*/, SearchMatch.A_ACCURATE, -1, -1); >@@ -1373,6 +1367,47 @@ > return newTypeReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); > } > >+/** >+ * Add the possibleMatch to the loop >+ * -> build compilation unit declarations, their bindings and record their results. >+ */ >+protected boolean parseAndBuildBindings(PossibleMatch possibleMatch, boolean mustResolve) throws CoreException { >+ if (this.progressMonitor != null && this.progressMonitor.isCanceled()) >+ throw new OperationCanceledException(); >+ >+ try { >+ if (BasicSearchEngine.VERBOSE) >+ System.out.println("Parsing " + possibleMatch.openable.toStringWithAncestors()); //$NON-NLS-1$ >+ >+ this.parser.nodeSet = possibleMatch.nodeSet; >+ CompilationResult unitResult = new CompilationResult(possibleMatch, 1, 1, this.options.maxProblemsPerUnit); >+ CompilationUnitDeclaration parsedUnit = this.parser.dietParse(possibleMatch, unitResult); >+ if (parsedUnit != null) { >+ if (!parsedUnit.isEmpty()) { >+ if (mustResolve) { >+ this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); >+ } >+ if (hasAlreadyDefinedType(parsedUnit)) return false; // skip type has it is hidden so not visible >+ getMethodBodies(parsedUnit, possibleMatch.nodeSet); >+ if (this.patternLocator.mayBeGeneric && !mustResolve && possibleMatch.nodeSet.mustResolve) { >+ // special case: possible match node set force resolution although pattern does not >+ // => we need to build types for this compilation unit >+ this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); >+ } >+ } >+ >+ // add the possibleMatch with its parsedUnit to matchesToProcess >+ possibleMatch.parsedUnit = parsedUnit; >+ int size = this.matchesToProcess.length; >+ if (this.numberOfMatches == size) >+ System.arraycopy(this.matchesToProcess, 0, this.matchesToProcess = new PossibleMatch[size == 0 ? 1 : size * 2], 0, this.numberOfMatches); >+ this.matchesToProcess[this.numberOfMatches++] = possibleMatch; >+ } >+ } finally { >+ this.parser.nodeSet = null; >+ } >+ return true; >+} > /* > * Process a compilation unit already parsed and build. > */ >@@ -1391,9 +1426,10 @@ > } > if (hasAlreadyDefinedType(unit)) return; // skip type has it is hidden so not visible > >- getMethodBodies(unit); >+ // Move getMethodBodies to #parseAndBuildings(...) method to allow possible match resolution management >+ //getMethodBodies(unit); > >- boolean mustResolve = ((InternalSearchPattern)this.pattern).mustResolve; >+ boolean mustResolve = ((InternalSearchPattern)this.pattern).mustResolve || possibleMatch.nodeSet.mustResolve; > if (bindingsWereCreated && mustResolve) { > if (unit.types != null) { > if (BasicSearchEngine.VERBOSE) >@@ -1773,7 +1809,7 @@ > if (encloses(enclosingElement)) { > int length = scanner.currentPosition - nameSourceStart; > SearchMatch match = this.patternLocator.newDeclarationMatch(method, enclosingElement, method.binding, accuracy, length, this); >- report(match); >+ if (match != null) report(match); > } > } > } >@@ -1868,6 +1904,8 @@ > */ > protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException { > MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet; >+ boolean locatorMustResolve = this.patternLocator.mustResolve; >+ if (nodeSet.mustResolve) this.patternLocator.mustResolve = true; > if (mustResolve) { > this.unitScope= unit.scope.compilationUnitScope(); > // move the possible matching nodes that exactly match the search pattern to the matching nodes set >@@ -1950,6 +1988,8 @@ > > // Clear handle cache > this.methodHandles = null; >+ this.bindings.removeKey(this.pattern); >+ this.patternLocator.mustResolve = locatorMustResolve; > } > /** > * Visit the given field declaration and report the nodes that match exactly the >Index: search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java,v >retrieving revision 1.29 >diff -u -r1.29 MatchingNodeSet.java >--- search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java 23 Feb 2005 02:47:46 -0000 1.29 >+++ search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java 8 Jun 2005 14:36:15 -0000 >@@ -36,12 +36,23 @@ > static Integer ERASURE_MATCH = new Integer(SearchPattern.R_ERASURE_MATCH); > > /** >+ * Tell whether locators need to resolve or not for current matching node set. >+ */ >+public boolean mustResolve; >+ >+/** > * Set of possible matching ast nodes. They need to be resolved > * to determine if they really match the search pattern. > */ > SimpleSet possibleMatchingNodesSet = new SimpleSet(7); > private HashtableOfLong possibleMatchingNodesKeys = new HashtableOfLong(7); > >+ >+public MatchingNodeSet(boolean mustResolvePattern) { >+ super(); >+ mustResolve = mustResolvePattern; >+} >+ > public int addMatch(ASTNode node, int matchLevel) { > switch (matchLevel) { > case PatternLocator.INACCURATE_MATCH: >Index: search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java,v >retrieving revision 1.53 >diff -u -r1.53 MethodLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 6 Jun 2005 08:09:08 -0000 1.53 >+++ search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 8 Jun 2005 14:36:16 -0000 >@@ -49,6 +49,64 @@ > // inaccurate matches will be found > } > } >+/* >+ * Return whether a method may override a method in super classes erasures or not. >+ */ >+private boolean isErasureMethodOverride(ReferenceBinding type, MethodBinding method) { >+ if (type == null) return false; >+ >+ // matches superclass >+ if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { >+ ReferenceBinding superClass = type.superclass(); >+ if (superClass.isParameterizedType()) { >+ TypeBinding erasure = ((ParameterizedTypeBinding)superClass).erasure(); >+ if (erasure instanceof ReferenceBinding) { >+ MethodBinding[] methods = superClass.getMethods(this.pattern.selector); >+ int length = methods.length; >+ for (int i = 0; i<length; i++) { >+ if (methods[i].areParametersEqual(method)) return true; >+ } >+ } >+ } >+ if (isErasureMethodOverride(superClass, method)) { >+ return true; >+ } >+ } >+ >+ // matches interfaces >+ ReferenceBinding[] interfaces = type.superInterfaces(); >+ if (interfaces == null) return false; >+ int iLength = interfaces.length; >+ for (int i = 0; i<iLength; i++) { >+ if (interfaces[i].isParameterizedType()) { >+ TypeBinding erasure = ((ParameterizedTypeBinding)interfaces[i]).erasure(); >+ if (erasure instanceof ReferenceBinding) { >+ MethodBinding[] methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector); >+ int length = methods.length; >+ for (int j = 0; j<length; j++) { >+ if (methods[i].areParametersEqual(method)) return true; >+ } >+ } >+ } >+ if (isErasureMethodOverride(interfaces[i], method)) { >+ return true; >+ } >+ } >+ return false; >+} >+/* >+ * Return whether a type name is in pattern all super declaring types names. >+ */ >+private boolean isTypeInSuperDeclaringTypeNames(char[][] typeName) { >+ if (allSuperDeclaringTypeNames == null) return false; >+ int length = allSuperDeclaringTypeNames.length; >+ for (int i= 0; i<length; i++) { >+ if (CharOperation.equals(allSuperDeclaringTypeNames[i], typeName)) { >+ return true; >+ } >+ } >+ return false; >+} > /** > * Returns whether the code gen will use an invoke virtual for > * this message send or not. >@@ -85,16 +143,20 @@ > if (!matchesName(this.pattern.selector, node.selector)) return IMPOSSIBLE_MATCH; > > // Verify parameters types >+ boolean resolve = ((InternalSearchPattern)this.pattern).mustResolve; > if (this.pattern.parameterSimpleNames != null) { > int length = this.pattern.parameterSimpleNames.length; > ASTNode[] args = node.arguments; > int argsLength = args == null ? 0 : args.length; > if (length != argsLength) return IMPOSSIBLE_MATCH; >- // Disable filter on argument syntax to allow generic type search. >- // (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990) >- if (!this.pattern.mustResolveGeneric) { >- for (int i = 0; i < argsLength; i++) { >- if (!matchesTypeReference(this.pattern.parameterSimpleNames[i], ((Argument) args[i]).type)) return IMPOSSIBLE_MATCH; >+ for (int i = 0; i < argsLength; i++) { >+ if (!matchesTypeReference(this.pattern.parameterSimpleNames[i], ((Argument) args[i]).type)) { >+ if (!((InternalSearchPattern)this.pattern).mustResolve) { >+ // Set resolution flag on node set in case of types was inferred in parameterized types from generic ones... >+ // (see bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763) >+ nodeSet.mustResolve = true; >+ resolve = true; >+ } > } > } > } >@@ -105,7 +167,7 @@ > } > > // Method declaration may match pattern >- return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); >+ return nodeSet.addMatch(node, resolve ? POSSIBLE_MATCH : ACCURATE_MATCH); > } > public int match(MemberValuePair node, MatchingNodeSet nodeSet) { > if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; >@@ -163,7 +225,7 @@ > super.matchLevelAndReportImportRef(importRef, binding, locator); > } > } >-protected int matchMethod(MethodBinding method) { >+protected int matchMethod(MethodBinding method, boolean skipImpossibleArg) { > if (!matchesName(this.pattern.selector, method.selector)) return IMPOSSIBLE_MATCH; > > int level = ACCURATE_MATCH; >@@ -205,10 +267,13 @@ > } > if (level > newLevel) { > if (newLevel == IMPOSSIBLE_MATCH) { >-// if (isErasureMatch) { >-// return ERASURE_MATCH; >-// } >- return IMPOSSIBLE_MATCH; >+ if (skipImpossibleArg) { >+ // Do not consider match as impossible while finding declarations and source level >= 1.5 >+ // (see bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763) >+ newLevel = level; >+ } else { >+ return IMPOSSIBLE_MATCH; >+ } > } > level = newLevel; // can only be downgraded > } >@@ -218,54 +283,6 @@ > return level; > } > /** >- * Return if pattern method may override a method in super classes >- * or or implement one in super interfaces of given type. >- * @param type >- * @return level >- */ >-int matchOverriddenMethod(ReferenceBinding type) { >- if (type == null) return INACCURATE_MATCH; >- int level = IMPOSSIBLE_MATCH; >- >- // matches superclass >- if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { >- if (type.superclass().isParameterizedType()) { >- TypeBinding erasure = ((ParameterizedTypeBinding)type.superclass()).erasure(); >- if (erasure instanceof ReferenceBinding) { >- MethodBinding[] methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector); >- int length = methods.length; >- for (int i = 0; i<length && level == IMPOSSIBLE_MATCH; i++) { >- level = matchMethod(methods[i]); >- } >- if (level != IMPOSSIBLE_MATCH) return level; >- } >- } >- level = matchOverriddenMethod(type.superclass()); >- if (level != IMPOSSIBLE_MATCH) return level; >- } >- >- // matches interfaces >- ReferenceBinding[] interfaces = type.superInterfaces(); >- if (interfaces == null) return INACCURATE_MATCH; >- int iLength = interfaces.length; >- for (int i = 0; i<iLength; i++) { >- if (interfaces[i].isParameterizedType()) { >- TypeBinding erasure = ((ParameterizedTypeBinding)interfaces[i]).erasure(); >- if (erasure instanceof ReferenceBinding) { >- MethodBinding[] methods = ((ReferenceBinding)erasure).getMethods(this.pattern.selector); >- int mLength = methods.length; >- for (int j = 0; j<mLength && level == IMPOSSIBLE_MATCH; j++) { >- level = matchMethod(methods[j]); >- } >- if (level != IMPOSSIBLE_MATCH) return level; >- } >- } >- level = matchOverriddenMethod(interfaces[i]); >- if (level != IMPOSSIBLE_MATCH) return level; >- } >- return IMPOSSIBLE_MATCH; >-} >-/** > * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator) > */ > protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { >@@ -387,6 +404,38 @@ > protected int referenceType() { > return IJavaElement.METHOD; > } >+public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, int length, MatchLocator locator) { >+ if (elementBinding != null) { >+ MethodBinding methodBinding = (MethodBinding) elementBinding; >+ // Redo arguments verif as in this case previous filter may accept different ones >+ boolean equals = true; >+ if (this.pattern.parameterSimpleNames != null) { >+ int paramLength = this.pattern.parameterSimpleNames.length; >+ for (int i=0; equals && i<paramLength; i++) { >+ int level = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], methodBinding.parameters[i]); >+ if (level == IMPOSSIBLE_MATCH) equals = false; >+ } >+ } >+ // If arguments are not equals then try to see if method arguments can match erasures in hierarchy >+ if (!equals && this.pattern.findDeclarations && this.mayBeGeneric) { >+ if (isErasureMethodOverride(methodBinding.declaringClass, methodBinding)) { >+ return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator); >+ } >+ if (isTypeInSuperDeclaringTypeNames(methodBinding.declaringClass.compoundName)) { >+ MethodBinding patternBinding = locator.getMethodBinding(this.pattern); >+ if (patternBinding != null) { >+ patternBinding = patternBinding.original(); >+ if (!isErasureMethodOverride(patternBinding.declaringClass, patternBinding)) { >+ return null; >+ } >+ } >+ return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator); >+ } >+ return null; >+ } >+ } >+ return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator); >+} > protected void reportDeclaration(MethodBinding methodBinding, MatchLocator locator, SimpleSet knownMethods) throws CoreException { > ReferenceBinding declaringClass = methodBinding.declaringClass; > IType type = locator.lookupType(declaringClass); >@@ -463,14 +512,12 @@ > if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH; > > MethodBinding method = (MethodBinding) binding; >- int methodLevel = matchMethod(method); >+ boolean skipVerif = this.pattern.findDeclarations && this.mayBeGeneric; >+ int methodLevel = matchMethod(method, skipVerif); > if (methodLevel == IMPOSSIBLE_MATCH) { >- if (method != method.original()) methodLevel = matchMethod(method.original()); >+ if (method != method.original()) methodLevel = matchMethod(method.original(), skipVerif); > if (methodLevel == IMPOSSIBLE_MATCH) { >- if (this.pattern.findDeclarations && this.pattern.mustResolveGeneric) { >- methodLevel = matchOverriddenMethod(method.declaringClass); >- } >- if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; >+ return IMPOSSIBLE_MATCH; > } else { > method = method.original(); > } >@@ -503,9 +550,9 @@ > return IMPOSSIBLE_MATCH; > } > >- int methodLevel = matchMethod(method); >+ int methodLevel = matchMethod(method, false); > if (methodLevel == IMPOSSIBLE_MATCH) { >- if (method != method.original()) methodLevel = matchMethod(method.original()); >+ if (method != method.original()) methodLevel = matchMethod(method.original(), false); > if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; > method = method.original(); > } >Index: search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java,v >retrieving revision 1.52 >diff -u -r1.52 MethodPattern.java >--- search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java 14 May 2005 14:45:28 -0000 1.52 >+++ search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java 8 Jun 2005 14:36:16 -0000 >@@ -36,7 +36,6 @@ > public char[][] parameterSimpleNames; > public int parameterCount; > public int flags = 0; >-public boolean mustResolveGeneric = false; > > // extra reference info > protected IType declaringType; >@@ -181,28 +180,6 @@ > // Store type signatures and arguments for method > methodArguments = extractMethodArguments(method); > if (hasMethodArguments()) ((InternalSearchPattern)this).mustResolve = true; >- >- // See if we must resolve specifically for generics >- if (parameterSimpleNames != null && parameterSimpleNames.length > 0) { >- int psLength = parameterSimpleNames.length; >- try { >- // Currently, we need to resolve for generic if one of method type argument >- // equals to one of declaring type type parameter >- ITypeParameter[] typeParameters = this.declaringType.getTypeParameters(); >- if (typeParameters != null && typeParameters.length > 0) { >- int tpLength = typeParameters.length; >- for (int i=0; i<psLength && !this.mustResolveGeneric; i++) { >- for (int j=0; j<tpLength && !this.mustResolveGeneric; j++) { >- if (CharOperation.equals(parameterSimpleNames[i], typeParameters[j].getElementName().toCharArray())) { >- this.mustResolveGeneric = true; >- } >- } >- } >- } >- } catch (JavaModelException e) { >- // ignore >- } >- } > } > /* > * Instanciate a method pattern with signatures for generics search >Index: search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java,v >retrieving revision 1.46 >diff -u -r1.46 PatternLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 25 Apr 2005 16:23:02 -0000 1.46 >+++ search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 8 Jun 2005 14:36:16 -0000 >@@ -26,6 +26,7 @@ > protected boolean isEquivalentMatch; > protected boolean isErasureMatch; > protected boolean mustResolve; >+protected boolean mayBeGeneric; > > // match to report > SearchMatch match = null; >Index: search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java,v >retrieving revision 1.21 >diff -u -r1.21 PossibleMatch.java >--- search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java 15 Mar 2005 17:07:56 -0000 1.21 >+++ search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java 8 Jun 2005 14:36:17 -0000 >@@ -33,11 +33,11 @@ > private String sourceFileName; > private char[] source; > >-public PossibleMatch(MatchLocator locator, IResource resource, Openable openable, SearchDocument document) { >+public PossibleMatch(MatchLocator locator, IResource resource, Openable openable, SearchDocument document, boolean mustResolve) { > this.resource = resource; > this.openable = openable; > this.document = document; >- this.nodeSet = new MatchingNodeSet(); >+ this.nodeSet = new MatchingNodeSet(mustResolve); > char[] qualifiedName = getQualifiedName(); > if (qualifiedName != null) > this.compoundName = CharOperation.splitOn('.', qualifiedName);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 96761
: 22619