Search in sources :

Example 6 with GrAnnotationMemberValue

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue 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)

Example 7 with GrAnnotationMemberValue

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.

the class GrAnnotationArrayInitializerImpl method addInternal.

@Override
public ASTNode addInternal(ASTNode first, ASTNode last, ASTNode anchor, Boolean before) {
    final GrAnnotationMemberValue[] initializers = getInitializers();
    if (initializers.length == 0) {
        return super.addInternal(first, last, getNode().getFirstChildNode(), false);
    }
    final ASTNode lastChild = getNode().getLastChildNode();
    getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", lastChild);
    return super.addInternal(first, last, lastChild.getTreePrev(), false);
}
Also used : GrAnnotationMemberValue(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue) ASTNode(com.intellij.lang.ASTNode)

Example 8 with GrAnnotationMemberValue

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.

the class MixinMemberContributor method processDynamicElements.

@Override
public void processDynamicElements(@NotNull final PsiType qualifierType, @NotNull PsiScopeProcessor processor, @NotNull final PsiElement place, @NotNull ResolveState state) {
    if (isInAnnotation(place))
        return;
    final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType);
    if (aClass == null)
        return;
    final PsiModifierList modifierList = aClass.getModifierList();
    if (modifierList == null)
        return;
    List<PsiClass> mixins = new ArrayList<>();
    for (PsiAnnotation annotation : getAllMixins(modifierList)) {
        final PsiAnnotationMemberValue value = annotation.findAttributeValue("value");
        if (value instanceof GrAnnotationArrayInitializer) {
            final GrAnnotationMemberValue[] initializers = ((GrAnnotationArrayInitializer) value).getInitializers();
            for (GrAnnotationMemberValue initializer : initializers) {
                addMixin(initializer, mixins);
            }
        } else if (value instanceof GrExpression) {
            addMixin((GrExpression) value, mixins);
        }
    }
    final MixinProcessor delegate = new MixinProcessor(processor, qualifierType, place);
    for (PsiClass mixin : mixins) {
        if (!mixin.processDeclarations(delegate, state, null, place)) {
            return;
        }
    }
}
Also used : GrAnnotationMemberValue(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue) ArrayList(java.util.ArrayList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrAnnotationArrayInitializer(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer)

Aggregations

GrAnnotationMemberValue (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue)8 GrAnnotationArrayInitializer (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer)3 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)2 GrAnnotationNameValuePair (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair)2 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 ASTNode (com.intellij.lang.ASTNode)1 PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiAnnotationOwner (com.intellij.psi.PsiAnnotationOwner)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)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