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 74161 Details for
Bug 186333
[search] Should better locate fields and methods matches on binary super types with unresolved references
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Additional patch
v01.txt (text/plain), 18.92 KB, created by
Frederic Fusier
on 2007-07-19 11:05:45 EDT
(
hide
)
Description:
Additional patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2007-07-19 11:05:45 EDT
Size:
18.92 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java,v >retrieving revision 1.34 >diff -u -r1.34 ClassFileMatchLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java 18 Jul 2007 14:53:15 -0000 1.34 >+++ search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java 19 Jul 2007 13:23:02 -0000 >@@ -58,102 +58,115 @@ > if (matchBinary(pattern, info, null)) { > binaryType = new ResolvedBinaryType((JavaElement) binaryType.getParent(), binaryType.getElementName(), binaryType.getKey()); > locator.reportBinaryMemberDeclaration(null, binaryType, null, info, SearchMatch.A_ACCURATE); >+ return; > } > >- // Get methods from binary type info >+ // Define arrays to store methods/fields from binary type if necessary > IBinaryMethod[] binaryMethods = info.getMethods(); > int bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length; >- IBinaryMethod[] inaccurateMethods = new IBinaryMethod[bMethodsLength]; >+ IBinaryMethod[] unresolvedMethods = null; > char[][] binaryMethodSignatures = null; >- if (bMethodsLength > 0) { >- System.arraycopy(binaryMethods, 0, inaccurateMethods, 0, bMethodsLength); >- } >+ boolean hasUnresolvedMethods = false; > > // Get fields from binary type info > IBinaryField[] binaryFields = info.getFields(); > int bFieldsLength = binaryFields == null ? 0 : binaryFields.length; >- IBinaryField[] inaccurateFields = new IBinaryField[bFieldsLength]; >- if (bFieldsLength > 0) { >- System.arraycopy(binaryFields, 0, inaccurateFields, 0, bFieldsLength); >- } >+ IBinaryField[] unresolvedFields = null; >+ boolean hasUnresolvedFields = false; > > // Report as many accurate matches as possible >- if (((InternalSearchPattern)pattern).mustResolve) { >+ int accuracy = SearchMatch.A_ACCURATE; >+ boolean mustResolve = ((InternalSearchPattern)pattern).mustResolve; >+ if (mustResolve) { > BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info); > if (binding != null) { > // filter out element not in hierarchy scope > if (!locator.typeInHierarchy(binding)) return; > >- // Report accurate methods >+ // Search matches on resolved methods > MethodBinding[] availableMethods = binding.availableMethods(); > int aMethodsLength = availableMethods == null ? 0 : availableMethods.length; >+ hasUnresolvedMethods = bMethodsLength != aMethodsLength; > for (int i = 0; i < aMethodsLength; i++) { > MethodBinding method = availableMethods[i]; >- int level = locator.patternLocator.resolveLevel(method); > char[] methodSignature = method.genericSignature(); > if (methodSignature == null) methodSignature = method.signature(); >- switch (level) { >- case PatternLocator.ACCURATE_MATCH: >- IMethod methodHandle = binaryType.getMethod( >- new String(method.isConstructor() ? binding.compoundName[binding.compoundName.length-1] : method.selector), >- CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(methodSignature)))); >- locator.reportBinaryMemberDeclaration(null, methodHandle, method, info, SearchMatch.A_ACCURATE); >- // fall through impossible match case to remove the reported method >- case PatternLocator.IMPOSSIBLE_MATCH: >- // Store binary method signatures to avoid multiple computation >- if (binaryMethodSignatures == null) { >- binaryMethodSignatures = new char[bMethodsLength][]; >- for (int j=0; j<bMethodsLength; j++) { >- IBinaryMethod binaryMethod = binaryMethods[j]; >- char[] signature = binaryMethod.getGenericSignature(); >- if (signature == null) signature = binaryMethod.getMethodDescriptor(); >- binaryMethodSignatures[j] = signature; >- } >- } >- // The method is either accurate or impossible so remove from inaccurate methods list >+ >+ // Report the match if possible >+ int level = locator.patternLocator.resolveLevel(method); >+ if (level != PatternLocator.IMPOSSIBLE_MATCH) { >+ IMethod methodHandle = binaryType.getMethod( >+ new String(method.isConstructor() ? binding.compoundName[binding.compoundName.length-1] : method.selector), >+ CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(methodSignature)))); >+ accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE; >+ locator.reportBinaryMemberDeclaration(null, methodHandle, method, info, accuracy); >+ } >+ >+ // Remove method from unresolved list >+ if (hasUnresolvedMethods) { >+ if (binaryMethodSignatures == null) { // Store binary method signatures to avoid multiple computation >+ binaryMethodSignatures = new char[bMethodsLength][]; > for (int j=0; j<bMethodsLength; j++) { >- if (CharOperation.equals(binaryMethods[j].getSelector(), method.selector) && CharOperation.equals(binaryMethodSignatures[j], methodSignature)) { >- inaccurateMethods[j] = null; >- break; >+ IBinaryMethod binaryMethod = binaryMethods[j]; >+ char[] signature = binaryMethod.getGenericSignature(); >+ if (signature == null) signature = binaryMethod.getMethodDescriptor(); >+ binaryMethodSignatures[j] = signature; >+ } >+ } >+ for (int j=0; j<bMethodsLength; j++) { >+ if (CharOperation.equals(binaryMethods[j].getSelector(), method.selector) && CharOperation.equals(binaryMethodSignatures[j], methodSignature)) { >+ if (unresolvedMethods == null) { >+ System.arraycopy(binaryMethods, 0, unresolvedMethods = new IBinaryMethod[bMethodsLength], 0, bMethodsLength); > } >+ unresolvedMethods[j] = null; >+ break; > } >- break; >+ } > } > } > >- // Report accurate fields >+ // Search matches on resolved fields > FieldBinding[] availableFields = binding.availableFields(); > int aFieldsLength = availableFields == null ? 0 : availableFields.length; >+ hasUnresolvedFields = bFieldsLength != aFieldsLength; > for (int i = 0; i < aFieldsLength; i++) { > FieldBinding field = availableFields[i]; >+ >+ // Report the match if possible > int level = locator.patternLocator.resolveLevel(field); >- switch (level) { >- case PatternLocator.ACCURATE_MATCH: >- IField fieldHandle = binaryType.getField(new String(field.name)); >- locator.reportBinaryMemberDeclaration(null, fieldHandle, field, info, SearchMatch.A_ACCURATE); >- // fall through impossible match case to remove reported field >- case PatternLocator.IMPOSSIBLE_MATCH: >- // The field is either an accurate or impossible match, so remove it from inaccurate fields list >- for (int j=0; j<bFieldsLength; j++) { >- if ( CharOperation.equals(binaryFields[j].getName(), field.name)) { >- inaccurateFields[j] = null; >- break; >+ if (level != PatternLocator.IMPOSSIBLE_MATCH) { >+ IField fieldHandle = binaryType.getField(new String(field.name)); >+ accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE; >+ locator.reportBinaryMemberDeclaration(null, fieldHandle, field, info, accuracy); >+ } >+ >+ // Remove the field from unresolved list >+ if (hasUnresolvedFields) { >+ for (int j=0; j<bFieldsLength; j++) { >+ if ( CharOperation.equals(binaryFields[j].getName(), field.name)) { >+ if (unresolvedFields == null) { >+ System.arraycopy(binaryFields, 0, unresolvedFields = new IBinaryField[bFieldsLength], 0, bFieldsLength); > } >+ unresolvedFields[j] = null; >+ break; > } >- break; >+ } > } > } > > // If all methods/fields were accurate then returns now >- if (bMethodsLength == aMethodsLength && bFieldsLength == aFieldsLength) { >+ if (!hasUnresolvedMethods && !hasUnresolvedFields) { > return; > } > } >+ accuracy = SearchMatch.A_INACCURATE; > } > > // Report inaccurate methods >+ if (mustResolve) binaryMethods = unresolvedMethods; >+ bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length; > for (int i=0; i < bMethodsLength; i++) { >- IBinaryMethod method = inaccurateMethods[i]; >+ IBinaryMethod method = binaryMethods[i]; > if (method == null) continue; // impossible match or already reported as accurate > if (matchBinary(pattern, method, info)) { > char[] name; >@@ -175,19 +188,21 @@ > String[] parameterTypes = CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(methodSignature))); > IMethod methodHandle = binaryType.getMethod(selector, parameterTypes); > methodHandle = new ResolvedBinaryMethod(binaryType, selector, parameterTypes, methodHandle.getKey()); >- locator.reportBinaryMemberDeclaration(null, methodHandle, null, info, SearchMatch.A_INACCURATE); >+ locator.reportBinaryMemberDeclaration(null, methodHandle, null, info, accuracy); > } > } > > // Report inaccurate fields >+ if (mustResolve) binaryFields = unresolvedFields; >+ bFieldsLength = binaryFields == null ? 0 : binaryFields.length; > for (int i=0; i<bFieldsLength; i++) { >- IBinaryField field = inaccurateFields[i]; >+ IBinaryField field = binaryFields[i]; > if (field == null) continue; // impossible match or already reported as accurate > if (matchBinary(pattern, field, info)) { > String fieldName = new String(field.getName()); > IField fieldHandle = binaryType.getField(fieldName); > fieldHandle = new ResolvedBinaryField(binaryType, fieldName, fieldHandle.getKey()); >- locator.reportBinaryMemberDeclaration(null, fieldHandle, null, info, SearchMatch.A_INACCURATE); >+ locator.reportBinaryMemberDeclaration(null, fieldHandle, null, info, accuracy); > } > } > } >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v >retrieving revision 1.164 >diff -u -r1.164 JavaSearchTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 18 Jul 2007 14:53:14 -0000 1.164 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 19 Jul 2007 13:23:04 -0000 >@@ -1936,16 +1936,15 @@ > * class file. > * (Regression test for 1G4IN3E: ITPJCORE:WINNT - AbortCompilation using J9 to search for class declaration) > */ >-public void testPotentialMatchInBinary1() throws CoreException { >- IJavaProject project = this.getJavaProject("JavaSearch"); >- IClasspathEntry[] classpath = project.getRawClasspath(); >+public void testSearchFieldInBinaryWithResolution() throws CoreException { >+ IClasspathEntry[] classpath = JAVA_PROJECT.getRawClasspath(); > try { > // add AbortCompilation.jar to classpath > int length = classpath.length; > IClasspathEntry[] newClasspath = new IClasspathEntry[length+1]; > System.arraycopy(classpath, 0, newClasspath, 0, length); > newClasspath[length] = JavaCore.newLibraryEntry(new Path("/JavaSearch/AbortCompilation.jar"), null, null); >- project.setRawClasspath(newClasspath, null); >+ JAVA_PROJECT.setRawClasspath(newClasspath, null); > > // potential match for a field declaration > this.resultCollector.showAccuracy = true; >@@ -1957,7 +1956,40 @@ > ); > } finally { > // reset classpath >- project.setRawClasspath(classpath, null); >+ JAVA_PROJECT.setRawClasspath(classpath, null); >+ } >+} >+// bug 186333: Pattern which does not resolve should find all the matches exact >+public void testSearchFieldInBinaryNoResolution() throws CoreException { >+ IClasspathEntry[] classpath = JAVA_PROJECT.getRawClasspath(); >+ try { >+ // add AbortCompilation.jar to classpath >+ int length = classpath.length; >+ IClasspathEntry[] newClasspath = new IClasspathEntry[length+1]; >+ System.arraycopy(classpath, 0, newClasspath, 0, length); >+ newClasspath[length] = JavaCore.newLibraryEntry(new Path("/JavaSearch/AbortCompilation.jar"), null, null); >+ JAVA_PROJECT.setRawClasspath(newClasspath, null); >+ >+ // exact match for a field declaration >+ JavaSearchResultCollector collector = new JavaSearchResultCollector() { >+ public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { >+ IField field = (IField) searchMatch.getElement(); >+ if (field.getDeclaringType().getElementName().equals("MissingFieldType")) { >+ super.acceptSearchMatch(searchMatch); >+ } >+ } >+ }; >+ collector.showAccuracy = true; >+ search("*", FIELD, DECLARATIONS, getJavaSearchScope(), collector); >+ assertSearchResults( >+ "AbortCompilation.jar AbortCompilation.MissingFieldType.field [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar AbortCompilation.MissingFieldType.missing [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar AbortCompilation.MissingFieldType.otherField [No source] EXACT_MATCH", >+ collector >+ ); >+ } finally { >+ // reset classpath >+ JAVA_PROJECT.setRawClasspath(classpath, null); > } > } > /** >@@ -1965,16 +1997,15 @@ > * class file. > * (Regression test for 1G4IN3E: ITPJCORE:WINNT - AbortCompilation using J9 to search for class declaration) > */ >-public void testPotentialMatchInBinary2() throws CoreException { >- IJavaProject project = this.getJavaProject("JavaSearch"); >- IClasspathEntry[] classpath = project.getRawClasspath(); >+public void testSearchMethodInBinaryWithResolution() throws CoreException { >+ IClasspathEntry[] classpath = JAVA_PROJECT.getRawClasspath(); > try { > // add AbortCompilation.jar to classpath > int length = classpath.length; > IClasspathEntry[] newClasspath = new IClasspathEntry[length+1]; > System.arraycopy(classpath, 0, newClasspath, 0, length); > newClasspath[length] = JavaCore.newLibraryEntry(new Path("/JavaSearch/AbortCompilation.jar"), null, null); >- project.setRawClasspath(newClasspath, null); >+ JAVA_PROJECT.setRawClasspath(newClasspath, null); > > // potential match for a method declaration > this.resultCollector.showAccuracy = true; >@@ -1986,7 +2017,41 @@ > ); > } finally { > // reset classpath >- project.setRawClasspath(classpath, null); >+ JAVA_PROJECT.setRawClasspath(classpath, null); >+ } >+} >+// bug 186333: Pattern which does not resolve should find all the matches exact >+public void testSearchMethodInBinaryNoResolution() throws CoreException { >+ IClasspathEntry[] classpath = JAVA_PROJECT.getRawClasspath(); >+ try { >+ // add AbortCompilation.jar to classpath >+ int length = classpath.length; >+ IClasspathEntry[] newClasspath = new IClasspathEntry[length+1]; >+ System.arraycopy(classpath, 0, newClasspath, 0, length); >+ newClasspath[length] = JavaCore.newLibraryEntry(new Path("/JavaSearch/AbortCompilation.jar"), null, null); >+ JAVA_PROJECT.setRawClasspath(newClasspath, null); >+ >+ // exact match for a method declaration >+ JavaSearchResultCollector collector = new JavaSearchResultCollector() { >+ public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { >+ IMethod method = (IMethod) searchMatch.getElement(); >+ if (method.getDeclaringType().getElementName().equals("MissingArgumentType")) { >+ super.acceptSearchMatch(searchMatch); >+ } >+ } >+ }; >+ collector.showAccuracy = true; >+ search("*", METHOD, DECLARATIONS, getJavaSearchScope(), collector); >+ assertSearchResults( >+ "AbortCompilation.jar void AbortCompilation.MissingArgumentType.foo() [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar void AbortCompilation.MissingArgumentType.foo(java.util.EventListener) [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar void AbortCompilation.MissingArgumentType.foo2() [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar AbortCompilation.MissingArgumentType() [No source] EXACT_MATCH", >+ collector >+ ); >+ } finally { >+ // reset classpath >+ JAVA_PROJECT.setRawClasspath(classpath, null); > } > } > /** >@@ -1994,36 +2059,52 @@ > * class file. > * (Regression test for 1G4IN3E: ITPJCORE:WINNT - AbortCompilation using J9 to search for class declaration) > */ >-public void testPotentialMatchInBinary3() throws CoreException { >- IJavaProject project = this.getJavaProject("JavaSearch"); >- IClasspathEntry[] classpath = project.getRawClasspath(); >+public void testSearchTypesInBinaryWithResolution() throws CoreException { >+ IClasspathEntry[] classpath = JAVA_PROJECT.getRawClasspath(); > try { > // add AbortCompilation.jar to classpath > int length = classpath.length; > IClasspathEntry[] newClasspath = new IClasspathEntry[length+1]; > System.arraycopy(classpath, 0, newClasspath, 0, length); > newClasspath[length] = JavaCore.newLibraryEntry(new Path("/JavaSearch/AbortCompilation.jar"), null, null); >- project.setRawClasspath(newClasspath, null); >- >- // potential match for a type declaration >+ JAVA_PROJECT.setRawClasspath(newClasspath, null); > >+ // exact match for a type declaration > resultCollector.showAccuracy = true; >- search( >- "Missing*", >- TYPE, >- DECLARATIONS, >- getJavaSearchScope(), >- this.resultCollector); >+ search("AbortCompilation.*Missing*", TYPE, DECLARATIONS, getJavaSearchScope()); > assertSearchResults( > "AbortCompilation.jar AbortCompilation.EnclosingType$MissingEnclosingType [No source] EXACT_MATCH\n" + > "AbortCompilation.jar AbortCompilation.MissingArgumentType [No source] EXACT_MATCH\n" + >- "AbortCompilation.jar AbortCompilation.MissingFieldType [No source] EXACT_MATCH", >- this.resultCollector); >+ "AbortCompilation.jar AbortCompilation.MissingFieldType [No source] EXACT_MATCH" >+ ); > } finally { > // reset classpath >- project.setRawClasspath(classpath, null); >+ JAVA_PROJECT.setRawClasspath(classpath, null); > } > } >+public void testSearchTypeInBinaryNoResolution() throws CoreException { >+ IClasspathEntry[] classpath = JAVA_PROJECT.getRawClasspath(); >+ try { >+ // add AbortCompilation.jar to classpath >+ int length = classpath.length; >+ IClasspathEntry[] newClasspath = new IClasspathEntry[length+1]; >+ System.arraycopy(classpath, 0, newClasspath, 0, length); >+ newClasspath[length] = JavaCore.newLibraryEntry(new Path("/JavaSearch/AbortCompilation.jar"), null, null); >+ JAVA_PROJECT.setRawClasspath(newClasspath, null); >+ >+ // exact match for a type declaration >+ resultCollector.showAccuracy = true; >+ search("Missing*", TYPE, DECLARATIONS, getJavaSearchScope()); >+ assertSearchResults( >+ "AbortCompilation.jar AbortCompilation.EnclosingType$MissingEnclosingType [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar AbortCompilation.MissingArgumentType [No source] EXACT_MATCH\n" + >+ "AbortCompilation.jar AbortCompilation.MissingFieldType [No source] EXACT_MATCH" >+ ); >+ } finally { >+ // reset classpath >+ JAVA_PROJECT.setRawClasspath(classpath, null); >+ } >+} > /** > * Hierarchy scope test. > * (regression test for bug 3445 search: type hierarchy scope incorrect (1GLC8VS))
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 186333
:
74058
| 74161