コード例 #1
0
  @Override
  public boolean checkApplicability(
      @NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
    final String qname = annotation.getQualifiedName();
    if (!GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD.equals(qname)) return false;

    checkScriptField(holder, annotation);

    PsiElement annoParent = annotation.getParent();
    PsiElement ownerToUse =
        annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent;
    if (!(ownerToUse instanceof GrVariableDeclaration)
        || !PsiUtil.isLocalVariable(((GrVariableDeclaration) ownerToUse).getVariables()[0])) {
      return false;
    }

    if (!GrAnnotationImpl.isAnnotationApplicableTo(
        annotation, PsiAnnotation.TargetType.LOCAL_VARIABLE)) {
      GrCodeReferenceElement ref = annotation.getClassReference();
      String target = JavaErrorMessages.message("annotation.target.LOCAL_VARIABLE");
      String description =
          JavaErrorMessages.message("annotation.not.applicable", ref.getText(), target);
      holder.createErrorAnnotation(ref, description);
    }

    return true;
  }
コード例 #2
0
  @Nullable
  public static String isAnnotationApplicable(
      @NotNull GrAnnotation annotation, final PsiElement parent) {
    PsiElement owner = parent.getParent();

    final PsiElement ownerToUse = parent instanceof PsiModifierList ? owner : parent;

    String[] elementTypeFields = GrAnnotationImpl.getApplicableElementTypeFields(ownerToUse);
    if (elementTypeFields != null
        && !GrAnnotationImpl.isAnnotationApplicableTo(annotation, false, elementTypeFields)) {
      final String annotationTargetText =
          JavaErrorMessages.message("annotation.target." + elementTypeFields[0]);
      GrCodeReferenceElement ref = annotation.getClassReference();
      return JavaErrorMessages.message(
          "annotation.not.applicable", ref.getText(), annotationTargetText);
    }

    return null;
  }