类com.intellij.psi.search.searches.AnnotatedElementsSearch源码实例Demo

下面列出了怎么用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<>();
	}
}
 
源代码2 项目: camel-idea-plugin   文件: JavaClassUtils.java
/**
 * 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();
}
 
源代码3 项目: Intellij-Plugin   文件: StepUtil.java
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<>();
}
 
 类所在包
 同包方法