@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; }