How to find anonymous class or local type using JDT Java Search Engine?

I want to programmatically get a model of an anonymous class or locally declared type (i.e. an IType instance) from the JDT Java Search Engine, known by its fully qualified name. So far, I have done well with the following when searching for "regular" 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 is it interrupted for anonymous classes and locally declared types, and how can I fix it? I suspect that I need to modify SearchPattern, but have not found anything convincing in JavaDoc.

Any recommendations are greatly appreciated.

Regards, Chris

+3
source share
2 answers

this.fullyQualifiedName ? '$' , :

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

Source: https://habr.com/ru/post/1746389/


All Articles