Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xbase doesn't bind overriden TypeConvertingCompiler
Xbase doesn't bind overriden TypeConvertingCompiler [message #1775434] Mon, 30 October 2017 08:47 Go to next message
René Bärnreuther is currently offline René BärnreutherFriend
Messages: 31
Registered: October 2017
Member
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!


Re: Xbase doesn't bind overriden TypeConvertingCompiler [message #1775440 is a reply to message #1775434] Mon, 30 October 2017 08:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12109
Registered: July 2009
Senior Member
i dont understand this.

xbasecompiler is a subclass of TypeConvertingCompiler already. so why two subclasses?


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase doesn't bind overriden TypeConvertingCompiler [message #1775441 is a reply to message #1775440] Mon, 30 October 2017 09:07 Go to previous message
René Bärnreuther is currently offline René BärnreutherFriend
Messages: 31
Registered: October 2017
Member
Alright, I added it in the "basic" compiler I changed and it works now, thanks for the quick help.

Previous Topic:Performance of Xtext editor
Next Topic:Literals class is not created
Goto Forum:
  


Current Time: Thu Jul 19 09:19:56 GMT 2018

Powered by FUDForum. Page generated in 0.02187 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top