Bug 211366 - [search] does not return references to types in binary classes
Summary: [search] does not return references to types in binary classes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 major with 3 votes (vote)
Target Milestone: 3.4 M4   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-28 20:59 EST by Leho Nigul CLA
Modified: 2007-12-12 11:23 EST (History)
3 users (show)

See Also:


Attachments
project on which I ran my test (1.51 KB, application/x-zip-compressed)
2007-11-28 20:59 EST, Leho Nigul CLA
no flags Details
Proposed patch (15.55 KB, application/octet-stream)
2007-12-04 05:55 EST, Frederic Fusier CLA
no flags Details
New proposed patch (15.42 KB, application/octet-stream)
2007-12-04 07:30 EST, Frederic Fusier CLA
no flags Details
Additional patch (5.73 KB, patch)
2007-12-05 13:45 EST, Frederic Fusier CLA
no flags Details | Diff
Second additional patch (9.39 KB, patch)
2007-12-05 16:10 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Leho Nigul CLA 2007-11-28 20:59:05 EST
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:
Comment 1 Frederic Fusier CLA 2007-11-29 02:57:34 EST
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...
Comment 2 Frederic Fusier CLA 2007-11-29 05:10:04 EST
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
Comment 3 Leho Nigul CLA 2007-11-29 07:44:59 EST
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 !
Comment 4 Frederic Fusier CLA 2007-11-29 09:13:07 EST
I'll try to do my best :-)
Comment 5 Frederic Fusier CLA 2007-12-04 05:55:23 EST
Created attachment 84401 [details]
Proposed patch

Also include the fix for bug 211857
Comment 6 Frederic Fusier CLA 2007-12-04 07:30:15 EST
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...
Comment 7 Frederic Fusier CLA 2007-12-04 07:30:54 EST
Released for 3.4M4 in HEAD stream.
Comment 8 Leho Nigul CLA 2007-12-04 09:12:46 EST
Thanks a LOT Frederic !
I will give this patch a try today
Comment 9 Leho Nigul CLA 2007-12-04 18:16:20 EST
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 !
Comment 10 Frederic Fusier CLA 2007-12-05 13:45:02 EST
Created attachment 84557 [details]
Additional patch

OrPattern will be processed correctly with this additional patch...
Comment 11 Frederic Fusier CLA 2007-12-05 13:51:29 EST
Additional patch released in HEAD stream.

I'll provide soon another additional patch to return TypeReferenceMatch instead of TypeDeclarationMatch...
Comment 12 Leho Nigul CLA 2007-12-05 13:56:16 EST
Will you also support OR_PATTERN ?

Thanks ! 
Comment 13 Leho Nigul CLA 2007-12-05 13:57:15 EST
Sorry, missed you Comment 10 :)
Comment 14 Frederic Fusier CLA 2007-12-05 16:10:16 EST
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.
Comment 15 David Audel CLA 2007-12-12 09:40:07 EST
Verified for 3.4M4 using build I20071210-1800.