开发者

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

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_EXA开发者_C百科CT_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


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


If i have rightly understood your question then this can be of help:

SearchEngine.searchAllTypeNames

This searches for all top-level types and member types in the given scope.

More info from here : http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_int_core.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜