use of org.eclipse.jface.text.rules.IToken in project syncope by apache.
the class JavaScriptScanner method createRules.
/**
* Creates the list of <code>IRule</code>.
* If you have to customize rules, override this method.
*
* @return the list of <code>IRule</code>
*/
protected List<IRule> createRules() {
IToken normal = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.FOREGROUND)));
IToken string = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_STRING)));
IToken comment = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_COMMENT)));
IToken keyword = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_KEYWORD)));
List<IRule> rules = new ArrayList<IRule>();
rules.add(new SingleLineRule("\"", "\"", string, '\\'));
rules.add(new SingleLineRule("'", "'", string, '\\'));
rules.add(new SingleLineRule("\\//", null, normal));
rules.add(new EndOfLineRule("//", comment));
WordRule wordRule = new WordRule(new JavaWordDetector(), normal);
for (int i = 0; i < KEYWORDS.length; i++) {
wordRule.addWord(KEYWORDS[i], keyword);
}
rules.add(wordRule);
return rules;
}
use of org.eclipse.jface.text.rules.IToken in project hale by halestudio.
the class GroovyPartitionScanner method createRules.
public static List<IRule> createRules(boolean withColor) {
IPreferenceStore store = GroovyUIPlugin.getDefault().getPreferenceStore();
Object objComment;
Object objdComment;
Object objmString;
Object objsString;
Object objsComment;
if (withColor) {
RGB rgb = PreferenceConverter.getColor(store, PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_STRINGS_COLOR);
objComment = objmString = objsString = objsComment = objdComment = new TextAttribute(new Color(null, rgb), null, SWT.ITALIC);
} else {
objComment = JAVA_MULTI_LINE_COMMENT;
objmString = GROOVY_MULTILINE_STRINGS;
objsString = JAVA_STRING;
objsComment = JAVA_SINGLE_LINE_COMMENT;
objdComment = JAVA_DOC;
}
IToken comment = new Token(objComment);
IToken mString = new Token(objmString);
IToken sString = new Token(objsString);
IToken sComment = new Token(objsComment);
IToken jdoc = new Token(objdComment);
List<IRule> rules = new ArrayList<IRule>();
// Add rule for single line comments.
rules.add(new EndOfLineRule("//", sComment));
// Add rule for strings and character constants.
rules.add(new MultiLineRule("'''", "'''", mString));
rules.add(new MultiLineRule("\"\"\"", "\"\"\"", mString));
// GRECLIPSE-1111 do not eagerly match these kinds of multiline strings
rules.add(new SingleLineRule("\"", "\"", sString, '\\'));
rules.add(new SingleLineRule("'", "'", sString, '\\'));
// GRECLIPSE-1203 make dollar slashies optionally highlighted
if (store.getBoolean(PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_SLASHY_STRINGS)) {
rules.add(new MultiLineRule("$/", "/$", mString, '\0', false));
}
// Add special case word rule.
rules.add(new WordPredicateRule(comment));
// Add rule for JavaDoc
// $NON-NLS-1$ //$NON-NLS-2$
rules.add(new MultiLineRule("/**", "*/", jdoc, (char) 0, true));
// Add rules for multi-line comments
// $NON-NLS-1$ //$NON-NLS-2$
rules.add(new MultiLineRule("/*", "*/", comment, (char) 0, true));
return rules;
}
use of org.eclipse.jface.text.rules.IToken in project dbeaver by serge-rider.
the class HTMLSQLConverter method convertText.
@NotNull
@Override
public String convertText(@NotNull SQLDialect dialect, @NotNull SQLSyntaxManager syntaxManager, @NotNull SQLRuleScanner ruleManager, @NotNull IDocument document, int startPos, int length, @NotNull Map<String, Object> options) {
StringBuilder result = new StringBuilder();
ruleManager.setRange(document, startPos, length);
try {
result.append("<pre>");
for (; ; ) {
IToken token = ruleManager.nextToken();
if (token.isEOF()) {
break;
}
int tokenOffset = ruleManager.getTokenOffset();
final int tokenLength = ruleManager.getTokenLength();
boolean hasSpan = false;
Object data = token.getData();
if (data instanceof TextAttribute) {
result.append("<span style='");
TextAttribute ta = (TextAttribute) data;
if (ta.getBackground() != null) {
result.append("background-color:").append(toHex(ta.getBackground())).append(";");
}
if (ta.getForeground() != null) {
result.append("color:").append(toHex(ta.getForeground())).append(";");
}
if ((ta.getStyle() & SWT.BOLD) == SWT.BOLD) {
result.append("font-weight:bold;");
}
if ((ta.getStyle() & SWT.ITALIC) == SWT.ITALIC) {
result.append("font-style: italic;");
}
// ta.getStyle()
result.append("'>");
hasSpan = true;
}
result.append(document.get(tokenOffset, tokenLength));
if (hasSpan) {
result.append("</span>");
}
}
result.append("</pre>");
} catch (BadLocationException e) {
log.error("Error converting SQL to HTML", e);
}
return result.toString().trim();
}
use of org.eclipse.jface.text.rules.IToken in project dbeaver by serge-rider.
the class UnformattedSQLConverter method convertText.
@NotNull
@Override
public String convertText(@NotNull SQLDialect dialect, @NotNull SQLSyntaxManager syntaxManager, @NotNull SQLRuleScanner ruleManager, @NotNull IDocument document, int startPos, int length, @NotNull Map<String, Object> options) {
StringBuilder result = new StringBuilder();
ruleManager.setRange(document, startPos, length);
String[] singleLineComments = dialect.getSingleLineComments();
Pair<String, String> multiLineComments = dialect.getMultiLineComments();
boolean lastWhitespace = false;
try {
for (; ; ) {
IToken token = ruleManager.nextToken();
if (token.isEOF()) {
break;
}
int tokenOffset = ruleManager.getTokenOffset();
final int tokenLength = ruleManager.getTokenLength();
if (token.isWhitespace()) {
if (!lastWhitespace) {
result.append(' ');
}
lastWhitespace = true;
} else if (token instanceof SQLCommentToken) {
String comment = document.get(tokenOffset, tokenLength);
for (String slc : singleLineComments) {
if (comment.startsWith(slc)) {
if (multiLineComments != null) {
comment = multiLineComments.getFirst() + comment.substring(slc.length()) + multiLineComments.getSecond();
}
break;
}
}
comment = CommonUtils.compactWhiteSpaces(comment);
result.append(comment);
} else {
lastWhitespace = false;
result.append(document.get(tokenOffset, tokenLength));
}
}
} catch (BadLocationException e) {
log.error("Error unformatting SQL", e);
}
return result.toString().trim();
}
use of org.eclipse.jface.text.rules.IToken in project dbeaver by dbeaver.
the class HTMLSQLConverter method convertText.
@NotNull
@Override
public String convertText(@NotNull SQLDialect dialect, @NotNull SQLSyntaxManager syntaxManager, @NotNull SQLRuleScanner ruleManager, @NotNull IDocument document, int startPos, int length, @NotNull Map<String, Object> options) {
StringBuilder result = new StringBuilder();
ruleManager.setRange(document, startPos, length);
try {
result.append("<pre>");
for (; ; ) {
IToken token = ruleManager.nextToken();
if (token.isEOF()) {
break;
}
int tokenOffset = ruleManager.getTokenOffset();
final int tokenLength = ruleManager.getTokenLength();
boolean hasSpan = false;
Object data = token.getData();
if (data instanceof TextAttribute) {
result.append("<span style='");
TextAttribute ta = (TextAttribute) data;
if (ta.getBackground() != null) {
result.append("background-color:").append(toHex(ta.getBackground())).append(";");
}
if (ta.getForeground() != null) {
result.append("color:").append(toHex(ta.getForeground())).append(";");
}
if ((ta.getStyle() & SWT.BOLD) == SWT.BOLD) {
result.append("font-weight:bold;");
}
if ((ta.getStyle() & SWT.ITALIC) == SWT.ITALIC) {
result.append("font-style: italic;");
}
// ta.getStyle()
result.append("'>");
hasSpan = true;
}
result.append(document.get(tokenOffset, tokenLength));
if (hasSpan) {
result.append("</span>");
}
}
result.append("</pre>");
} catch (BadLocationException e) {
log.error("Error converting SQL to HTML", e);
}
return result.toString().trim();
}
Aggregations