Search in sources :

Example 1 with PsiAnnotationOwner

use of com.intellij.psi.PsiAnnotationOwner in project intellij-community by JetBrains.

the class FieldAnnotationChecker method checkScriptField.

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"));
        }
    }
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) PsiAnnotationOwner(com.intellij.psi.PsiAnnotationOwner) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PsiAnnotationOwner

use of com.intellij.psi.PsiAnnotationOwner in project intellij-community by JetBrains.

the class GriffonPropertyListenerAnnotationChecker method checkArgumentList.

@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;
}
Also used : GrAnnotationMemberValue(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) PsiAnnotationOwner(com.intellij.psi.PsiAnnotationOwner) PsiClass(com.intellij.psi.PsiClass) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

PsiAnnotationOwner (com.intellij.psi.PsiAnnotationOwner)2 PsiElement (com.intellij.psi.PsiElement)2 PsiClass (com.intellij.psi.PsiClass)1 GrAnnotationMemberValue (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue)1 GrAnnotationNameValuePair (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair)1 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)1 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)1