use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class JavaCompletionContributor method semicolonNeeded.
public static boolean semicolonNeeded(final Editor editor, PsiFile file, final int startOffset) {
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.findElementOfClassAtOffset(file, startOffset, PsiJavaCodeReferenceElement.class, false);
if (ref != null && !(ref instanceof PsiReferenceExpression)) {
if (ref.getParent() instanceof PsiTypeElement) {
return true;
}
}
if (psiElement(PsiIdentifier.class).withParent(psiParameter()).accepts(file.findElementAt(startOffset))) {
return true;
}
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(startOffset);
if (iterator.atEnd())
return false;
if (iterator.getTokenType() == JavaTokenType.IDENTIFIER) {
iterator.advance();
}
while (!iterator.atEnd() && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(iterator.getTokenType())) {
iterator.advance();
}
if (!iterator.atEnd() && iterator.getTokenType() == JavaTokenType.LPARENTH && PsiTreeUtil.getParentOfType(ref, PsiExpression.class, PsiClass.class) == null) {
// looks like a method declaration, e.g. StringBui<caret>methodName() inside a class
return true;
}
if (!iterator.atEnd() && (iterator.getTokenType() == JavaTokenType.COLON) && null == PsiTreeUtil.findElementOfClassAtOffset(file, startOffset, PsiConditionalExpression.class, false)) {
return true;
}
while (!iterator.atEnd() && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(iterator.getTokenType())) {
iterator.advance();
}
if (iterator.atEnd() || iterator.getTokenType() != JavaTokenType.IDENTIFIER)
return false;
iterator.advance();
while (!iterator.atEnd() && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(iterator.getTokenType())) {
iterator.advance();
}
if (iterator.atEnd())
return false;
// <caret> foo = something, we don't want the reference to be treated as a type
return iterator.getTokenType() == JavaTokenType.EQ;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class AnnotationInsertHandler method isAtTokenNeeded.
private static boolean isAtTokenNeeded(InsertionContext myContext) {
HighlighterIterator iterator = ((EditorEx) myContext.getEditor()).getHighlighter().createIterator(myContext.getStartOffset());
LOG.assertTrue(iterator.getTokenType() == JavaTokenType.IDENTIFIER);
iterator.retreat();
if (iterator.getTokenType() == TokenType.WHITE_SPACE)
iterator.retreat();
return iterator.getTokenType() != JavaTokenType.AT && iterator.getTokenType() != JavaTokenType.DOT;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class JavaBraceMatcherTest method testBinaryStatement.
public void testBinaryStatement() {
myFixture.configureByText("a.java", "import java.util.ArrayList;" + "class A {" + " int i = 3 <caret>< 4 ? 5 > 6 : 1 : 1 : 1;" + "}");
final Editor editor = myFixture.getEditor();
final EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
final HighlighterIterator iterator = editorHighlighter.createIterator(editor.getCaretModel().getOffset());
boolean matched = BraceMatchingUtil.matchBrace(editor.getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, true);
assertFalse(matched);
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method testScriptHighlightingInE4X.
public void testScriptHighlightingInE4X() throws Exception {
// 10 20 30 40 50
// 01234567890123456789012 34567890123456 7 89012 34567890123456789
String text = "var a = <xml>{ c }</xml>";
configureByFile(BASE_PATH + getTestName(false) + ".js2");
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(myProject, getFile().getVirtualFile());
highlighter.setText(text);
HighlighterIterator iterator = highlighter.createIterator(15);
assertEquals(JSTokenTypes.IDENTIFIER, iterator.getTokenType());
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project Perl5-IDEA by Camelcade.
the class PerlEnterInBracketsHandler method preprocessEnter.
@Override
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) {
if (!file.getLanguage().is(PerlLanguage.INSTANCE) || !CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) {
return Result.Continue;
}
Integer currentOffset = caretOffset.get();
if (currentOffset < 1) {
return Result.Continue;
}
assert editor instanceof EditorEx;
EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
Document document = editor.getDocument();
CharSequence documentChars = document.getCharsSequence();
HighlighterIterator highlighterIterator = editorHighlighter.createIterator(currentOffset - 1);
IElementType previousTokenType = PerlEditorUtil.getPreviousTokenType(highlighterIterator);
if (highlighterIterator.atEnd() || StringUtil.containsLineBreak(documentChars.subSequence(highlighterIterator.getStart(), currentOffset))) {
return Result.Continue;
}
int openTokenStart = highlighterIterator.getStart();
IElementType nextTokenType = PerlEditorUtil.getNextTokenType(highlighterIterator);
if (highlighterIterator.atEnd() || StringUtil.containsLineBreak(documentChars.subSequence(currentOffset, highlighterIterator.getEnd()))) {
return Result.Continue;
}
if (previousTokenType == LEFT_BRACKET && nextTokenType == RIGHT_BRACKET) {
doIndent(file, editor, dataContext, originalHandler, document);
} else if (previousTokenType == QUOTE_SINGLE_OPEN && nextTokenType == QUOTE_SINGLE_CLOSE && openTokenStart > 0) {
IElementType qwTokenType = PerlEditorUtil.getPreviousTokenType(editorHighlighter.createIterator(openTokenStart - 1));
if (qwTokenType == RESERVED_QW) {
doIndent(file, editor, dataContext, originalHandler, document);
}
}
return Result.Continue;
}
Aggregations