i need find java types (classe, interface, enum, annotation) in projectes' source directories of workspace, given name string. example, input "test" return java types names start "test" defined in projects source directories. tried handle jdt's searchengine follows
searchpattern pattern = searchpattern.createpattern("test", ijavasearchconstants.type, ijavasearchconstants.declarations, searchpattern.r_prefix_match); ijavasearchscope scope = searchengine.createworkspacescope(); searchrequestor requestor = new searchrequestor() { public void acceptsearchmatch(searchmatch match) { system.out.println("found: " + match.getelement()); } }; searchengine searchengine = new searchengine(); try { searchengine.search(pattern, new searchparticipant[] { searchengine .getdefaultsearchparticipant() }, scope, requestor, null); } catch (coreexception e) { e.printstacktrace(); }
the code above returned java types not in eclipse workspace. example:
found: testsimple (not open) [in testsimple.class [in <default> [in /home/me/test]]]
testsimple.java file created command line in home directory , has nothing eclipse projects. (my eclipse workspace defined in /home/me/eclipse/workspace.) not sure why included in search result? searchengine best way handle scenario, given fact need java type names, don't need inside class such field, method or reference? thanks
you want build more confined search scope, then, asking each ijavaproject of package fragment roots (ijavaproject#getallpackagefragmentroots()
) , including returning k_source
ipackagefragmentroot#getkind()
avoid getting types referenced libraries well. search on names shouldn't more hit indexes being stored. can't rely on filenames because miss inner classes entirely.
Comments
Post a Comment