Good morning everyone,
I'm currently trying to override some methods of the TypeConvertingCompiler for my own Castexpression which uses custom types.
My grammar for this looks like the following:
@Override XUnaryOperation returns XExpression:
{XUnaryOperation} feature=[types::JvmIdentifiableElement|OpUnary] operand=XUnaryOperation
| CastedExpression;
CastedExpression returns XExpression:
XPostfixOperation (=>({CastedExpression.target=current} 'as') typing=DataType)*
;
The typing works just fine for it. My DataTypes are basically:
SimpleDataType:
{SimpleDataType} typeName=('integer' | 'string' | 'rational' | 'boolean');
My compiler now does the following:
protected def _toJavaExpression(CastedExpression expr, ITreeAppendable b) {
b.append("((");
if (expr.typing instanceof SimpleDataType) {
b.append(getClassType((expr.typing as SimpleDataType).typeName))
}//returns something like "Integer" or "String"
b.append(") ");
b.append(expr.getTarget().toString())
b.append(")");
}
Afterwards the TypeConvertingCompiler (http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.3/org/eclipse/xtext/xbase/compiler/TypeConvertingCompiler.html) gets called. I tried overriding the class by creating a new Java Class, adding a println to see if it works and binding it to the RuntimeModule, but my class doesn't get called.
My RuntimeModule is the following:
/* Adds the customized TypeComputer */
def Class<? extends ITypeComputer> bindITypeComputer() {
AthenaTypeComputer
}
/* Adds the customized Compiler */
def Class<? extends XbaseCompiler> bindXbaseCompiler() {
AthenaCompiler
}
/* Adds the operator mapping to the language */
def Class<? extends OperatorMapping> bindOperatorMapping() {
OperatorMappingCustom
}
def Class<? extends ImplicitlyImportedFeatures> bindImplicitlyImportedFeatures() {
AthenaImplcitlyImportedFeatures
}
def Class<? extends TypeConvertingCompiler> bindTypeConvertingCompiler() {
AthenaTypeConvertingCompiler
}
If I debug my project I also see it using the default TypeConvertingClass.
The head of my class looks like this:
public class AthenaTypeConvertingCompiler extends TypeConvertingCompiler { /* currently copy pasted class with println */ }
What I finally want to achieve is, that the program:
variable a : integer;
a <-- 4;
variable b : rational;
b <-- a as rational;
Gives the following output:
int a;
a = 4;
double b;
int _a = a;
b = (((Integer) a)).intValue(); // SHOULD BE GIVEN
b = (((Integer) a)).integerValue(); // Currently given due to my custom typing.
What can I do to change this behaviour?
If there are any questions feel free to ask. Thanks in advance!