本文整理汇总了Java中com.intellij.openapi.editor.highlighter.EditorHighlighter.createIterator方法的典型用法代码示例。如果您正苦于以下问题:Java EditorHighlighter.createIterator方法的具体用法?Java EditorHighlighter.createIterator怎么用?Java EditorHighlighter.createIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.highlighter.EditorHighlighter
的用法示例。
在下文中一共展示了EditorHighlighter.createIterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcParensBalance
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
private static int calcParensBalance(Document document, EditorHighlighter highlighter, int rangeStart, int rangeEnd){
LOG.assertTrue(0 <= rangeStart);
LOG.assertTrue(rangeStart <= rangeEnd);
LOG.assertTrue(rangeEnd <= document.getTextLength());
HighlighterIterator iterator = highlighter.createIterator(rangeStart);
int balance = 0;
while(!iterator.atEnd() && iterator.getStart() < rangeEnd){
IElementType tokenType = iterator.getTokenType();
if (tokenType == JavaTokenType.LPARENTH){
balance++;
}
else if (tokenType == JavaTokenType.RPARENTH){
balance--;
}
iterator.advance();
}
return balance;
}
示例2: testCpp
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
public void testCpp() throws Exception {
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), "A.cpp");
// 0123456789012345678 9 0123 45 6 7
highlighter.setText("#include try enum \"\\xff\\z\\\"xxx\"");
HighlighterIterator iterator = highlighter.createIterator(2);
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
iterator = highlighter.createIterator(9);
assertEquals(CustomHighlighterTokenType.KEYWORD_2, iterator.getTokenType());
iterator = highlighter.createIterator(15);
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
iterator = highlighter.createIterator(19);
assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType());
iterator = highlighter.createIterator(23);
assertEquals(StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN, iterator.getTokenType());
iterator = highlighter.createIterator(25);
assertEquals(StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN, iterator.getTokenType());
iterator = highlighter.createIterator(27);
assertEquals(CustomHighlighterTokenType.STRING, iterator.getTokenType());
}
示例3: handleBetweenSquareBraces
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
private static boolean handleBetweenSquareBraces(Editor editor,
int caret,
DataContext context,
Project project,
EditorActionHandler originalHandler) {
String text = editor.getDocument().getText();
if (text == null || text.isEmpty()) return false;
final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
if (caret < 1 || caret > text.length() - 1) {
return false;
}
HighlighterIterator iterator = highlighter.createIterator(caret - 1);
if (GroovyTokenTypes.mLBRACK == iterator.getTokenType()) {
if (text.length() > caret) {
iterator = highlighter.createIterator(caret);
if (GroovyTokenTypes.mRBRACK == iterator.getTokenType()) {
originalHandler.execute(editor, context);
originalHandler.execute(editor, context);
editor.getCaretModel().moveCaretRelatively(0, -1, false, false, true);
insertSpacesByGroovyContinuationIndent(editor, project);
return true;
}
}
}
return false;
}
示例4: charTyped
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (c != '{' || project == null || !HandlerUtils.canBeInvoked(editor, project)) {
return Result.CONTINUE;
}
if (!(file instanceof GroovyFile)) return Result.CONTINUE;
int caret = editor.getCaretModel().getOffset();
final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
if (caret < 1) return Result.CONTINUE;
HighlighterIterator iterator = highlighter.createIterator(caret - 1);
if (iterator.getTokenType() != GroovyTokenTypes.mLCURLY) return Result.CONTINUE;
iterator.retreat();
if (iterator.atEnd() || iterator.getTokenType() != GroovyTokenTypes.mDOLLAR) return Result.CONTINUE;
iterator.advance();
if (iterator.atEnd()) return Result.CONTINUE;
iterator.advance();
if (iterator.getTokenType() != GroovyTokenTypes.mGSTRING_BEGIN) return Result.CONTINUE;
editor.getDocument().insertString(caret, "}");
return Result.STOP;
}
示例5: beforeCharDeleted
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
@Override
public void beforeCharDeleted(char c, PsiFile file, Editor editor) {
if (c != '{') return;
if (!(file instanceof GroovyFile)) return;
final int offset = editor.getCaretModel().getOffset();
final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
if (offset < 1) return;
HighlighterIterator iterator = highlighter.createIterator(offset);
if (iterator.getTokenType() != GroovyTokenTypes.mRCURLY) return;
iterator.retreat();
if (iterator.getStart() < 1 || iterator.getTokenType() != GroovyTokenTypes.mLCURLY) return;
editor.getDocument().deleteString(offset, offset + 1);
}
示例6: getExistingRParenthOffset
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
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;
}
示例7: testHaskel
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
public void testHaskel() throws Exception {
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), "A.hs");
// 0123456789012345678 9 0123 45 6 7
highlighter.setText("{-# #-} module");
HighlighterIterator iterator = highlighter.createIterator(2);
assertEquals(CustomHighlighterTokenType.MULTI_LINE_COMMENT, iterator.getTokenType());
iterator = highlighter.createIterator(12);
assertEquals(CustomHighlighterTokenType.KEYWORD_1, iterator.getTokenType());
}
示例8: testBrokenText
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
public void testBrokenText() {
myFixture.configureByText("a.java", "import java.util.ArrayList;" +
"class A {" +
" ArrayList<caret><String");
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);
}
示例9: testBinaryStatement
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
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);
}
示例10: getAllTokens
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
public static List<IElementType> getAllTokens(EditorHighlighter highlighter) {
List<IElementType> tokens = new ArrayList<IElementType>();
HighlighterIterator iterator = highlighter.createIterator(0);
while (!iterator.atEnd()) {
tokens.add(iterator.getTokenType());
iterator.advance();
}
return tokens;
}
示例11: isLexemeBoundary
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
/**
* Finds out whether there's a boundary between two lexemes of different type at given offset.
*/
public static boolean isLexemeBoundary(@NotNull Editor editor, int offset) {
if (!(editor instanceof EditorEx) || offset <= 0 || offset >= editor.getDocument().getTextLength()) return false;
if (CharArrayUtil.isEmptyOrSpaces(editor.getDocument().getImmutableCharSequence(), offset - 1, offset + 1)) return false;
EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
HighlighterIterator it = highlighter.createIterator(offset);
if (it.getStart() != offset) {
return false;
}
IElementType rightToken = it.getTokenType();
it.retreat();
IElementType leftToken = it.getTokenType();
return !Comparing.equal(leftToken, rightToken);
}
示例12: paintBorderEffect
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
private void paintBorderEffect(Graphics2D g,
ClipDetector clipDetector,
EditorHighlighter highlighter,
int clipStartOffset,
int clipEndOffset) {
HighlighterIterator it = highlighter.createIterator(clipStartOffset);
while (!it.atEnd() && it.getStart() < clipEndOffset) {
TextAttributes attributes = it.getTextAttributes();
if (isBorder(attributes)) {
paintBorderEffect(g, clipDetector, it.getStart(), it.getEnd(), attributes);
}
it.advance();
}
}
示例13: paintHighlighters
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
public void paintHighlighters(EditorHighlighter highlighter) {
int startOffset = startOfLineByOffset(myStartOffset);
if (startOffset < 0 || startOffset >= myEditor.getDocument().getTextLength()) return;
RangeIterator iterator = new RangeIterator(new FoldingOrNewLineGaps(myEditor), SAME_COLOR_BOXES,
highlighter.createIterator(startOffset),
BOX_FILTER);
iterator.init(myRange);
while (!iterator.atEnd()) {
iterator.advance();
paintBorder(myGraphics, myEditor, iterator.getStart(), iterator.getEnd(),
iterator.getTextAttributes().getEffectColor(), iterator.getTextAttributes().getEffectType());
}
}
示例14: isBetweenXmlTags
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
private static boolean isBetweenXmlTags(Project project, Editor editor, PsiFile file, int offset) {
if (offset == 0) return false;
CharSequence chars = editor.getDocument().getCharsSequence();
if (chars.charAt(offset - 1) != '>') return false;
EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
if (iterator.getTokenType() != XmlTokenType.XML_TAG_END) return false;
if (isAtTheEndOfEmptyTag(project, editor, file, iterator)) {
return false;
}
iterator.retreat();
int retrieveCount = 1;
while(!iterator.atEnd()) {
final IElementType tokenType = iterator.getTokenType();
if (tokenType == XmlTokenType.XML_END_TAG_START) return false;
if (tokenType == XmlTokenType.XML_START_TAG_START) break;
++retrieveCount;
iterator.retreat();
}
for(int i = 0; i < retrieveCount; ++i) iterator.advance();
iterator.advance();
return !iterator.atEnd() && iterator.getTokenType() == XmlTokenType.XML_END_TAG_START;
}
示例15: getUnmatchedLBracesNumberBefore
import com.intellij.openapi.editor.highlighter.EditorHighlighter; //导入方法依赖的package包/类
/**
* Calculates number of unmatched left braces before the given offset.
*
* @param editor target editor
* @param offset target offset
* @param fileType target file type
* @return number of unmatched braces before the given offset;
* negative value if it's not possible to perform the calculation or if there are no unmatched left braces before
* the given offset
*/
protected static int getUnmatchedLBracesNumberBefore(Editor editor, int offset, FileType fileType) {
if (offset == 0) {
return -1;
}
CharSequence chars = editor.getDocument().getCharsSequence();
if (chars.charAt(offset - 1) != '{') {
return -1;
}
EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
if (!braceMatcher.isLBraceToken(iterator, chars, fileType) || !braceMatcher.isStructuralBrace(iterator, chars, fileType)) {
return -1;
}
Language language = iterator.getTokenType().getLanguage();
iterator = highlighter.createIterator(0);
int lBracesBeforeOffset = 0;
int lBracesAfterOffset = 0;
int rBracesBeforeOffset = 0;
int rBracesAfterOffset = 0;
for (; !iterator.atEnd(); iterator.advance()) {
IElementType tokenType = iterator.getTokenType();
if (!tokenType.getLanguage().equals(language) || !braceMatcher.isStructuralBrace(iterator, chars, fileType)) {
continue;
}
boolean beforeOffset = iterator.getStart() < offset;
if (braceMatcher.isLBraceToken(iterator, chars, fileType)) {
if (beforeOffset) {
lBracesBeforeOffset++;
}
else {
lBracesAfterOffset++;
}
}
else if (braceMatcher.isRBraceToken(iterator, chars, fileType)) {
if (beforeOffset) {
rBracesBeforeOffset++;
}
else {
rBracesAfterOffset++;
}
}
}
return lBracesBeforeOffset - rBracesBeforeOffset - (rBracesAfterOffset - lBracesAfterOffset);
}