本文整理匯總了Java中com.intellij.psi.search.searches.AnnotatedPackagesSearch類的典型用法代碼示例。如果您正苦於以下問題:Java AnnotatedPackagesSearch類的具體用法?Java AnnotatedPackagesSearch怎麽用?Java AnnotatedPackagesSearch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AnnotatedPackagesSearch類屬於com.intellij.psi.search.searches包,在下文中一共展示了AnnotatedPackagesSearch類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAnnotationIndex
import com.intellij.psi.search.searches.AnnotatedPackagesSearch; //導入依賴的package包/類
public void testAnnotationIndex() throws Exception {
getJavaFacade().setAssertOnFileLoadingFilter(new VirtualFileFilter() {
@Override
public boolean accept(final VirtualFile file) {
return !"package-info.java".equals(file.getName());
}
}, myTestRootDisposable);
final PsiClass annotationTypeClass = findClass("annotations.AnnotationType");
assertTrue(annotationTypeClass.isAnnotationType());
final Collection<PsiMember> all = AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
assertEquals(2, all.size());
Set<String> correctNames = new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
for (PsiMember member : all) {
assertTrue(correctNames.contains(member.getName()));
}
final Collection<PsiPackage> packages =
AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
assertEquals(1, packages.size());
assertEquals("annotated", packages.iterator().next().getQualifiedName());
tearDownLoadingFilter();
}
示例2: testAnnotationIndex
import com.intellij.psi.search.searches.AnnotatedPackagesSearch; //導入依賴的package包/類
public void testAnnotationIndex() throws Exception {
getJavaFacade().setAssertOnFileLoadingFilter(new VirtualFileFilter() {
@Override
public boolean accept(final VirtualFile file) {
return !"package-info.java".equals(file.getName());
}
});
final PsiClass annotationTypeClass = findClass("annotations.AnnotationType");
assertTrue(annotationTypeClass.isAnnotationType());
final Collection<PsiMember> all = AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
assertEquals(2, all.size());
Set<String> correctNames = new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
for (PsiMember member : all) {
assertTrue(correctNames.contains(member.getName()));
}
final Collection<PsiPackage> packages =
AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
assertEquals(1, packages.size());
assertEquals("annotated", packages.iterator().next().getQualifiedName());
tearDownLoadingFilter();
}
示例3: testAnnotationIndex
import com.intellij.psi.search.searches.AnnotatedPackagesSearch; //導入依賴的package包/類
public void testAnnotationIndex() throws Exception {
getJavaFacade().setAssertOnFileLoadingFilter(new VirtualFileFilter() {
@Override
public boolean accept(final VirtualFile file) {
return !"package-info.java".equals(file.getName());
}
}, null);
final PsiClass annotationTypeClass = findClass("annotations.AnnotationType");
assertTrue(annotationTypeClass.isAnnotationType());
final Collection<PsiMember> all = AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
assertEquals(2, all.size());
Set<String> correctNames = new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
for (PsiMember member : all) {
assertTrue(correctNames.contains(member.getName()));
}
final Collection<PsiJavaPackage> packages =
AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
assertEquals(1, packages.size());
assertEquals("annotated", packages.iterator().next().getQualifiedName());
tearDownLoadingFilter();
}
示例4: execute
import com.intellij.psi.search.searches.AnnotatedPackagesSearch; //導入依賴的package包/類
@Override
public boolean execute(@NotNull final AnnotatedPackagesSearch.Parameters p, @NotNull final Processor<PsiPackage> consumer) {
final PsiClass annClass = p.getAnnotationClass();
assert annClass.isAnnotationType() : "Annotation type should be passed to annotated packages search";
final String annotationFQN = annClass.getQualifiedName();
assert annotationFQN != null;
final PsiManagerImpl psiManager = (PsiManagerImpl)annClass.getManager();
final SearchScope useScope = p.getScope();
final String annotationShortName = annClass.getName();
assert annotationShortName != null;
final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : null;
final Collection<PsiAnnotation> annotations = JavaAnnotationIndex.getInstance().get(annotationShortName, psiManager.getProject(), scope);
for (PsiAnnotation annotation : annotations) {
PsiModifierList modlist = (PsiModifierList)annotation.getParent();
final PsiElement owner = modlist.getParent();
if (!(owner instanceof PsiClass)) continue;
PsiClass candidate = (PsiClass)owner;
if (!"package-info".equals(candidate.getName())) continue;
LOG.assertTrue(candidate.isValid());
final PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
if (ref == null) continue;
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) continue;
if (useScope instanceof GlobalSearchScope &&
!((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) {
continue;
}
final String qname = candidate.getQualifiedName();
if (qname != null && !consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(
qname.substring(0, qname.lastIndexOf('.'))))) {
return false;
}
}
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(psiManager.getProject());
final GlobalSearchScope infoFilesFilter = new PackageInfoFilesOnly();
GlobalSearchScope infoFiles =
useScope instanceof GlobalSearchScope ? ((GlobalSearchScope)useScope).intersectWith(infoFilesFilter) : infoFilesFilter;
final boolean[] wantmore = new boolean[]{true};
helper.processAllFilesWithWord(annotationShortName, infoFiles, new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile psiFile) {
PsiPackageStatement stmt = PsiTreeUtil.getChildOfType(psiFile, PsiPackageStatement.class);
if (stmt == null) return true;
final PsiModifierList annotations = stmt.getAnnotationList();
if (annotations == null) return true;
final PsiAnnotation ann = annotations.findAnnotation(annotationFQN);
if (ann == null) return true;
final PsiJavaCodeReferenceElement ref = ann.getNameReferenceElement();
if (ref == null) return true;
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) return true;
wantmore[0] = consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(stmt.getPackageName()));
return wantmore[0];
}
}, true);
return wantmore[0];
}
示例5: execute
import com.intellij.psi.search.searches.AnnotatedPackagesSearch; //導入依賴的package包/類
@Override
public boolean execute(@NotNull final AnnotatedPackagesSearch.Parameters p, @NotNull final Processor<PsiJavaPackage> consumer) {
final PsiClass annClass = p.getAnnotationClass();
assert annClass.isAnnotationType() : "Annotation type should be passed to annotated packages search";
final String annotationFQN = annClass.getQualifiedName();
assert annotationFQN != null;
final PsiManagerImpl psiManager = (PsiManagerImpl)annClass.getManager();
final SearchScope useScope = p.getScope();
final String annotationShortName = annClass.getName();
assert annotationShortName != null;
final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : null;
final Collection<PsiAnnotation> annotations = JavaAnnotationIndex.getInstance().get(annotationShortName, psiManager.getProject(), scope);
for (PsiAnnotation annotation : annotations) {
PsiModifierList modlist = (PsiModifierList)annotation.getParent();
final PsiElement owner = modlist.getParent();
if (!(owner instanceof PsiClass)) continue;
PsiClass candidate = (PsiClass)owner;
if (!"package-info".equals(candidate.getName())) continue;
LOG.assertTrue(candidate.isValid());
final PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
if (ref == null) continue;
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) continue;
if (useScope instanceof GlobalSearchScope &&
!((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) {
continue;
}
final String qname = candidate.getQualifiedName();
if (qname != null && !consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(
qname.substring(0, qname.lastIndexOf('.'))))) {
return false;
}
}
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(psiManager.getProject());
final GlobalSearchScope infoFilesFilter = new PackageInfoFilesOnly();
GlobalSearchScope infoFiles =
useScope instanceof GlobalSearchScope ? ((GlobalSearchScope)useScope).intersectWith(infoFilesFilter) : infoFilesFilter;
final boolean[] wantmore = new boolean[]{true};
helper.processAllFilesWithWord(annotationShortName, infoFiles, new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile psiFile) {
PsiPackageStatement stmt = PsiTreeUtil.getChildOfType(psiFile, PsiPackageStatement.class);
if (stmt == null) return true;
final PsiModifierList annotations = stmt.getAnnotationList();
if (annotations == null) return true;
final PsiAnnotation ann = annotations.findAnnotation(annotationFQN);
if (ann == null) return true;
final PsiJavaCodeReferenceElement ref = ann.getNameReferenceElement();
if (ref == null) return true;
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) return true;
wantmore[0] = consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(stmt.getPackageName()));
return wantmore[0];
}
}, true);
return wantmore[0];
}