本文整理汇总了Java中com.intellij.openapi.editor.highlighter.HighlighterIterator类的典型用法代码示例。如果您正苦于以下问题:Java HighlighterIterator类的具体用法?Java HighlighterIterator怎么用?Java HighlighterIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HighlighterIterator类属于com.intellij.openapi.editor.highlighter包,在下文中一共展示了HighlighterIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRBraceToken
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
public boolean isRBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
BracePair pair = findPair(false, iterator, fileText, fileType);
if (pair == null) return false;
if (pair.getRightBraceType() != AppleScriptTypes.END)
return super.isRBraceToken(iterator, fileText, fileType);//true;
boolean result = false;
int count = 0;
while (true) {
iterator.retreat();
count++;
if (iterator.atEnd()) break;
IElementType eType = iterator.getTokenType();
if (eType == AppleScriptTypes.NLS || eType == AppleScriptTypes.BLOCK_BODY)
result = true;
else break;
}
while (count-- > 0) iterator.advance();
return result;
}
示例2: calcParensBalance
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的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;
}
示例3: isClosingQuote
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
boolean closingQuote = super.isClosingQuote(iterator, offset);
if (closingQuote) {
// check escape next
if (!iterator.atEnd()) {
iterator.advance();
if (!iterator.atEnd() && StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType())) {
closingQuote = false;
}
iterator.retreat();
}
}
return closingQuote;
}
示例4: testCpp
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的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());
}
示例5: findEndTagStart
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
private static boolean findEndTagStart(HighlighterIterator iterator) {
IElementType tokenType = iterator.getTokenType();
int balance = 0;
int count = 0;
while(balance >= 0){
iterator.retreat();
count++;
if (iterator.atEnd()) break;
tokenType = iterator.getTokenType();
if (tokenType == XmlTokenType.XML_TAG_END || tokenType == XmlTokenType.XML_EMPTY_ELEMENT_END){
balance++;
}
else if (tokenType == XmlTokenType.XML_END_TAG_START || tokenType == XmlTokenType.XML_START_TAG_START){
balance--;
}
}
while(count-- > 0) iterator.advance();
return tokenType == XmlTokenType.XML_END_TAG_START;
}
示例6: handleBetweenSquareBraces
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的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;
}
示例7: processWords
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
private static void processWords(Editor editor, int startOffset, TokenProcessor processor) {
CharSequence chars = editor.getDocument().getCharsSequence();
HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(startOffset);
while (!iterator.atEnd()) {
int start = iterator.getStart();
int end = iterator.getEnd();
while (start < end) {
int wordStart = start;
while (wordStart < end && !isWordPart(chars.charAt(wordStart))) wordStart++;
int wordEnd = wordStart;
while (wordEnd < end && isWordPart(chars.charAt(wordEnd))) wordEnd++;
if (wordEnd > wordStart && containsLettersOrDigits(chars, wordStart, wordEnd) && !processor.processToken(wordStart, wordEnd)) {
return;
}
start = wordEnd + 1;
}
iterator.advance();
}
}
示例8: isNonClosedLiteral
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
protected boolean isNonClosedLiteral(HighlighterIterator iterator, CharSequence chars) {
int end = iterator.getEnd();
if (getLiteralStartOffset(chars, iterator.getStart()) >= end - 1) {
return true;
}
char endSymbol = chars.charAt(end - 1);
if (endSymbol != '"' && endSymbol != '\'') {
return true;
}
//for triple quoted string
if (end >= 3
&& (endSymbol == chars.charAt(end - 2))
&& (chars.charAt(end - 2) == chars.charAt(end - 3))
&& (end < 4 || chars.charAt(end - 4) != endSymbol)) {
return true;
}
return false;
}
示例9: isClosingQuote
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
public boolean isClosingQuote(HighlighterIterator iterator, int offset) {
final IElementType tokenType = iterator.getTokenType();
if (myLiteralTokenSet.contains(tokenType)) {
int start = iterator.getStart();
int end = iterator.getEnd();
if (end - start >= 1 && offset == end - 1) {
Document doc = iterator.getDocument();
if (doc == null) return false;
CharSequence chars = doc.getCharsSequence();
if (chars.length() > offset + 1) {
Character ch = chars.charAt(offset + 1);
if (Arrays.binarySearch(ourAutoClosingChars, ch) < 0)
return false;
}
return true;
}
}
return false;
}
示例10: highlightScope
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
private void highlightScope(int offset, @NotNull FileType fileType) {
if (myEditor.getFoldingModel().isOffsetCollapsed(offset)) return;
if (myEditor.getDocument().getTextLength() <= offset) return;
HighlighterIterator iterator = getEditorHighlighter().createIterator(offset);
final CharSequence chars = myDocument.getCharsSequence();
if (!BraceMatchingUtil.isStructuralBraceToken(fileType, iterator, chars)) {
// if (BraceMatchingUtil.isRBraceTokenToHighlight(myFileType, iterator) || BraceMatchingUtil.isLBraceTokenToHighlight(myFileType, iterator)) return;
}
else {
if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType) ||
BraceMatchingUtil.isLBraceToken(iterator, chars, fileType)) return;
}
if (!BraceMatchingUtil.findStructuralLeftBrace(fileType, iterator, chars)) {
removeLineMarkers();
return;
}
highlightLeftBrace(iterator, true, fileType);
}
示例11: isAtTheEndOfEmptyTag
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
private static boolean isAtTheEndOfEmptyTag(Project project, Editor editor, PsiFile file, HighlighterIterator iterator) {
if (iterator.getTokenType() != XmlTokenType.XML_TAG_END) {
return false;
}
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
final PsiElement element = file.findElementAt(iterator.getStart());
if (element == null) {
return false;
}
final PsiElement parent = element.getParent();
return parent instanceof XmlTag &&
parent.getTextRange().getEndOffset() == iterator.getEnd();
}
示例12: testIteratorEnd
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
public void testIteratorEnd() {
HighlighterIterator iterator = myHighlighter.createIterator(0);
assertFalse(iterator.atEnd());
iterator.retreat();
assertTrue(iterator.atEnd());
iterator.advance();
assertFalse(iterator.atEnd());
iterator.advance();
assertFalse(iterator.atEnd());
iterator.advance();
assertFalse(iterator.atEnd());
iterator.advance();
assertTrue(iterator.atEnd());
iterator.advance();
assertTrue(iterator.atEnd());
}
示例13: hasNonClosedLiteral
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
try {
Document doc = editor.getDocument();
CharSequence chars = doc.getCharsSequence();
int lineEnd = doc.getLineEndOffset(doc.getLineNumber(offset));
while (!iterator.atEnd() && iterator.getStart() < lineEnd) {
if (isQuotedToken(iterator.getTokenType())) {
if (iterator.getStart() >= iterator.getEnd() - 1 ||
chars.charAt(iterator.getEnd() - 1) != '\"' && chars.charAt(iterator.getEnd() - 1) != '\'') {
return true;
}
}
iterator.advance();
}
} finally {
while (!iterator.atEnd() && iterator.getStart() != offset) iterator.retreat();
}
return false;
}
示例14: hasNonClosedLiteral
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator iterator, int offset) {
final IElementType tokenType = iterator.getTokenType();
if (tokenType == GroovyTokenTypes.mSTRING_LITERAL || tokenType == GroovyTokenTypes.mGSTRING_BEGIN || tokenType ==
GroovyTokenTypes.mGSTRING_LITERAL || tokenType ==
GroovyTokenTypes.mGSTRING_CONTENT) {
final Document document = iterator.getDocument();
if (document == null) return false;
final String literal = document.getText().substring(iterator.getStart(), offset + 1);
if ("'''".equals(literal) || "\"\"\"".equals(literal) || "'".equals(literal) || "\"".equals(literal)) {
return true;
}
}
return !(tokenType == GroovyTokenTypes.mGSTRING_CONTENT || tokenType == GroovyTokenTypes.mGSTRING_LITERAL || tokenType ==
GroovyTokenTypes.mSTRING_LITERAL || tokenType ==
GroovyTokenTypes.mGSTRING_END);
}
示例15: isOpeningQuote
import com.intellij.openapi.editor.highlighter.HighlighterIterator; //导入依赖的package包/类
@Override
public boolean isOpeningQuote(HighlighterIterator iterator, int offset) {
if (!myLiteralTokenSet.contains(iterator.getTokenType())) {
return false;
}
int start = iterator.getStart();
if (offset == start) {
return true;
}
final Document document = iterator.getDocument();
if (document == null) {
return false;
}
CharSequence text = document.getCharsSequence();
char theQuote = text.charAt(offset);
if (offset >= 2
&& text.charAt(offset - 1) == theQuote
&& text.charAt(offset - 2) == theQuote
&& (offset < 3 || text.charAt(offset - 3) != theQuote)) {
if (super.isOpeningQuote(iterator, offset)) {
return true;
}
}
return false;
}