Java Code Examples for com.intellij.codeInsight.AnnotationUtil#findAnnotation()

The following examples show how to use com.intellij.codeInsight.AnnotationUtil#findAnnotation() . 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: PsiEventDeclarationsExtractor.java    From litho with Apache License 2.0 6 votes vote down vote up
public static ImmutableList<EventDeclarationModel> getEventDeclarations(PsiClass psiClass) {
  final PsiAnnotation layoutSpecAnnotation =
      AnnotationUtil.findAnnotation(psiClass, LayoutSpec.class.getName());
  if (layoutSpecAnnotation == null) {
    throw new RuntimeException("LayoutSpec annotation not found on class");
  }

  PsiAnnotationMemberValue psiAnnotationMemberValue =
      layoutSpecAnnotation.findAttributeValue("events");

  ArrayList<EventDeclarationModel> eventDeclarationModels = new ArrayList<>();
  if (psiAnnotationMemberValue instanceof PsiArrayInitializerMemberValue) {
    PsiArrayInitializerMemberValue value =
        (PsiArrayInitializerMemberValue) psiAnnotationMemberValue;
    for (PsiAnnotationMemberValue annotationMemberValue : value.getInitializers()) {
      PsiClassObjectAccessExpression accessExpression =
          (PsiClassObjectAccessExpression) annotationMemberValue;
      eventDeclarationModels.add(getEventDeclarationModel(accessExpression));
    }
  } else if (psiAnnotationMemberValue instanceof PsiClassObjectAccessExpression) {
    eventDeclarationModels.add(
        getEventDeclarationModel((PsiClassObjectAccessExpression) psiAnnotationMemberValue));
  }

  return ImmutableList.copyOf(eventDeclarationModels);
}
 
Example 2
Source File: SuggestionServiceImpl.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private Stream<Suggestion> fromComponent(final PsiClass clazz, final String defaultFamily) {
    final PsiAnnotation componentAnnotation =
            AnnotationUtil.findAnnotation(clazz, PARTITION_MAPPER, PROCESSOR, EMITTER);
    final PsiAnnotationMemberValue name = componentAnnotation.findAttributeValue("name");
    if (name == null || "\"\"".equals(name.getText())) {
        return Stream.empty();
    }

    final PsiAnnotationMemberValue familyValue = componentAnnotation.findAttributeValue("family");
    final String componentFamily = (familyValue == null || removeQuotes(familyValue.getText()).isEmpty()) ? null
            : removeQuotes(familyValue.getText());

    final String family = ofNullable(componentFamily).orElseGet(() -> ofNullable(defaultFamily).orElse(null));
    if (family == null) {
        return Stream.empty();
    }

    return Stream
            .of(new Suggestion(family + "." + DISPLAY_NAME, Suggestion.Type.Family), new Suggestion(
                    family + "." + removeQuotes(name.getText()) + "." + DISPLAY_NAME, Suggestion.Type.Component));
}
 
Example 3
Source File: PsiEventMethodExtractor.java    From litho with Apache License 2.0 5 votes vote down vote up
static ImmutableList<SpecMethodModel<EventMethod, EventDeclarationModel>> getOnEventMethods(
    PsiClass psiClass, List<Class<? extends Annotation>> permittedInterStageInputAnnotations) {
  final List<SpecMethodModel<EventMethod, EventDeclarationModel>> delegateMethods =
      new ArrayList<>();

  for (PsiMethod psiMethod : psiClass.getMethods()) {
    final PsiAnnotation onEventAnnotation =
        AnnotationUtil.findAnnotation(psiMethod, OnEvent.class.getName());
    if (onEventAnnotation == null) {
      continue;
    }

    PsiClassObjectAccessExpression accessExpression =
        (PsiClassObjectAccessExpression) onEventAnnotation.findAttributeValue("value");
    final List<MethodParamModel> methodParams =
        getMethodParams(
            psiMethod,
            EventMethodExtractor.getPermittedMethodParamAnnotations(
                permittedInterStageInputAnnotations),
            permittedInterStageInputAnnotations,
            ImmutableList.of());

    final SpecMethodModel<EventMethod, EventDeclarationModel> eventMethod =
        new SpecMethodModel<>(
            ImmutableList.of(),
            PsiModifierExtractor.extractModifiers(psiMethod.getModifierList()),
            psiMethod.getName(),
            PsiTypeUtils.generateTypeSpec(psiMethod.getReturnType()),
            ImmutableList.copyOf(getTypeVariables(psiMethod)),
            ImmutableList.copyOf(methodParams),
            psiMethod,
            PsiEventDeclarationsExtractor.getEventDeclarationModel(accessExpression));
    delegateMethods.add(eventMethod);
  }

  return ImmutableList.copyOf(delegateMethods);
}
 
Example 4
Source File: PsiWorkingRangesMethodExtractor.java    From litho with Apache License 2.0 5 votes vote down vote up
private static SpecMethodModel<EventMethod, WorkingRangeDeclarationModel>
    generateWorkingRangeMethod(
        PsiMethod psiMethod,
        List<Class<? extends Annotation>> permittedInterStageInputAnnotations,
        String annotationQualifiedName) {
  final List<MethodParamModel> methodParams =
      getMethodParams(
          psiMethod,
          getPermittedMethodParamAnnotations(permittedInterStageInputAnnotations),
          permittedInterStageInputAnnotations,
          ImmutableList.of());

  PsiAnnotation psiAnnotation = AnnotationUtil.findAnnotation(psiMethod, annotationQualifiedName);
  PsiNameValuePair valuePair = AnnotationUtil.findDeclaredAttribute(psiAnnotation, "name");

  return SpecMethodModel.<EventMethod, WorkingRangeDeclarationModel>builder()
      .annotations(ImmutableList.of())
      .modifiers(PsiModifierExtractor.extractModifiers(psiMethod.getModifierList()))
      .name(psiMethod.getName())
      .returnTypeSpec(PsiTypeUtils.generateTypeSpec(psiMethod.getReturnType()))
      .typeVariables(ImmutableList.copyOf(getTypeVariables(psiMethod)))
      .methodParams(ImmutableList.copyOf(methodParams))
      .representedObject(psiMethod)
      .typeModel(
          new WorkingRangeDeclarationModel(
              valuePair.getLiteralValue(), valuePair.getNameIdentifier()))
      .build();
}
 
Example 5
Source File: BlazeJUnitTestFilterFlags.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static String methodFilter(PsiMethod method, @Nullable String testSuffixRegex) {
  if (testSuffixRegex != null) {
    return method.getName() + testSuffixRegex;
  } else if (AnnotationUtil.findAnnotation(method, "Parameters") != null) {
    // Supports @junitparams.Parameters, an annotation that applies to an individual test method
    return method.getName() + JUnitParameterizedClassHeuristic.STANDARD_JUNIT_TEST_SUFFIX;
  } else {
    return method.getName();
  }
}
 
Example 6
Source File: MethodObject.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
public boolean overridesMethod() {
    PsiMethod methodBinding = getMethodDeclaration();
    return !(AnnotationUtil.findAnnotation(methodBinding, "Override") == null &&
            methodBinding.findSuperMethods().length == 0);
}
 
Example 7
Source File: ProjectInfo.java    From IntelliJDeodorant with MIT License 4 votes vote down vote up
public boolean overridesMethod(final @NotNull PsiMethod psiMethod) {
    return AnnotationUtil.findAnnotation(psiMethod, "Override") == null &&
            psiMethod.findSuperMethods().length == 0;
}
 
Example 8
Source File: PsiTriggerMethodExtractor.java    From litho with Apache License 2.0 4 votes vote down vote up
public static ImmutableList<SpecMethodModel<EventMethod, EventDeclarationModel>>
    getOnTriggerMethods(
        PsiClass psiClass,
        List<Class<? extends Annotation>> permittedInterStageInputAnnotations) {
  final List<SpecMethodModel<EventMethod, EventDeclarationModel>> delegateMethods =
      new ArrayList<>();

  for (PsiMethod psiMethod : psiClass.getMethods()) {
    final OnTrigger onTriggerAnnotation =
        PsiAnnotationProxyUtils.findAnnotationInHierarchy(psiMethod, OnTrigger.class);
    if (onTriggerAnnotation != null) {
      final List<MethodParamModel> methodParams =
          getMethodParams(
              psiMethod,
              TriggerMethodExtractor.getPermittedMethodParamAnnotations(
                  permittedInterStageInputAnnotations),
              permittedInterStageInputAnnotations,
              ImmutableList.<Class<? extends Annotation>>of());

      PsiAnnotation psiOnTriggerAnnotation =
          AnnotationUtil.findAnnotation(psiMethod, OnTrigger.class.getName());
      PsiNameValuePair valuePair =
          AnnotationUtil.findDeclaredAttribute(psiOnTriggerAnnotation, "value");
      PsiClassObjectAccessExpression valueClassExpression =
          (PsiClassObjectAccessExpression) valuePair.getValue();

      // Reuse EventMethodModel and EventDeclarationModel because we are capturing the same info
      TypeSpec returnTypeSpec = PsiTypeUtils.generateTypeSpec(psiMethod.getReturnType());
      final SpecMethodModel<EventMethod, EventDeclarationModel> eventMethod =
          new SpecMethodModel<EventMethod, EventDeclarationModel>(
              ImmutableList.<Annotation>of(),
              PsiModifierExtractor.extractModifiers(psiMethod.getModifierList()),
              psiMethod.getName(),
              returnTypeSpec,
              ImmutableList.copyOf(getTypeVariables(psiMethod)),
              ImmutableList.copyOf(methodParams),
              psiMethod,
              PsiEventDeclarationsExtractor.getEventDeclarationModel(valueClassExpression));
      delegateMethods.add(eventMethod);
    }
  }

  return ImmutableList.copyOf(delegateMethods);
}
 
Example 9
Source File: HaxePullUpHelper.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
private static void deleteOverrideAnnotationIfFound(PsiMethod oMethod) {
  final PsiAnnotation annotation = AnnotationUtil.findAnnotation(oMethod, Override.class.getName());
  if (annotation != null) {
    annotation.delete();
  }
}