I have a custom parser that extends AbstractParser and in its parse() method, it uses "result.addNotice(n)" to add instances of DefaultParserNotice.
Everything seems to work real well, but sometimes a notice stays there and won't go away (even though the parse() method does not return any notices at all). You can type in the underlined text, and the notice seems to maintain the position in the document (grows/shrinks as you type).
Do you have any idea where I should look?
My parser class looks like this:
- Code: Select all
class MyParser extends AbstractParser {
private DefaultParseResult result;
MyParser() {
result = new DefaultParseResult(this);
// ....
}
public ParseResult parse(RSyntaxDocument doc, String style) {
result.clearNotices();
Element root = doc.getDefaultRootElement();
result.setParsedLines(0, root.getElementCount()-1);
try {
// ...
DefaultParserNotice n = new DefaultParserNotice(
this,
error.getMessage(), // a String
rowNumber(error.getStart(), doc),
error.getStart(),
Math.max(error.getEnd() - error.getStart() + 1, 1));
if ( error.getError_type().equals(ExpressionErrorType.semantic_error) ) {
n.setLevel(DefaultParserNotice.WARNING);
n.setColor(new Color(0, 192, 0));
}
else {
n.setLevel(DefaultParserNotice.ERROR);
n.setColor(new Color(255, 0, 0));
}
result.addNotice(n);
// ...
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
return result;
}
private int rowNumber(int position, RSyntaxDocument doc) {
for (int i = 0; i < doc.getDefaultRootElement().getElementCount(); i++) {
Element e = doc.getDefaultRootElement().getElement(i);
if (position >= e.getStartOffset() && position <= e.getEndOffset())
return i + 1;
}
return doc.getRootElements().length;
}
}
Thanks,
Filip
