use of org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult in project knime-core by knime.
the class JSnippetParser method parse.
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(final RSyntaxDocument doc, final String style) {
assert m_snippet.getDocument() == doc;
JavaSnippetCompiler compiler = new JavaSnippetCompiler(m_snippet);
StringWriter log = new StringWriter();
DiagnosticCollector<JavaFileObject> digsCollector = new DiagnosticCollector<>();
CompilationTask compileTask = null;
try {
compileTask = compiler.getTask(log, digsCollector);
} catch (IOException e) {
LOGGER.error("Cannot create an compile task.", e);
return new DefaultParseResult(this);
}
compileTask.call();
DefaultParseResult parseResult = new DefaultParseResult(this);
parseResult.setError(null);
for (Diagnostic<? extends JavaFileObject> d : digsCollector.getDiagnostics()) {
boolean isSnippet = m_snippet.isSnippetSource(d.getSource());
if (isSnippet) {
DefaultParserNotice notice = new DefaultParserNotice(this, d.getMessage(Locale.US), (int) d.getLineNumber(), (int) d.getStartPosition(), (int) (d.getEndPosition() - d.getStartPosition() + 1));
if (d.getKind().equals(Kind.ERROR)) {
notice.setLevel(ParserNotice.Level.ERROR);
// LOGGER.error(d.getMessage(Locale.US));
} else if (d.getKind().equals(Kind.WARNING)) {
notice.setLevel(ParserNotice.Level.WARNING);
// LOGGER.warn(d.getMessage(Locale.US));
} else {
notice.setLevel(ParserNotice.Level.INFO);
// LOGGER.debug(d.getMessage(Locale.US));
}
parseResult.addNotice(notice);
}
}
return parseResult;
}
use of org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult in project knime-core by knime.
the class AbstractRuleParser method parse.
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(final RSyntaxDocument doc, final String style) {
if (isNotApplicable(style)) {
return new DefaultParseResult(this);
}
DefaultParseResult res = new DefaultParseResult(this);
Element rootElement = doc.getDefaultRootElement();
boolean wasCatchAllRule = false;
for (int line = 0; line < rootElement.getElementCount(); ++line) {
String lastString = null;
StringBuilder sb = new StringBuilder();
// Go through the tokens
Token token = doc.getTokenListForLine(line);
while (token != null && token.isPaintable()) {
String lexeme = token.getLexeme();
// If it is an operator, make it a reserved word.
if (getOperators().contains(lexeme)) {
token.setType(TokenTypes.RESERVED_WORD);
token.setLanguageIndex(0);
}
sb.append(lexeme);
if (lexeme.length() > 0 && lexeme.charAt(0) == '"' && lexeme.charAt(lexeme.length() - 1) == '"') {
lastString = lexeme;
}
token = token.getNextToken();
}
try {
String lineText = sb.toString();
// Check for potential error in outcomes.
if (lineText.trim().endsWith("\"") && m_warnOnColRefsInStrings) {
String lastContent = lastString != null && lastString.length() > 2 ? lastString.substring(1, lastString.length() - 1) : lastString;
// ENH better check
if (lastContent != null && lastContent.endsWith("$") && lastContent.charAt(0) == '$') {
DefaultParserNotice notice = new DefaultParserNotice(this, "You might be referring to a column or flow variable, although no String " + "interpolation is implemented, you might want to " + "remove the quotes around the reference.", line, doc.getTokenListForLine(line).getOffset() + lineText.lastIndexOf(lastContent), lastContent.length());
notice.setLevel(ParserNotice.Level.WARNING);
res.addNotice(notice);
}
}
if (!lineText.isEmpty()) {
wasCatchAllRule |= parseAndWarn(doc, res, wasCatchAllRule, line, lineText);
}
} catch (ParseException e) {
DefaultParserNotice notice;
if (e.getErrorOffset() >= sb.length()) {
notice = new DefaultParserNotice(this, e.getMessage(), line);
} else {
notice = new DefaultParserNotice(this, e.getMessage(), line, doc.getTokenListForLine(line).getOffset() + e.getErrorOffset(), sb.length() - e.getErrorOffset());
}
res.addNotice(notice);
}
}
return res;
}
Aggregations