@Nullable public static PsiElement prevVisibleLeafOrNewLine(PsiElement element) { PsiElement prevLeaf = element; while ((prevLeaf = PsiTreeUtil.prevLeaf(prevLeaf)) != null) { if (prevLeaf instanceof PsiComment || prevLeaf instanceof PsiErrorElement) { continue; } if (prevLeaf instanceof PsiWhiteSpace) { if (prevLeaf.textContains('\n')) { return prevLeaf; } continue; } break; } return prevLeaf; }
private static boolean hasNewLineBefore(@NotNull PsiElement anchor) { PsiElement prevSibling = anchor.getPrevSibling(); while (prevSibling instanceof PsiWhiteSpace) { if (prevSibling.textContains('\n')) { return true; } prevSibling = prevSibling.getPrevSibling(); } return false; }
private static void deleteImportSpec(@Nullable GoImportSpec importSpec) { GoImportDeclaration importDeclaration = PsiTreeUtil.getParentOfType(importSpec, GoImportDeclaration.class); if (importSpec != null && importDeclaration != null) { PsiElement startElementToDelete = importSpec; PsiElement endElementToDelete = importSpec; if (importDeclaration.getImportSpecList().size() == 1) { startElementToDelete = importDeclaration; endElementToDelete = importDeclaration; PsiElement nextSibling = endElementToDelete.getNextSibling(); if (nextSibling != null && nextSibling.getNode().getElementType() == GoTypes.SEMICOLON) { endElementToDelete = nextSibling; } } // todo: delete after proper formatter implementation PsiElement nextSibling = endElementToDelete.getNextSibling(); if (nextSibling instanceof PsiWhiteSpace && nextSibling.textContains('\n')) { endElementToDelete = nextSibling; } startElementToDelete.getParent().deleteChildRange(startElementToDelete, endElementToDelete); } }
boolean oneLineType = !parent.textContains('\n'); if ((n1.getElementType() == STRUCT || n1.getElementType() == INTERFACE) && n2.getElementType() == LBRACE) { return oneLineType ? none() : one();
@Override public boolean textContains(char c) { return getDelegate().textContains(c); }