下面列出了怎么用com.intellij.psi.search.searches.AnnotatedElementsSearch的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Create a search pattern for the given <code>annotationName</code> annotation
* name.
*
* @param annotationName the annotation name to search.
* @return a search pattern for the given <code>annotationName</code> annotation
* name.
*/
protected static Query<PsiModifierListOwner> createAnnotationTypeReferenceSearchPattern(SearchContext context, String annotationName) {
PsiClass annotationClass = context.getUtils().findClass(context.getModule(), annotationName);
if (annotationClass != null) {
return AnnotatedElementsSearch.searchElements(annotationClass, context.getScope(), PsiModifierListOwner.class);
} else {
return new EmptyQuery<>();
}
}
/**
* Return a list of {@link PsiClass}s annotated with the specified annotation
* @param project - Project reference to narrow the search inside.
* @param annotation - the full qualify annotation name to search for
* @return a list of classes annotated with the specified annotation.
*/
@NotNull
private Collection<PsiClass> getClassesAnnotatedWith(Project project, String annotation) {
PsiClass stepClass = JavaPsiFacade.getInstance(project).findClass(annotation, ProjectScope.getLibrariesScope(project));
if (stepClass != null) {
final Query<PsiClass> psiMethods = AnnotatedElementsSearch.searchPsiClasses(stepClass, GlobalSearchScope.allScope(project));
return psiMethods.findAll();
}
return Collections.emptyList();
}
public static Collection<PsiMethod> getStepMethods(Module module) {
final PsiClass step = JavaPsiFacade.getInstance(module.getProject()).findClass("com.thoughtworks.gauge.Step", GlobalSearchScope.allScope(module.getProject()));
if (step != null) {
Collection<PsiMethod> methods = new ArrayList<>();
for (Module m : Gauge.getSubModules(module))
methods.addAll(AnnotatedElementsSearch.searchPsiMethods(step, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(m, true)).findAll());
return methods;
}
return new ArrayList<>();
}