How to search class with short name or keywords in project?

Answered

 I want to search class qualified name with short name or keywords like code completion in project , and I use this code:

AllClassesSearch.search(ProjectScope.getAllScope(project),project).filtering(p-> p.getName().equals("RequestMapping") && p.getClassKind() == JvmClassKind.ANNOTATION)

It's has two problem:

  • 1 - It's so slowly.
  • 2 - The result  isn't contains  java moudle class.

What shoud i do ?

3 comments
Comment actions Permalink

Hi,

Please take a look at com.intellij.psi.search.PsiShortNamesCache.

I don't understand what you mean by "The results isn't contains java module class", so please clarify if the issue still remains.

0
Comment actions Permalink

Hi Karol,

thank you for your help.

I have used PsiShortNamesCache.processClassesWithName.

PsiShortNamesCache.getInstance(project).processClassesWithName("Exception", p -> {
list.add(p.getQualifiedName());
return true;
}, ProjectScope.getEverythingScope(project), null);

When I search for Exception / List , the result is empty and cannot return java.lang.Exception / java.util.List .

 That's what "The results isn't contains java module class" means.

 

 

0
Comment actions Permalink

Hi,
Did you try to use different scopes, e.g. GlobalScope.allScope(project)?
Also, make sure that JDK is correctly set up, and Java classes are resolved in a project you invoke this code in.

0

Please sign in to leave a comment.