Java 类com.intellij.psi.PsiAnnotationOwner 实例源码

项目:intellij-ce-playground    文件:DelegatesToAnnotationChecker.java   
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
  if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName())) return false;

  final PsiAnnotationMemberValue valueAttribute = annotation.findAttributeValue("value");

  if (valueAttribute == null) {
    final PsiAnnotationOwner owner = annotation.getOwner();
    if (owner instanceof GrModifierList) {
      final PsiElement parent1 = ((GrModifierList)owner).getParent();
      if (parent1 instanceof GrParameter) {
        final PsiElement parent = parent1.getParent();
        if (parent instanceof GrParameterList) {
          for (GrParameter parameter : ((GrParameterList)parent).getParameters()) {
            if (parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET) != null) {
              return true;
            }
          }
        }
      }
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:AnnotationChecker.java   
public void checkApplicability(@NotNull GrAnnotation annotation, @Nullable PsiAnnotationOwner owner) {
  final GrCodeReferenceElement ref = annotation.getClassReference();
  final PsiElement resolved = ref.resolve();

  if (resolved == null) return;
  assert resolved instanceof PsiClass;

  PsiClass anno = (PsiClass)resolved;
  String qname = anno.getQualifiedName();
  if (!anno.isAnnotationType() && GrAnnotationCollector.findAnnotationCollector(anno) == null) {
    if (qname != null) {
      myHolder.createErrorAnnotation(ref, GroovyBundle.message("class.is.not.annotation", qname));
    }
    return;
  }

  for (CustomAnnotationChecker checker : CustomAnnotationChecker.EP_NAME.getExtensions()) {
    if (checker.checkApplicability(myHolder, annotation)) return;
  }

  String description = CustomAnnotationChecker.isAnnotationApplicable(annotation, owner);
  if (description != null) {
    myHolder.createErrorAnnotation(ref, description).registerFix(new GrRemoveAnnotationIntention());
  }
}
项目:tools-idea    文件:DelegatesToAnnotationChecker.java   
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
  if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName())) return false;

  final PsiAnnotationMemberValue valueAttribute = annotation.findAttributeValue("value");

  if (valueAttribute == null) {
    final PsiAnnotationOwner owner = annotation.getOwner();
    if (owner instanceof GrModifierList) {
      final PsiElement parent1 = ((GrModifierList)owner).getParent();
      if (parent1 instanceof GrParameter) {
        final PsiElement parent = parent1.getParent();
        if (parent instanceof GrParameterList) {
          for (GrParameter parameter : ((GrParameterList)parent).getParameters()) {
            if (parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET) != null) {
              return true;
            }
          }
        }
      }
    }
  }

  return false;
}
项目:intellij-plugin    文件:CoffigResolver.java   
Optional<PsiAnnotation> getConfigAnnotation(@NotNull PsiModifierListOwner psiModifierListOwner) {
    return Optional.ofNullable(psiModifierListOwner.getModifierList())
            .map(PsiAnnotationOwner::getAnnotations)
            .map(Arrays::stream)
            .map(stream -> stream.filter(annotation -> Optional.ofNullable(annotation.getNameReferenceElement())
                    .map(PsiReference::resolve)
                    .map(psiElement -> psiElement == configAnnotationClass)
                    .orElse(false)
            ))
            .flatMap(Stream::findFirst);
}
项目:intellij-plugin    文件:ResourceNode.java   
private PsiAnnotation getPathAnnotation(PsiClass pathAnnotationClass, @NotNull PsiModifierListOwner psiModifierListOwner) {
    return Optional.ofNullable(psiModifierListOwner.getModifierList())
            .map(PsiAnnotationOwner::getAnnotations)
            .map(Arrays::stream)
            .map(stream -> stream.filter(annotation -> Optional.ofNullable(annotation.getNameReferenceElement())
                    .map(PsiReference::resolve)
                    .map(psiElement -> psiElement == pathAnnotationClass)
                    .orElse(false)
            ))
            .flatMap(Stream::findFirst)
            .orElse(null);
}
项目:intellij-ce-playground    文件:FieldAnnotationChecker.java   
private static void checkScriptField(AnnotationHolder holder, GrAnnotation annotation) {
  final PsiAnnotationOwner owner = annotation.getOwner();
  final GrMember container = PsiTreeUtil.getParentOfType(((PsiElement)owner), GrMember.class);
  if (container != null) {
    if (container.getContainingClass() instanceof GroovyScriptClass) {
      holder.createErrorAnnotation(annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script.body"));
    }
    else {
      holder.createErrorAnnotation(annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script"));
    }
  }
}
项目:intellij-ce-playground    文件:GriffonPropertyListenerAnnotationChecker.java   
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
  if (!"griffon.transform.PropertyListener".equals(annotation.getQualifiedName())) return false;

  final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
  if (attributes.length != 1) return false;

  final GrAnnotationNameValuePair attribute = attributes[0];
  final GrAnnotationMemberValue value = attribute.getValue();

  final PsiAnnotationOwner owner = annotation.getOwner();
  if (owner instanceof GrField) {
    if (value instanceof GrClosableBlock) {
      return true;
    }
  }
  else if (owner instanceof GrTypeDefinition) {
    if (value instanceof GrReferenceExpression) {
      final PsiElement resolved = ((GrReferenceExpression)value).resolve();
      if (resolved instanceof GrField) {
        final PsiClass containingClass = ((GrField)resolved).getContainingClass();
        if (annotation.getManager().areElementsEquivalent((PsiElement)owner, containingClass)) {
          return true;
        }
      }
    }
  }

  return false;
}
项目:tools-idea    文件:FieldAnnotationChecker.java   
private static void checkScriptField(AnnotationHolder holder, GrAnnotation annotation) {
  final PsiAnnotationOwner owner = annotation.getOwner();
  final GrMember container = PsiTreeUtil.getParentOfType(((PsiElement)owner), GrMember.class);
  if (container != null) {
    if (container.getContainingClass() instanceof GroovyScriptClass) {
      holder.createErrorAnnotation(annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script.body"));
    }
    else {
      holder.createErrorAnnotation(annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script"));
    }
  }
}
项目:tools-idea    文件:GriffonPropertyListenerAnnotationChecker.java   
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
  if (!"griffon.transform.PropertyListener".equals(annotation.getQualifiedName())) return false;

  final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
  if (attributes.length != 1) return false;

  final GrAnnotationNameValuePair attribute = attributes[0];
  final GrAnnotationMemberValue value = attribute.getValue();

  final PsiAnnotationOwner owner = annotation.getOwner();
  if (owner instanceof GrField) {
    if (value instanceof GrClosableBlock) {
      return true;
    }
  }
  else if (owner instanceof GrTypeDefinition) {
    if (value instanceof GrReferenceExpression) {
      final PsiElement resolved = ((GrReferenceExpression)value).resolve();
      if (resolved instanceof GrField) {
        final PsiClass containingClass = ((GrField)resolved).getContainingClass();
        if (annotation.getManager().areElementsEquivalent((PsiElement)owner, containingClass)) {
          return true;
        }
      }
    }
  }

  return false;
}
项目:lombok-intellij-plugin    文件:PsiAnnotationSearchUtil.java   
@Nullable
private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner annotationOwner, @NotNull String qualifiedName) {
  if (annotationOwner == null) {
    return null;
  }

  PsiAnnotation[] annotations = annotationOwner.getAnnotations();
  if (annotations.length == 0) {
    return null;
  }

  final String shortName = StringUtil.getShortName(qualifiedName);

  for (PsiAnnotation annotation : annotations) {
    PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
    if (null != referenceElement) {
      final String referenceName = referenceElement.getReferenceName();
      if (shortName.equals(referenceName)) {

        if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
          String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();
          if (qualifiedName.equals(possibleFullQualifiedName)) {
            return annotation;
          }
        }

        final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
        if (qualifiedName.equals(annotationQualifiedName)) {
          return annotation;
        }
      }
    }
  }

  return null;
}
项目:lombok-intellij-plugin    文件:PsiAnnotationSearchUtil.java   
@Nullable
private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner annotationOwner, @NotNull String... qualifiedNames) {
  if (annotationOwner == null || qualifiedNames.length == 0) {
    return null;
  }

  PsiAnnotation[] annotations = annotationOwner.getAnnotations();
  if (annotations.length == 0) {
    return null;
  }

  final String[] shortNames = new String[qualifiedNames.length];
  for (int i = 0; i < qualifiedNames.length; i++) {
    shortNames[i] = StringUtil.getShortName(qualifiedNames[i]);
  }

  for (PsiAnnotation annotation : annotations) {
    final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
    if (null != referenceElement) {
      final String referenceName = referenceElement.getReferenceName();
      if (ArrayUtil.find(shortNames, referenceName) > -1) {

        if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
          final String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();

          if (ArrayUtil.find(qualifiedNames, possibleFullQualifiedName) > -1) {
            return annotation;
          }
        }

        final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
        if (ArrayUtil.find(qualifiedNames, annotationQualifiedName) > -1) {
          return annotation;
        }
      }
    }
  }

  return null;
}
项目:consulo-java    文件:ClsAnnotationImpl.java   
@Override
public PsiAnnotationOwner getOwner()
{
    return (PsiAnnotationOwner) getParent();//todo
}