Community
Participate
Working Groups
Created attachment 84031 [details] project on which I ran my test Build ID: I20071101-2000 Steps To Reproduce: I have the following code to search for type references: IProject pr = ResourcesPlugin.getWorkspace().getRoot().getProject("Test"); IJavaProject javaP = JavaCore.create(pr); SearchEngine searchEngine = new SearchEngine(); IJavaElement[] jEls = new IJavaElement[1]; jEls[0]=javaP; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(jEls); SearchPattern pattern1 = SearchPattern.createPattern("java.lang.Deprecated", IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.REFERENCES, SearchPattern.R_EXACT_MATCH); SearchParticipant[] participats = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}; TestRequestor req = new TestRequestor(); try { searchEngine.search(pattern1, participats, scope, req, null); } catch(Exception e) { e.printStackTrace(); } List res = req.getResults(); Where TestRequestor is following public class TestRequestor extends SearchRequestor { private ArrayList resList = new ArrayList(); public void acceptSearchMatch(SearchMatch match) throws CoreException { resList.add(match); } public ArrayList getResults() { return resList; } } When I invoke it for attached project, I expect to get two matches one for @Deprecated annotation in TT2 class and one for @Deprecated annotation for TT class that is located in "tt" class folder and has no associated source. However, the search return only one match for annotation in TT2 class, which is wrong. In general it seems like Type references for "pure binary" classes are not returned by the search More information:
Search Engine is not yet able to to find references in class files which does not have attached sources, it can only find declarations (see bug 127442). As it's critical, I'll take some time to figure out if something special can be done for annotations references...
Leho, could reduce the severity of this bug as, according to the documentation (see https://bugs.eclipse.org/bugs/page.cgi?id=fields.html#bug_severity), it should be major rather than critical (there's no crash at all)... Thanks
Hi Frederic Ok, I reduced it to major. Is there any chance it can be fixed somehow (at least for searching references to annotations) in 3.4? Thanks !
I'll try to do my best :-)
Created attachment 84401 [details] Proposed patch Also include the fix for bug 211857
Created attachment 84407 [details] New proposed patch Previous patch included a change in PossibleMatch which was not 100% satistactory, so I've removed it and I will open a specific bug to describe and fix the issue in this area...
Released for 3.4M4 in HEAD stream.
Thanks a LOT Frederic ! I will give this patch a try today
Frederic, I tried your patch, but I ran into some strange issues: 1) The match that I get is for some reason TypeDeclarationMatch, not TypeReferenceMatch as I would expect it to be. 2) My code fails when my pattern is OR_PATTERN (I search for references to multiple annotation types) I looked at your code in the patch and you have this--> if (((InternalSearchPattern)pattern).kind == TYPE_REF_PATTERN) { matchAnnotations((TypeReferencePattern)pattern, locator, classFile, info); } Can you add the OR_PATTERN to this condition? Otherwise I would be forced to invoke search for about 100 times (for each annotation type I am looking for) as opposed to once -- huge inefficiency Thanks !
Created attachment 84557 [details] Additional patch OrPattern will be processed correctly with this additional patch...
Additional patch released in HEAD stream. I'll provide soon another additional patch to return TypeReferenceMatch instead of TypeDeclarationMatch...
Will you also support OR_PATTERN ? Thanks !
Sorry, missed you Comment 10 :)
Created attachment 84568 [details] Second additional patch This second additional patch fixes the wrong SearchMatch type. You'll now get TypeReferenceMatch as expected. I also added a test using a really more complex OrPattern to verify that everything was OK even with several levels of depth. This patch has been released in HEAD stream.
Verified for 3.4M4 using build I20071210-1800.