當前位置: 首頁>>代碼示例>>Java>>正文


Java AnnotatedPackagesSearch類代碼示例

本文整理匯總了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();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:Src15RepositoryUseTest.java

示例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();
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:27,代碼來源:Src15RepositoryUseTest.java

示例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();
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:27,代碼來源:Src15RepositoryUseTest.java

示例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];
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:72,代碼來源:AnnotatedPackagesSearcher.java

示例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];
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:72,代碼來源:AnnotatedPackagesSearcher.java


注:本文中的com.intellij.psi.search.searches.AnnotatedPackagesSearch類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。