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 (AnnotationTargetUtil.findAnnotationTarget(annotation, PsiAnnotation.TargetType.TYPE_USE)
            != null) {
          return true;
        }
      }
    }

    return false;
  }
Пример #2
0
 public static void collectTypeUseAnnotations(
     @NotNull PsiModifierList modifierList, @NotNull List<PsiAnnotation> annotations) {
   for (PsiAnnotation annotation : modifierList.getAnnotations()) {
     if (AnnotationTargetUtil.isTypeAnnotation(annotation)) {
       annotations.add(annotation);
     }
   }
 }
Пример #3
0
 public static void markTypeAnnotations(@NotNull PsiTypeElement typeElement) {
   PsiElement left =
       PsiTreeUtil.skipSiblingsBackward(
           typeElement, PsiComment.class, PsiWhiteSpace.class, PsiTypeParameterList.class);
   if (left instanceof PsiModifierList) {
     for (PsiAnnotation annotation : ((PsiModifierList) left).getAnnotations()) {
       if (AnnotationTargetUtil.isTypeAnnotation(annotation)) {
         annotation.putUserData(TYPE_ANNO_MARK, Boolean.TRUE);
       }
     }
   }
 }
 public static boolean isAnnotationApplicableTo(
     GrAnnotation annotation, @NotNull TargetType... elementTypeFields) {
   return elementTypeFields.length == 0
       || AnnotationTargetUtil.findAnnotationTarget(annotation, elementTypeFields) != null;
 }
Пример #5
0
 public static boolean isTypeAnnotation(@Nullable PsiElement element) {
   return element instanceof PsiAnnotation
       && AnnotationTargetUtil.isTypeAnnotation((PsiAnnotation) element);
 }
Пример #6
0
 /**
  * @deprecated use {@link AnnotationTargetUtil#getTargetsForLocation(PsiAnnotationOwner)} (to be
  *     removed ion IDEA 17)
  */
 @SuppressWarnings("unused")
 public static TargetType[] getTargetsForLocation(@Nullable PsiAnnotationOwner owner) {
   return AnnotationTargetUtil.getTargetsForLocation(owner);
 }
Пример #7
0
 /**
  * @deprecated use {@link AnnotationTargetUtil#getAnnotationTargets(PsiClass)} (to be removed ion
  *     IDEA 17)
  */
 @SuppressWarnings("unused")
 public static Set<TargetType> getAnnotationTargets(@NotNull PsiClass annotationType) {
   return AnnotationTargetUtil.getAnnotationTargets(annotationType);
 }
Пример #8
0
 /**
  * @deprecated use {@link AnnotationTargetUtil#findAnnotationTarget(PsiClass, TargetType...)} (to
  *     be removed ion IDEA 17)
  */
 @SuppressWarnings("unused")
 public static TargetType findApplicableTarget(
     @NotNull PsiClass annotationType, @NotNull TargetType... types) {
   return AnnotationTargetUtil.findAnnotationTarget(annotationType, types);
 }