Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to override XbaseCompiler
how to override XbaseCompiler [message #762749] Thu, 08 December 2011 15:18 Go to next message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
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.
Re: how to override XbaseCompiler [message #762910 is a reply to message #762749] Thu, 08 December 2011 19:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

have a look at http://www.eclipse.org/forums/index.php/mv/msg/262355/757528/#msg_757528

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override XbaseCompiler [message #763663 is a reply to message #762910] Sat, 10 December 2011 08:37 Go to previous message
tiange zhang is currently offline tiange zhangFriend
Messages: 16
Registered: February 2011
Location: Shanghai, China
Junior Member
Thanks.

I read the forums article and the blog article, but still don't known why there are two method to be overrided, it seems _toJavaExpression is enough
Previous Topic:[Xtext 2.1.1] interface segregation
Next Topic:Source file handling for artefacts which shouldn't be overwritten
Goto Forum:
  


Current Time: Sat Apr 20 02:00:42 GMT 2024

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

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

Back to the top