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);
}
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;
}
Aggregations