Beispiel #1
0
  private static boolean isAnnotated(ASTNode element) {
    PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement) element.getPsi();

    PsiElement qualifier = ref.getQualifier();
    if (qualifier instanceof PsiJavaCodeReferenceElement) {
      if (((PsiJavaCodeReferenceElement) qualifier).resolve() instanceof PsiPackage) {
        return false;
      }
      if (PsiTreeUtil.getChildOfType(qualifier, PsiAnnotation.class) != null) {
        return true;
      }
    }

    PsiModifierList modifierList = PsiImplUtil.findNeighbourModifierList(ref);
    if (modifierList != null) {
      for (PsiAnnotation annotation : modifierList.getAnnotations()) {
        if (PsiImplUtil.findApplicableTarget(annotation, PsiAnnotation.TargetType.TYPE_USE)
            != null) {
          return true;
        }
      }
    }

    return false;
  }
 public static void collectTypeUseAnnotations(
     @NotNull PsiModifierList modifierList, @NotNull List<PsiAnnotation> annotations) {
   for (PsiAnnotation annotation : modifierList.getAnnotations()) {
     if (AnnotationTargetUtil.isTypeAnnotation(annotation)) {
       annotations.add(annotation);
     }
   }
 }
  /**
   * @deprecated use {@link #collectTypeUseAnnotations(PsiModifierList, List)} (to be removed in
   *     IDEA 16)
   */
  @SuppressWarnings("unused")
  public static List<PsiAnnotation> getTypeUseAnnotations(@NotNull PsiModifierList modifierList) {
    SmartList<PsiAnnotation> result = null;

    for (PsiAnnotation annotation : modifierList.getAnnotations()) {
      if (isTypeAnnotation(annotation)) {
        if (result == null) result = new SmartList<PsiAnnotation>();
        result.add(annotation);
      }
    }

    return result;
  }