private static void deleteOverrideAnnotationIfFound(PsiMethod oMethod) { final PsiAnnotation annotation = AnnotationUtil.findAnnotation(oMethod, CommonClassNames.JAVA_LANG_OVERRIDE); if (annotation != null) { PsiElement prev = annotation.getPrevSibling(); PsiElement next = annotation.getNextSibling(); if ((prev == null || org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isLineFeed(prev)) && org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isLineFeed(next)) { next.delete(); } annotation.delete(); } }
@NotNull public GrStatement addStatementBefore(@NotNull GrStatement element, @Nullable GrStatement anchor) throws IncorrectOperationException { if (anchor == null && getRBrace() == null) { throw new IncorrectOperationException(); } if (anchor != null && !this.equals(anchor.getParent())) { throw new IncorrectOperationException(); } final LeafElement nls = Factory.createSingleLeafElement(GroovyTokenTypes.mNLS, "\n", 0, 1, null, getManager()); PsiElement actualAnchor = anchor == null ? getRBrace() : anchor; if (mayUseNewLinesAsSeparators()) { PsiElement prev = actualAnchor.getPrevSibling(); if (prev instanceof GrParameterList && prev.getTextLength() == 0 && prev.getPrevSibling() != null) { prev = prev.getPrevSibling(); } if (!PsiUtil.isLineFeed(prev)) { addBefore(nls.getPsi(), actualAnchor); } } element = (GrStatement) addBefore(element, actualAnchor); if (mayUseNewLinesAsSeparators()) { addBefore(nls.getPsi(), actualAnchor); } else { addBefore( Factory.createSingleLeafElement(GroovyTokenTypes.mNLS, "\n", 0, 1, null, getManager()) .getPsi(), actualAnchor); } return element; }
public void visitStatementOwner(GrStatementOwner owner, boolean shouldInsertReturnNull) { boolean hasLineFeed = false; for (PsiElement e = owner.getFirstChild(); e != null; e = e.getNextSibling()) { if (e instanceof GrStatement) { ((GrStatement) e).accept(this); hasLineFeed = false; } else if (TokenSets.COMMENT_SET.contains(e.getNode().getElementType())) { builder.append(e.getText()); } else if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isLineFeed(e)) { hasLineFeed = true; if (IN_TEST) { builder.append(genSameLineFeed(e.getText())); } else { builder.append(e.getText()); } } } if (shouldInsertReturnNull) { if (!hasLineFeed) { builder.append('\n'); } builder.append("return null;\n"); } }