| Summary: | [search] JDT search does not locate binary subclasses when IJavaSearchConstants.IMPLEMENTORS is used | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Kim Tsao <ktsao> | ||||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | srikanth_sankaran | ||||||
| Version: | 4.4 | ||||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows 7 | ||||||||
| Whiteboard: | stalebug | ||||||||
| Attachments: |
|
||||||||
Created attachment 245313 [details]
plugin testcase
Created attachment 245314 [details]
project testcase
To reproduce: 1. In a new Eclipse workspace (I have eclipse-standard-luna-RC3-win32), import the plugin from TestProj.zip. 2. Create a new run configuration with the defaults and launch 3. Import Proj.zip into the new workspace. Invoke the "JDT Search > Search for subclasses" menu option. This action displays the result of the search, which is "x.y.z.C" 4. In TestProj, I have the code snippet commented out that creates the SuperTypeReferencePattern directly. You can uncomment this (and comment out the SearchPattern code) and test again. The results will show both "x.y.z.C" and "subclasses.B". moving out of 4.6 This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
I have a Java project that is set up with a classpath jar which contains an abstract class called "lib.A" and a class called "subclasses.B" which extends "lib.A". The project also has a source class called "x.y.z.C" which extends "lib.A". When I use JDT search with the following SearchPattern: SearchPattern searchPattern = SearchPattern.createPattern("lib.A", IJavaSearchConstants.TYPE, IJavaSearchConstants.IMPLEMENTORS, SearchPattern.R_CASE_SENSITIVE); The only result I get back is the source class "x.y.z.C". I did some investigation and found that when the constant IJavaSearchConstants.IMPLEMENTORS is specified, org.eclipse.jdt.core.search.SearchPattern creates a SuperTypeReferencePattern and sets the superRefKind flag as SuperTypeReferencePattern.ONLY_SUPER_INTERFACES. The ClassFileMatchLocator class is eventually used to determine a match on the binary class and only searches for super interfaces rather than super classes. i.e. boolean matchSuperTypeReference(SuperTypeReferencePattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!(binaryInfo instanceof IBinaryType)) return false; IBinaryType type = (IBinaryType) binaryInfo; if (pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_INTERFACES) { char[] vmName = type.getSuperclassName(); if (vmName != null) { char[] superclassName = convertClassFileFormat(vmName); if (checkTypeName(pattern.superSimpleName, pattern.superQualification, superclassName, pattern.isCaseSensitive(), pattern.isCamelCase())) return true; } } if (pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_CLASSES) { char[][] superInterfaces = type.getInterfaceNames(); if (superInterfaces != null) { for (int i = 0, max = superInterfaces.length; i < max; i++) { char[] superInterfaceName = convertClassFileFormat(superInterfaces[i]); if (checkTypeName(pattern.superSimpleName, pattern.superQualification, superInterfaceName, pattern.isCaseSensitive(), pattern.isCamelCase())) return true; } } } return false; } I searched the org.eclipse.jdt.core.search.SearchPattern class and could not find any instance where SuperTypeReferencePattern.ONLY_SUPER_CLASSES was used. My only option was to create the SuperTypeReferencePattern (which is discouraged because it's non-API): SuperTypeReferencePattern searchPattern = new SuperTypeReferencePattern("lib".toCharArray(), "A".toCharArray(), SuperTypeReferencePattern.ONLY_SUPER_CLASSES, SearchPattern.R_CASE_SENSITIVE);