Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Using the Search Engine to find an anonymous class
Using the Search Engine to find an anonymous class [message #534751] Thu, 20 May 2010 08:54 Go to next message
Chris  is currently offline Chris Friend
Messages: 44
Registered: April 2010
Member
Hi,

I want to find an anonymous class which I know by fully qualified name using the Java Search Engine. I tried the following, but it would not work for anonymous or any "normal" nested type:

SearchPattern pattern = SearchPattern.createPattern(this.fullyQualifiedName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
SearchRequestor requestor = new TypeSearchRequestor(this);
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, scope, requestor, null);


The TypeSearchRequestor does not get called in this setup for anonymous and nested classes. The code works fine however for any type, not nested in another.

What am I doing wrong here? Thanks for any insights you can offer.

Regards,
Chris
Re: Using the Search Engine to find an anonymous class [message #535962 is a reply to message #534751] Wed, 26 May 2010 13:45 Go to previous messageGo to next message
Chris  is currently offline Chris Friend
Messages: 44
Registered: April 2010
Member
Sadly, noone seems to have an answer to my OP. So there is the following workaround (which in fact has a lot of nice other properties):

Instead of using the fully qualified name, one can use the handle identifier. Then retrieving it from JDT is a piece of cake in all cases:

IJavaElement jdtData = JavaCore.create(this.handleIdentifier);


Not knowing this did cost me two days of stumbling around in circles Confused. Gladly I dared to peak into the JDT source code.

Hope this helps other JDT noobies, too.

Regards,
Chris
Re: Using the Search Engine to find an anonymous class [message #539562 is a reply to message #535962] Fri, 11 June 2010 10:17 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Chris wrote:
> Sadly, noone seems to have an answer to my OP. So there is the
> following workaround (which in fact has a lot of nice other properties):
>
> Instead of using the fully qualified name, one can use the handle
> identifier. Then retrieving it from JDT is a piece of cake in all cases:
>
> IJavaElement jdtData = JavaCore.create(this.handleIdentifier);
This is not the right approach (don't fiddle around with handles) and it
wont find all anonymous classes of a given type. What you need to do, is
search the type REFERENCES to that type and then test
match.getElement().isAnonymous().

Dani
>
> Not knowing this did cost me two days of stumbling around in circles
> :?. Gladly I dared to peak into the JDT source code.
>
> Hope this helps other JDT noobies, too.
>
> Regards,
> Chris
Re: Using the Search Engine to find an anonymous class [message #540698 is a reply to message #539562] Thu, 17 June 2010 05:58 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
Instead of using the fully qualified name, using the name of the inner class should work.
Re: Using the Search Engine to find an anonymous class [message #630738 is a reply to message #539562] Mon, 04 October 2010 18:03 Go to previous message
Faith Jansson is currently offline Faith JanssonFriend
Messages: 1
Registered: October 2010
Junior Member
I'm so glad I found this answer. The same thing has been bugging me. Thanks so much!
Previous Topic:refactor ----CopyParticipant failed problem
Next Topic:[GlassFish] Problem installing GlassFish server on Eclipse
Goto Forum:
  


Current Time: Fri Apr 26 09:04:30 GMT 2024

Powered by FUDForum. Page generated in 0.03887 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top