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 24462 Details for
Bug 100772
[1.5][search] Search for declarations in hierarchy reports too many matches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Complete patch to fix this issue
v02.txt (text/plain), 17.00 KB, created by
Frederic Fusier
on 2005-07-08 07:11:08 EDT
(
hide
)
Description:
Complete patch to fix this issue
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2005-07-08 07:11:08 EDT
Size:
17.00 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.249 >diff -u -r1.249 MatchLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 15 Jun 2005 06:30:08 -0000 1.249 >+++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 8 Jul 2005 09:42:55 -0000 >@@ -790,7 +790,7 @@ > boolean found = false; > if (paramLength == paramTypeslength) { > for (int p=0; p<paramLength; p++) { >- if (CharOperation.equals(methodParameters[p].erasure().shortReadableName(), parameterTypes[p])) { >+ if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) { > // param erasure match > found = true; > } else { >@@ -1912,13 +1912,18 @@ > */ > 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 (BasicSearchEngine.VERBOSE) { > System.out.println("Report matching: "); //$NON-NLS-1$ >- System.out.println(" - node set:\n"+nodeSet); //$NON-NLS-1$ >- System.out.println(" - must resolve: "+mustResolve); //$NON-NLS-1$ >+ int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.elementSize; >+ System.out.print(" - node set: accurate="+ size); //$NON-NLS-1$ >+ size = nodeSet.possibleMatchingNodesSet==null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize; >+ System.out.println(", possible="+size); //$NON-NLS-1$ >+ System.out.print(" - must resolve: "+mustResolve); //$NON-NLS-1$ >+ System.out.print(" (locator: "+this.patternLocator.mustResolve); //$NON-NLS-1$ >+ System.out.println(", nodeSet: "+nodeSet.mustResolve+')'); //$NON-NLS-1$ > } >- 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 >@@ -1941,7 +1946,10 @@ > } > nodeSet.possibleMatchingNodesSet = new SimpleSet(3); > if (BasicSearchEngine.VERBOSE) { >- System.out.println(" - resolved node set:\n"+nodeSet); //$NON-NLS-1$ >+ int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.elementSize; >+ System.out.print(" - node set: accurate="+size); //$NON-NLS-1$ >+ size = nodeSet.possibleMatchingNodesSet==null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize; >+ System.out.println(", possible="+size); //$NON-NLS-1$ > } > } else { > this.unitScope = null; >@@ -2006,6 +2014,7 @@ > this.methodHandles = null; > this.bindings.removeKey(this.pattern); > this.patternLocator.mustResolve = locatorMustResolve; >+ this.patternLocator.clear(); > } > /** > * Visit the given field declaration and report the nodes that match exactly the >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.56 >diff -u -r1.56 MethodLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 15 Jun 2005 06:30:08 -0000 1.56 >+++ search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 8 Jul 2005 09:42:56 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core.search.matching; > >+import java.util.HashMap; >+ > import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.*; > import org.eclipse.jdt.core.*; >@@ -29,12 +31,21 @@ > //extra reference info > public char[][][] allSuperDeclaringTypeNames; > >+//method declarations which parameters verification fail >+private HashMap methodDeclarationsWithInvalidParam = new HashMap(); >+ > public MethodLocator(MethodPattern pattern) { > super(pattern); > > this.pattern = pattern; > this.isDeclarationOfReferencedMethodsPattern = this.pattern instanceof DeclarationOfReferencedMethodsPattern; > } >+/* >+ * Clear caches >+ */ >+protected void clear() { >+ this.methodDeclarationsWithInvalidParam = new HashMap(); >+} > public void initializePolymorphicSearch(MatchLocator locator) { > try { > this.allSuperDeclaringTypeNames = >@@ -50,51 +61,6 @@ > } > } > /* >- * 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) { >@@ -159,6 +125,7 @@ > nodeSet.mustResolve = true; > resolve = true; > } >+ this.methodDeclarationsWithInvalidParam.put(node, null); > } else { > return IMPOSSIBLE_MATCH; > } >@@ -287,6 +254,54 @@ > > return level; > } >+private boolean matchOverriddenMethod(ReferenceBinding type, MethodBinding method, MethodBinding matchMethod) { >+ 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()) { >+ MethodBinding[] methods = superClass.getMethods(this.pattern.selector); >+ int length = methods.length; >+ for (int i = 0; i<length; i++) { >+ if (methods[i].areParametersEqual(method)) { >+ if (matchMethod == null) { >+ if (methodParametersEqualsPattern(methods[i].original())) return true; >+ } else { >+ if (methods[i].original().areParametersEqual(matchMethod)) return true; >+ } >+ } >+ } >+ } >+ if (matchOverriddenMethod(superClass, method, matchMethod)) { >+ 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()) { >+ MethodBinding[] methods = interfaces[i].getMethods(this.pattern.selector); >+ int length = methods.length; >+ for (int j = 0; j<length; j++) { >+ if (methods[i].areParametersEqual(method)) { >+ if (matchMethod == null) { >+ if (methodParametersEqualsPattern(methods[i].original())) return true; >+ } else { >+ if (methods[i].original().areParametersEqual(matchMethod)) return true; >+ } >+ } >+ } >+ } >+ if (matchOverriddenMethod(interfaces[i], method, matchMethod)) { >+ return true; >+ } >+ } >+ return false; >+} > /** > * @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) > */ >@@ -406,41 +421,60 @@ > locator.report(match); > } > } >-protected int referenceType() { >- return IJavaElement.METHOD; >+/* >+ * Return whether method parameters are equals to pattern ones. >+ */ >+private boolean methodParametersEqualsPattern(MethodBinding method) { >+ TypeBinding[] methodParameters = method.parameters; >+ >+ int length = methodParameters.length; >+ if (length != this.pattern.parameterSimpleNames.length) return false; >+ >+ for (int i = 0; i < length; i++) { >+ char[] paramQualifiedName = qualifiedPattern(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i]); >+ if (!CharOperation.match(paramQualifiedName, methodParameters[i].readableName(), this.isCaseSensitive)) { >+ return false; >+ } >+ } >+ return true; > } > 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 method parameters verification was not valid, then try to see if method arguments can match a method in hierarchy >+ if (this.methodDeclarationsWithInvalidParam.containsKey(reference)) { >+ // First see if this reference has already been resolved => report match if validated >+ Boolean report = (Boolean) this.methodDeclarationsWithInvalidParam.get(reference); >+ if (report != null) { >+ if (report.booleanValue()) { >+ return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator); >+ } >+ return null; > } >- } >- // 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)) { >+ if (matchOverriddenMethod(methodBinding.declaringClass, methodBinding, null)) { >+ this.methodDeclarationsWithInvalidParam.put(reference, Boolean.TRUE); > 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)) { >+ if (!matchOverriddenMethod(patternBinding.declaringClass, patternBinding, methodBinding)) { >+ this.methodDeclarationsWithInvalidParam.put(reference, Boolean.FALSE); > return null; > } > } >+ this.methodDeclarationsWithInvalidParam.put(reference, Boolean.TRUE); > return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator); > } >+ this.methodDeclarationsWithInvalidParam.put(reference, Boolean.FALSE); > return null; > } > } > return super.newDeclarationMatch(reference, element, elementBinding, accuracy, length, locator); > } >+protected int referenceType() { >+ return IJavaElement.METHOD; >+} > protected void reportDeclaration(MethodBinding methodBinding, MatchLocator locator, SimpleSet knownMethods) throws CoreException { > ReferenceBinding declaringClass = methodBinding.declaringClass; > IType type = locator.lookupType(declaringClass); >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.47 >diff -u -r1.47 PatternLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 8 Jun 2005 16:53:08 -0000 1.47 >+++ search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 8 Jul 2005 09:42:56 -0000 >@@ -107,6 +107,12 @@ > this.matchMode = matchRule & JavaSearchPattern.MATCH_MODE_MASK; > this.mustResolve = ((InternalSearchPattern)pattern).mustResolve; > } >+/* >+ * Clear caches >+ */ >+protected void clear() { >+ // nothing to clear by default >+} > /* (non-Javadoc) > * Modify PatternLocator.qualifiedPattern behavior: > * do not add star before simple name pattern when qualification pattern is null. >@@ -651,7 +657,6 @@ > int impossible = this.isErasureMatch ? ERASURE_MATCH : IMPOSSIBLE_MATCH; > > // pattern has type parameter(s) or type argument(s) >- boolean isRawType = type.isRawType(); > if (type.isGenericType()) { > // Binding is generic, get its type variable(s) > TypeVariableBinding[] typeVariables = null; >@@ -669,14 +674,16 @@ > } > // TODO (frederic) do we need to verify each parameter? > return level; // we can't do better >- } else if (isRawType) { >+ } else if (type.isRawType()) { > return level; // raw type always match >- } else if (!type.isParameterizedType()) { >- // Standard types (ie. neither generic nor parameterized nor raw types) >- // cannot match pattern with type parameters or arguments >- return (patternTypeArguments[depth]==null || patternTypeArguments[depth].length==0) ? level : IMPOSSIBLE_MATCH; > } else { >- ParameterizedTypeBinding paramTypeBinding = (ParameterizedTypeBinding) type; >+ TypeBinding leafType = type.leafComponentType(); >+ if (!leafType.isParameterizedType()) { >+ // Standard types (ie. neither generic nor parameterized nor raw types) >+ // cannot match pattern with type parameters or arguments >+ return (patternTypeArguments[depth]==null || patternTypeArguments[depth].length==0) ? level : IMPOSSIBLE_MATCH; >+ } >+ ParameterizedTypeBinding paramTypeBinding = (ParameterizedTypeBinding) leafType; > > // Compare arguments only if there ones on both sides > if (patternTypeArguments[depth] != null && patternTypeArguments[depth].length > 0 && >@@ -765,31 +772,21 @@ > // If pattern is not exact then match fails > if (patternTypeArgHasAnyChars) return impossible; > >- // Get reference binding >- ReferenceBinding refBinding = null; >- if (argTypeBinding.isArrayType()) { >- TypeBinding leafBinding = ((ArrayBinding) argTypeBinding).leafComponentType; >- if (!leafBinding.isBaseType()) { >- refBinding = (ReferenceBinding) leafBinding; >- } >- } else if (!argTypeBinding.isBaseType()) { >- refBinding = (ReferenceBinding) argTypeBinding; >- } > // Scan hierarchy >- if (refBinding != null) { >- refBinding = refBinding.superclass(); >- while (refBinding != null) { >- if (CharOperation.equals(patternTypeArgument, refBinding.shortReadableName(), this.isCaseSensitive) || >- CharOperation.equals(patternTypeArgument, refBinding.readableName(), this.isCaseSensitive)) { >- // found name in hierarchy => match >+ TypeBinding leafTypeBinding = argTypeBinding.leafComponentType(); >+ if (leafTypeBinding.isBaseType()) return impossible; >+ ReferenceBinding refBinding = ((ReferenceBinding) leafTypeBinding).superclass(); >+ while (refBinding != null) { >+ if (CharOperation.equals(patternTypeArgument, refBinding.shortReadableName(), this.isCaseSensitive) || >+ CharOperation.equals(patternTypeArgument, refBinding.readableName(), this.isCaseSensitive)) { >+ // found name in hierarchy => match >+ continue nextTypeArgument; >+ } else if (refBinding.isLocalType() || refBinding.isMemberType()) { >+ // for local or member type, verify also source name (bug 81084) >+ if (CharOperation.match(patternTypeArgument, refBinding.sourceName(), this.isCaseSensitive)) > continue nextTypeArgument; >- } else if (refBinding.isLocalType() || refBinding.isMemberType()) { >- // for local or member type, verify also source name (bug 81084) >- if (CharOperation.match(patternTypeArgument, refBinding.sourceName(), this.isCaseSensitive)) >- continue nextTypeArgument; >- } >- refBinding = refBinding.superclass(); > } >+ refBinding = refBinding.superclass(); > } > return impossible; > }
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 100772
:
23641
| 24462 |
24463
|
24476
|
24477