Java Code Examples for com.intellij.psi.PsiModifierList#getAnnotations()

The following examples show how to use com.intellij.psi.PsiModifierList#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationDetector.java    From here-be-dragons with MIT License 7 votes vote down vote up
static PsiAnnotation findAnnotation(PsiElement element, String annotationName) {
    if (element instanceof PsiModifierListOwner) {
        PsiModifierListOwner listOwner = (PsiModifierListOwner) element;
        PsiModifierList modifierList = listOwner.getModifierList();

        if (modifierList != null) {
            for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
                if (annotationName.equals(psiAnnotation.getQualifiedName())) {
                    return psiAnnotation;
                }
            }
        }

    }
    return null;
}
 
Example 2
Source File: TestSizeFinder.java    From intellij with Apache License 2.0 7 votes vote down vote up
@Nullable
public static TestSize getTestSize(PsiClass psiClass) {
  PsiModifierList psiModifierList = psiClass.getModifierList();
  if (psiModifierList == null) {
    return null;
  }
  PsiAnnotation[] annotations = psiModifierList.getAnnotations();
  TestSize testSize = getTestSize(annotations);
  if (testSize != null) {
    return testSize;
  }
  String fullText = psiModifierList.getText();
  return CATEGORY_ANNOTATION_HEURISTIC
      .entrySet()
      .stream()
      .filter(e -> fullText.contains(e.getKey()))
      .map(Map.Entry::getValue)
      .findFirst()
      .orElse(null);
}
 
Example 3
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
public static Set<String> getQualifierAnnotations(PsiElement element) {
  Set<String> qualifiedClasses = new HashSet<String>();

  if (element instanceof PsiModifierListOwner) {
    PsiModifierListOwner listOwner = (PsiModifierListOwner) element;
    PsiModifierList modifierList = listOwner.getModifierList();

    if (modifierList != null) {
      for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
        if (psiAnnotation != null && psiAnnotation.getQualifiedName() != null) {
          JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(element.getProject());
          PsiClass psiClass = psiFacade.findClass(psiAnnotation.getQualifiedName(),
              GlobalSearchScope.projectScope(element.getProject()));

          if (hasAnnotation(psiClass, CLASS_QUALIFIER)) {
            qualifiedClasses.add(psiAnnotation.getQualifiedName());
          }
        }
      }
    }
  }

  return qualifiedClasses;
}
 
Example 4
Source File: LombokProcessorProvider.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addApplicableProcessors(@NotNull PsiMember psiMember, @NotNull Collection<LombokProcessorData> target) {
  final PsiModifierList psiModifierList = psiMember.getModifierList();
  if (null != psiModifierList) {
    for (PsiAnnotation psiAnnotation : psiModifierList.getAnnotations()) {
      for (Processor processor : getProcessors(psiAnnotation)) {
        target.add(new LombokProcessorData(processor, psiAnnotation));
      }
    }
  }
}
 
Example 5
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isAnnotatedWith(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull final Pattern annotationPattern) {
  final PsiModifierList psiModifierList = psiModifierListOwner.getModifierList();
  if (psiModifierList != null) {
    for (PsiAnnotation psiAnnotation : psiModifierList.getAnnotations()) {
      final String suspect = getSimpleNameOf(psiAnnotation);
      if (annotationPattern.matcher(suspect).matches()) {
        return true;
      }
    }
  }
  return false;
}
 
Example 6
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean checkAnnotationsSimpleNameExistsIn(@NotNull PsiModifierListOwner modifierListOwner, @NotNull Collection<String> annotationNames) {
  final PsiModifierList modifierList = modifierListOwner.getModifierList();
  if (null != modifierList) {
    for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
      final String simpleName = getSimpleNameOf(psiAnnotation);
      if (annotationNames.contains(simpleName)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 7
Source File: InjectedFieldInJobNotTransientDetector.java    From cathode with Apache License 2.0 5 votes vote down vote up
private boolean hasAnnotation(PsiModifierList modifierList, String annotationName) {

      PsiAnnotation[] annotations = modifierList.getAnnotations();
      if (annotations != null && annotations.length > 0) {
        for (PsiAnnotation annotation : annotations) {
          if (annotationName.equals(annotation.getQualifiedName())) {
            return true;
          }
        }
      }

      return false;
    }
 
Example 8
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
static PsiAnnotation findAnnotation(PsiElement element, String annotationName) {
  if (element instanceof PsiModifierListOwner) {
    PsiModifierListOwner listOwner = (PsiModifierListOwner) element;
    PsiModifierList modifierList = listOwner.getModifierList();

    if (modifierList != null) {
      for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
        if (annotationName.equals(psiAnnotation.getQualifiedName())) {
          return psiAnnotation;
        }
      }
    }
  }
  return null;
}
 
Example 9
Source File: PsiConsultantImpl.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
static PsiAnnotation findAnnotationOnMethod(PsiMethod psiMethod, String annotationName) {
  PsiModifierList modifierList = psiMethod.getModifierList();
  for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
    if (annotationName.equals(psiAnnotation.getQualifiedName())) {
      return psiAnnotation;
    }
  }
  return null;
}