views:

29

answers:

1

Hi,

I want to programmatically get the model of an anonymous class or locally declared type (i.e. an instance of IType) from the JDT Java Search Engine, known by fully qualified name. So far, I did well with the following when searching for "usual" types that were not nested in other types:

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);

Why does it break for anonymous classes and locally declared types, and how can I fix it? I suspect, I have to change the SearchPattern, but found nothing conclusive in the JavaDoc.

Any advise is highly appreciated.

Regards, Chris

A: 

What this.fullyQualifiedName contains for anonymous or inner classes? Try to use '$' as a scope separator when building a fully qualified name of a class, like this:

a.b.c.Outer$Inner
a.b.c.Outer$1 // anonymous
spektom