use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrModifierListImpl method addAnnotation.
@Override
@NotNull
public GrAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) {
final PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(qualifiedName, getResolveScope());
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
GrAnnotation annotation;
if (psiClass != null && psiClass.isAnnotationType()) {
annotation = (GrAnnotation) addAfter(factory.createModifierFromText("@xxx"), null);
annotation.getClassReference().bindToElement(psiClass);
} else {
annotation = (GrAnnotation) addAfter(factory.createModifierFromText("@" + qualifiedName), null);
}
final PsiElement parent = getParent();
if (!(parent instanceof GrParameter)) {
final ASTNode node = annotation.getNode();
final ASTNode treeNext = node.getTreeNext();
if (treeNext != null) {
getNode().addLeaf(TokenType.WHITE_SPACE, "\n", treeNext);
} else {
parent.getNode().addLeaf(TokenType.WHITE_SPACE, "\n", getNode().getTreeNext());
}
}
return annotation;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrVariableDeclarationImpl method findSuitableModifier.
private PsiElement findSuitableModifier() {
final GrModifierList list = getModifierList();
PsiElement defModifier = list.getModifier(GrModifier.DEF);
if (defModifier != null)
return defModifier;
PsiElement finalModifier = list.getModifier(PsiModifier.FINAL);
if (finalModifier != null)
return finalModifier;
for (PsiElement element : list.getModifiers()) {
if (!(element instanceof GrAnnotation)) {
return element;
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation 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]);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrLightModifierList method getText.
@Override
public String getText() {
StringBuilder buffer = new StringBuilder();
for (GrAnnotation annotation : myAnnotations) {
buffer.append(annotation.getText());
buffer.append(' ');
}
for (@GrModifier.GrModifierConstant String modifier : GrModifier.GROOVY_MODIFIERS) {
if (hasExplicitModifier(modifier)) {
buffer.append(modifier);
buffer.append(' ');
}
}
if (buffer.length() > 0) {
buffer.delete(buffer.length() - 1, buffer.length());
}
return buffer.toString();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAnnotationStub method getPsiElement.
public GrAnnotation getPsiElement() {
GrAnnotation annotation = SoftReference.dereference(myPsiRef);
if (annotation != null) {
return annotation;
}
try {
annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText(myText, getPsi());
myPsiRef = new SoftReference<>(annotation);
return annotation;
} catch (IncorrectOperationException e) {
LOG.error("Bad annotation in repository!", e);
return null;
}
}
Aggregations