public static boolean canStickChildrenTogether(final ASTNode child1, final ASTNode child2) { if(child1 == null || child2 == null) { return true; } if(isWS(child1) || isWS(child2)) { return true; } ASTNode token1 = TreeUtil.findLastLeaf(child1); ASTNode token2 = TreeUtil.findFirstLeaf(child2); LOG.assertTrue(token1 != null); LOG.assertTrue(token2 != null); return !(token1.getElementType() instanceof IJavaElementType) || !(token2.getElementType() instanceof IJavaElementType) || canStickJavaTokens(token1, token2); }
private static int getExistingRParenthOffset(final Editor editor, final int tailOffset) { final Document document = editor.getDocument(); if (tailOffset >= document.getTextLength()) return -1; final CharSequence charsSequence = document.getCharsSequence(); EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter(); int existingRParenthOffset = -1; for(HighlighterIterator iterator = highlighter.createIterator(tailOffset); !iterator.atEnd(); iterator.advance()){ final IElementType tokenType = iterator.getTokenType(); if ((!(tokenType instanceof IJavaElementType) || !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(tokenType)) && tokenType != TokenType.WHITE_SPACE) { final int start = iterator.getStart(); if (iterator.getEnd() == start + 1 && ')' == charsSequence.charAt(start)) { existingRParenthOffset = start; } break; } } if (existingRParenthOffset >= 0){ final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(editor.getProject()); psiDocumentManager.commitDocument(document); TextRange range = getRangeToCheckParensBalance(psiDocumentManager.getPsiFile(document), document, editor.getCaretModel().getOffset()); int balance = calcParensBalance(document, highlighter, range.getStartOffset(), range.getEndOffset()); if (balance > 0){ return -1; } } return existingRParenthOffset; }
public static boolean canStickChildrenTogether(final ASTNode child1, final ASTNode child2) { if (child1 == null || child2 == null) return true; if (isWS(child1) || isWS(child2)) return true; ASTNode token1 = TreeUtil.findLastLeaf(child1); ASTNode token2 = TreeUtil.findFirstLeaf(child2); LOG.assertTrue(token1 != null); LOG.assertTrue(token2 != null); return !(token1.getElementType() instanceof IJavaElementType && token2.getElementType()instanceof IJavaElementType) || canStickJavaTokens(token1,token2); }
@Override public boolean apply(@Nullable IElementType input) { return input == C_STYLE_COMMENT || input == END_OF_LINE_COMMENT || input == IDENTIFIER || KEYWORD_BIT_SET.contains(input) || input instanceof IJavaElementType || input instanceof IJavaDocElementType; }
@Override public boolean isPairedBracesAllowedBeforeType(@NotNull final IElementType lbraceType, @Nullable final IElementType contextType) { if (contextType instanceof IJavaElementType) return isPairedBracesAllowedBeforeTypeInJava(contextType); return true; }