I try to extend xBase expression and add MyIntegerLiteral to XLiteral family, related grammar is:
XLiteral returns xbase::XExpression:
XClosure |
XBooleanLiteral |
XIntLiteral |
XNullLiteral |
XStringLiteral |
XTypeLiteral |
MyIntegerLiteral
;
MyIntegerLiteral returns xbase::XExpression:
{MyIntegerLiteral} value=MYINTEGER
;
terminal MYINTEGER :
'<<' ( !('>') )* '>>'
;
I don't know how to override XbaseCompiler._toJavaStatement and XbaseCompiler._toJavaExpression. It seems override _toJavaExpression only is enough, but if _toJavaStatement is missing, following exception will be raised.
java.lang.UnsupportedOperationException: Coudn't find a compilation strategy for expressions of type org.eclipse.xtext.example.domainmodel.domainmodel.impl.MyIntegerLiteralImpl
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler._toJavaStatement(AbstractXbaseCompiler.java:260)
......
Overridden XbaseCompiler:
public class DomainModelCompiler extends XbaseCompiler {
public void _toJavaStatement(MyIntegerLiteral func, IAppendable b, boolean isReferenced) {
//DO nothing but empty body is required
}
public void _toJavaExpression(MyIntegerLiteral func, IAppendable b) {
String body = func.getValue().substring(2, func.getValue().length() - 2);
b.append("Integer.valueOf(\"");
b.append(body);
b.append("\")");
}
}
How to implement toJavaStatement and toJavaExpression?
Thanks.