Search in sources :

Example 1 with AnnotationArgConverter

use of org.jetbrains.plugins.groovy.lang.psi.impl.AnnotationArgConverter in project intellij-community by JetBrains.

the class GrLightAnnotation method addAttribute.

public void addAttribute(PsiNameValuePair pair) {
    if (pair instanceof GrAnnotationNameValuePair) {
        myAnnotationArgList.addAttribute((GrAnnotationNameValuePair) pair);
    } else {
        GrAnnotationMemberValue newValue = new AnnotationArgConverter().convert(pair.getValue());
        if (newValue == null)
            return;
        String name = pair.getName();
        GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(pair.getProject());
        String annotationText;
        annotationText = name != null ? "@A(" + name + "=" + newValue.getText() + ")" : "@A(" + newValue.getText() + ")";
        GrAnnotation annotation = factory.createAnnotationFromText(annotationText);
        myAnnotationArgList.addAttribute(annotation.getParameterList().getAttributes()[0]);
    }
}
Also used : GrAnnotationMemberValue(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) AnnotationArgConverter(org.jetbrains.plugins.groovy.lang.psi.impl.AnnotationArgConverter)

Aggregations

GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)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 AnnotationArgConverter (org.jetbrains.plugins.groovy.lang.psi.impl.AnnotationArgConverter)1