use of org.eclipse.jface.text.rules.IToken in project eclipse.platform.text by eclipse.
the class WordRuleTest method testBug163116.
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=163116
*/
@Test
public void testBug163116() throws Exception {
IWordDetector detector = new IWordDetector() {
@Override
public boolean isWordPart(char c) {
return true;
}
@Override
public boolean isWordStart(char c) {
return true;
}
};
WordRule rule = new WordRule(detector, new Token(this));
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setRules(new IRule[] { rule });
scanner.setRange(new Document(), 0, 0);
IToken token = null;
int i = 0;
while (token != Token.EOF && i++ < 1000) token = scanner.nextToken();
assertTrue(i < 1000);
}
use of org.eclipse.jface.text.rules.IToken in project tmdm-studio-se by Talend.
the class ElementFKInfoColorProvider method getToken.
public IToken getToken(String prefKey) {
Token token = (Token) tokenTable.get(prefKey);
if (token == null) {
String colorName = store.getString(prefKey);
if (colorName == null || colorName.isEmpty()) {
if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_DEFAULT)) {
// $NON-NLS-1$
colorName = "0,128,0";
} else if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_STRING)) {
// $NON-NLS-1$
colorName = "0,0,255";
} else if (prefKey.equals(ElementFKInfoConfiguration.PREF_COLOR_KEYWORD)) {
// $NON-NLS-1$
colorName = "0,0,128";
}
}
RGB rgb = StringConverter.asRGB(colorName);
token = new Token(new TextAttribute(getColor(rgb)));
tokenTable.put(prefKey, token);
}
return token;
}
use of org.eclipse.jface.text.rules.IToken in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method initialize.
protected void initialize() {
partitionScanner.setRange(document, 0, document.getLength());
try {
for (IToken token = partitionScanner.nextToken(); !token.isEOF(); token = partitionScanner.nextToken()) {
String contentType = getTokenContentType(token);
if (isSupportedContentType(contentType)) {
TypedPosition p = createPosition(partitionScanner.getTokenOffset(), partitionScanner.getTokenLength(), contentType);
addPosition(document, positionCategory, p);
}
}
} catch (BadLocationException _ex) {
} catch (BadPositionCategoryException _ex) {
}
}
use of org.eclipse.jface.text.rules.IToken in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method documentChanged2.
public IRegion documentChanged2(DocumentEvent e) {
try {
IDocument d = e.getDocument();
Position[] category = d.getPositions(positionCategory);
IRegion line = d.getLineInformationOfOffset(e.getOffset());
int reparseStart = line.getOffset();
int partitionStart = -1;
String contentType = null;
int first = d.computeIndexInCategory(positionCategory, reparseStart);
if (first > 0) {
TypedPosition partition = (TypedPosition) category[first - 1];
if (partition.includes(reparseStart)) {
partitionStart = partition.getOffset();
contentType = partition.getType();
if (e.getOffset() == partition.getOffset() + partition.getLength()) {
reparseStart = partitionStart;
}
first--;
} else if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
partitionStart = partition.getOffset();
contentType = partition.getType();
reparseStart = partitionStart;
first--;
} else {
partitionStart = partition.getOffset() + partition.getLength();
// $NON-NLS-1$
contentType = "__dftl_partition_content_type";
}
}
positionUpdater.update(e);
for (int i = first; i < category.length; i++) {
Position p = category[i];
if (!p.isDeleted) {
continue;
}
rememberDeletedOffset(e.getOffset());
break;
}
category = d.getPositions(positionCategory);
partitionScanner.setPartialRange(d, reparseStart, d.getLength() - reparseStart, contentType, partitionStart);
int lastScannedPosition = reparseStart;
for (IToken token = partitionScanner.nextToken(); !token.isEOF(); ) {
contentType = getTokenContentType(token);
if (!isSupportedContentType(contentType)) {
token = partitionScanner.nextToken();
} else {
int start = partitionScanner.getTokenOffset();
int length = partitionScanner.getTokenLength();
lastScannedPosition = (start + length) - 1;
for (; first < category.length; first++) {
TypedPosition p = (TypedPosition) category[first];
if (lastScannedPosition < p.offset + p.length && (!p.overlapsWith(start, length) || d.containsPosition(positionCategory, start, length) && contentType.equals(p.getType()))) {
break;
}
rememberRegion(p.offset, p.length);
d.removePosition(positionCategory, p);
}
if (d.containsPosition(positionCategory, start, length)) {
if (lastScannedPosition > e.getOffset()) {
return createRegion();
}
first++;
} else {
try {
TypedPosition p = createPosition(start, length, contentType);
addPosition(d, positionCategory, p);
rememberRegion(start, length);
} catch (BadPositionCategoryException _ex) {
} catch (BadLocationException _ex) {
}
}
token = partitionScanner.nextToken();
}
}
if (lastScannedPosition != reparseStart)
lastScannedPosition++;
for (first = d.computeIndexInCategory(positionCategory, lastScannedPosition); first < category.length; ) {
TypedPosition p = (TypedPosition) category[first++];
d.removePosition(positionCategory, p);
rememberRegion(p.offset, p.length);
}
} catch (BadPositionCategoryException _ex) {
} catch (BadLocationException _ex) {
}
return createRegion();
}
use of org.eclipse.jface.text.rules.IToken in project abstools by abstools.
the class Preferences method getToken.
public static IToken getToken(IPreferenceStore store, String postfix) {
Color color = new Color(Display.getCurrent(), PreferenceConverter.getColor(store, SYNTAXCOLOR_COLOR + postfix));
IToken token = new Token(new TextAttribute(color, null, computeAttributes(store, postfix)));
return token;
}
Aggregations