Search in sources :

Example 1 with IJavaElementType

use of com.intellij.psi.tree.java.IJavaElementType in project intellij-community by JetBrains.

the class JavaSpacePropertyProcessor method canStickChildrenTogether.

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);
}
Also used : ASTNode(com.intellij.lang.ASTNode) IJavaElementType(com.intellij.psi.tree.java.IJavaElementType)

Example 2 with IJavaElementType

use of com.intellij.psi.tree.java.IJavaElementType in project intellij-community by JetBrains.

the class RParenthTailType method getExistingRParenthOffset.

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) EditorEx(com.intellij.openapi.editor.ex.EditorEx) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) IJavaElementType(com.intellij.psi.tree.java.IJavaElementType) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Aggregations

IJavaElementType (com.intellij.psi.tree.java.IJavaElementType)2 ASTNode (com.intellij.lang.ASTNode)1 Document (com.intellij.openapi.editor.Document)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 TextRange (com.intellij.openapi.util.TextRange)1 IElementType (com.intellij.psi.tree.IElementType)1