use of org.eclipse.jface.text.rules.IToken in project webtools.sourceediting by eclipse.
the class LineStyleProviderForJava method prepareRegions.
public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) {
boolean result = true;
/* Initialize the text attributes. Also load the colors and initialize the rules of the scanner */
getTextAttributes();
try {
// ideally, eventually, we'll have a "virtualDocument" we can
// refer to, but for now ... we'll simple rescan the one region.
// use simple adjustment (since "sub-content" starts at 0
int lastStart = typedRegion.getOffset();
int length = 0;
IToken lastToken = Token.UNDEFINED;
fScanner.setRange(getDocument(), lastStart, typedRegion.getLength());
while (true) {
IToken token = fScanner.nextToken();
if (token.isEOF()) {
if (!lastToken.isUndefined() && length != 0) {
addRange(holdResults, lastStart, length, getTokenTextAttribute(lastToken));
}
break;
}
if (token.isWhitespace()) {
length += fScanner.getTokenLength();
continue;
}
if (lastToken.isUndefined()) {
lastToken = token;
length += fScanner.getTokenLength();
continue;
}
if (token != lastToken) {
addRange(holdResults, lastStart, length, getTokenTextAttribute(lastToken));
lastToken = token;
lastStart = fScanner.getTokenOffset();
length = fScanner.getTokenLength();
continue;
}
length += fScanner.getTokenLength();
}
} catch (Exception e) {
// shouldn't happen, but we don't want it to stop other
// highlighting, if it does.
result = false;
}
return result;
}
use of org.eclipse.jface.text.rules.IToken in project webtools.sourceediting by eclipse.
the class LineStyleProviderForJSPEL method prepareRegions.
public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) {
boolean result = true;
try {
// ideally, eventually, we'll have a "virtualDocument" we can
// refer to, but for now ... we'll simple rescan the one region.
// use simple adjustment (since "sub-content" starts at 0
int offsetAdjustment = typedRegion.getOffset();
String content = fDocument.get(typedRegion.getOffset(), typedRegion.getLength());
IDocument document = new Document(content);
int lastStart = 0;
int length = 0;
IToken lastToken = Token.UNDEFINED;
int remainingLength = typedRegion.getLength();
fScanner.setRange(document, lastStart, remainingLength);
while (true) {
IToken token = fScanner.nextToken();
if (token.isEOF()) {
if (!lastToken.isUndefined() && length != 0)
addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken));
break;
}
if (token.isWhitespace()) {
length += fScanner.getTokenLength();
continue;
}
if (lastToken.isUndefined()) {
lastToken = token;
length += fScanner.getTokenLength();
continue;
}
if (token != lastToken) {
addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken));
lastToken = token;
lastStart = fScanner.getTokenOffset();
length = fScanner.getTokenLength();
continue;
}
length += fScanner.getTokenLength();
}
} catch (BadLocationException e) {
// shouldn't happen, but we don't want it to stop other
// highlighting, if it does.
result = false;
}
return result;
}
use of org.eclipse.jface.text.rules.IToken in project liferay-ide by liferay.
the class Configuration method getPresentationReconciler.
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
IToken defaultToken = null;
DefaultDamagerRepairer dr = null;
NonRuleBasedDamagerRepairer ndr = null;
defaultToken = new Token(new TextAttribute(colorManager.getColor(Constants.COLOR_DIRECTIVE)));
ContentScanner contentScanner = new ContentScanner(defaultToken, colorManager);
for (int i = 0; i < PartitionScanner.DIRECTIVES.length; i++) {
dr = new DefaultDamagerRepairer(contentScanner);
reconciler.setDamager(dr, PartitionScanner.DIRECTIVES[i]);
reconciler.setRepairer(dr, PartitionScanner.DIRECTIVES[i]);
}
dr = new DefaultDamagerRepairer(contentScanner);
reconciler.setDamager(dr, PartitionScanner.FTL_DIRECTIVE);
reconciler.setRepairer(dr, PartitionScanner.FTL_DIRECTIVE);
dr = new DefaultDamagerRepairer(contentScanner);
reconciler.setDamager(dr, PartitionScanner.FTL_DIRECTIVE_END);
reconciler.setRepairer(dr, PartitionScanner.FTL_DIRECTIVE_END);
ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(Constants.COLOR_XML_COMMENT)));
reconciler.setDamager(ndr, PartitionScanner.XML_COMMENT);
reconciler.setRepairer(ndr, PartitionScanner.XML_COMMENT);
ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(Constants.COLOR_STRING)));
reconciler.setDamager(ndr, PartitionScanner.STRING);
reconciler.setRepairer(ndr, PartitionScanner.STRING);
ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(Constants.COLOR_COMMENT)));
reconciler.setDamager(ndr, PartitionScanner.FTL_COMMENT);
reconciler.setRepairer(ndr, PartitionScanner.FTL_COMMENT);
defaultToken = new Token(new TextAttribute(colorManager.getColor(Constants.COLOR_INTERPOLATION)));
dr = new DefaultDamagerRepairer(new ContentScanner(defaultToken, colorManager));
reconciler.setDamager(dr, PartitionScanner.FTL_INTERPOLATION);
reconciler.setRepairer(dr, PartitionScanner.FTL_INTERPOLATION);
defaultToken = new Token(new TextAttribute(colorManager.getColor(Constants.COLOR_XML_TAG)));
dr = new DefaultDamagerRepairer(new ContentScanner(defaultToken, colorManager));
reconciler.setDamager(dr, PartitionScanner.XML_TAG);
reconciler.setRepairer(dr, PartitionScanner.XML_TAG);
return reconciler;
}
use of org.eclipse.jface.text.rules.IToken in project syncope by apache.
the class InnerCSSScanner method createRules.
@Override
protected List<IRule> createRules() {
RGB rgb = IHTMLColorConstants.TAGLIB;
Color color = new Color(Display.getCurrent(), rgb);
IToken tag = new Token(new TextAttribute(color));
rgb = IHTMLColorConstants.CSS_COMMENT;
color = new Color(Display.getCurrent(), rgb);
IToken comment = new Token(new TextAttribute(color));
List<IRule> rules = new ArrayList<IRule>();
rules.add(new SingleLineRule(" <style", ">", tag));
rules.add(new SingleLineRule(" </style", ">", tag));
rules.add(new MultiLineRule("/*", "*/", comment));
rules.addAll(super.createRules());
return rules;
}
use of org.eclipse.jface.text.rules.IToken in project syncope by apache.
the class InnerJavaScriptScanner method createRules.
@Override
protected List<IRule> createRules() {
IToken tag = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.TAG)));
IToken comment = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_COMMENT)));
IToken jsdoc = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JSDOC)));
List<IRule> rules = super.createRules();
rules.add(new SingleLineRule(" <script", ">", tag));
rules.add(new SingleLineRule(" </script", ">", tag));
rules.add(new MultiLineRule("/**", "*/", jsdoc));
rules.add(new MultiLineRule("/*", "*/", comment));
return rules;
}
Aggregations