I am overriding the standard error messages used by Xtext. In my SyntaxErrorMessageProvider
I am checking feature types. If the user typed in an double
there should be a possibility to change it to integer
by simply cutting the decimal places.
@Override
public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
if (context.getRecognitionException() instanceof MismatchedTokenException) {
MismatchedTokenException exception = (MismatchedTokenException) context
.getRecognitionException();
String value = exception.token.getText();
if (isDouble(value)) {
return new SyntaxErrorMessage("Parser error: The parameter '"
+ value + "' has a wrong type. It should be integer.",
IssueCodes.UNEXPECTED_DOUBLE_VALUE);
}
}
// should never happen!
return null;
}
The new SyntaxErrorMessage
object only holds the error message and the IssueCode
. In my QuickfixProvider
I want to offer a quickfix, which changes the DOUBLE
value to an INTEGER
:
@Fix(IssueCodes.UNEXPECTED_DOUBLE_VALUE)
public void changeDoubleToInt(final Issue issue,
IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Change to integer", "Change variable value to integer.",
"correction_change.gif", new IModification() {
public void apply(IModificationContext context)
throws BadLocationException {
IXtextDocument xtextDocument = context
.getXtextDocument();
// cut decimal places
}
});
}
But to do that, I need the double
value. Is it possible to commit the double value in the SyntacErrorMessageProvider
so that I can work with it in the QuickfixProvider
?