Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » UnsupportedOperationException on XExpression compiling
UnsupportedOperationException on XExpression compiling [message #996612] Wed, 02 January 2013 09:22 Go to next message
Tommaso De Sica is currently offline Tommaso De Sica
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

I've got these simple rules:
Expression:
	expression=XExpression
;

IfStatement:
	'IF''('condition=Expression')''{'
		statements+=Statement*
	'}'
;


Now, if I try (in my inferrer) to do something like this:
it.newLine.append('''if(«ifStat.condition.expression.toJavaExpression(it)») {''')


it causes following exception:
!STACK 0
java.lang.UnsupportedOperationException
	at org.eclipse.xtext.common.types.impl.JvmIdentifiableElementImpl.getSimpleName(JvmIdentifiableElementImpl.java:68)
	at org.eclipse.xtext.xbase.featurecalls.IdentifiableSimpleNameProvider.getSimpleName(IdentifiableSimpleNameProvider.java:48)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.getFavoriteVariableName(AbstractXbaseCompiler.java:382)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.declareFreshLocalVariable(AbstractXbaseCompiler.java:432)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:146)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:158)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:111)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:127)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:289)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.prepareExpression(FeatureCallCompiler.java:237)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:128)
	at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:113)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:127)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:289)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.toJavaStatement(AbstractXbaseCompiler.java:301)
	at it.rcpvision.ats.suitetest.jvmmodel.LanguageJvmModelInferrer.compileStatement(LanguageJvmModelInferrer.java:190)
	at it.rcpvision.ats.suitetest.jvmmodel.LanguageJvmModelInferrer$1$2$1.apply(LanguageJvmModelInferrer.java:124)
	at it.rcpvision.ats.suitetest.jvmmodel.LanguageJvmModelInferrer$1$2$1.apply(LanguageJvmModelInferrer.java:1)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateExecutableBody(JvmModelGenerator.java:784)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateMember(JvmModelGenerator.java:574)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMember(JvmModelGenerator.java:1529)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:220)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:1)
	at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:395)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateBody(JvmModelGenerator.java:225)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateBody(JvmModelGenerator.java:1501)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateType(JvmModelGenerator.java:160)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._internalDoGenerate(JvmModelGenerator.java:144)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.internalDoGenerate(JvmModelGenerator.java:1486)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.doGenerate(JvmModelGenerator.java:133)
	at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:259)
	at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:194)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:161)
	at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:141)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:91)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

[Updated on: Wed, 02 January 2013 09:48]

Report message to a moderator

Re: UnsupportedOperationException on XExpression compiling [message #996647 is a reply to message #996612] Wed, 02 January 2013 10:44 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De Sica
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

I've found the reason of Exception, but I can't solve it:
when there is a variable in my XExpression it wants to get simple name of that variable
public String getSimpleName(JvmIdentifiableElement element) {
		if (element == null || element.eIsProxy()) {
			return null;
		}
		if (element instanceof JvmFeature) {
			return ((JvmFeature) element).getSimpleName();
		}
		if (element instanceof JvmFormalParameter) {
			return ((JvmFormalParameter) element).getName();
		}
		if (element instanceof XVariableDeclaration) {
			return ((XVariableDeclaration) element).getName();
		}
		if (element instanceof XSwitchExpression) {
			final XSwitchExpression xSwitchExpression = (XSwitchExpression) element;
			String varName = xSwitchExpression.getLocalVarName();
			if (varName!=null)
				return varName;
			XExpression expression = xSwitchExpression.getSwitch();
			if (expression instanceof XFeatureCall) {
				return getSimpleName(((XFeatureCall) expression).getFeature());
			} else {
				return null;
			}
		}
		return element.getSimpleName();
	}

note: return element.getSimpleName();
but my variable has no simple name:
Variable returns jvmTypes::JvmIdentifiableElement:
	{Variable}type=JvmTypeReference simpleName=ID ';'
;

[Updated on: Wed, 02 January 2013 10:45]

Report message to a moderator

Re: UnsupportedOperationException on XExpression compiling [message #996652 is a reply to message #996647] Wed, 02 January 2013 10:59 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1321
Registered: July 2009
Senior Member
If you introduce your own expressions (which extends an Xbase class) you
have to provide your own implementation for what Xbase expects, in this
case, you must override getSimpleName and provide a case for your
Variable (and delegate to super in all other cases).

cheers
Lorenzo

On 01/02/2013 04:44 PM, Tommaso De Sica wrote:
> I've found the reason of Exception, but I can't solve it:
> when there is a variable in my XExpression it wants to get simple name
> of that variable
> public String getSimpleName(JvmIdentifiableElement element) {
> if (element == null || element.eIsProxy()) {
> return null;
> }
> if (element instanceof JvmFeature) {
> return ((JvmFeature) element).getSimpleName();
> }
> if (element instanceof JvmFormalParameter) {
> return ((JvmFormalParameter) element).getName();
> }
> if (element instanceof XVariableDeclaration) {
> return ((XVariableDeclaration) element).getName();
> }
> if (element instanceof XSwitchExpression) {
> final XSwitchExpression xSwitchExpression =
> (XSwitchExpression) element;
> String varName = xSwitchExpression.getLocalVarName();
> if (varName!=null)
> return varName;
> XExpression expression = xSwitchExpression.getSwitch();
> if (expression instanceof XFeatureCall) {
> return getSimpleName(((XFeatureCall)
> expression).getFeature());
> } else {
> return null;
> }
> }
> return element.getSimpleName();
> }
>
> but my variable has no simple name:
> Variable returns jvmTypes::JvmIdentifiableElement:
> {Variable}type=JvmTypeReference simpleName=ID ';'
> ;


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Re: UnsupportedOperationException on XExpression compiling [message #996657 is a reply to message #996647] Wed, 02 January 2013 11:16 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De Sica
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

It works, thank you!

[Updated on: Wed, 02 January 2013 11:46]

Report message to a moderator

Re: UnsupportedOperationException on XExpression compiling [message #996714 is a reply to message #996657] Wed, 02 January 2013 13:34 Go to previous message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1321
Registered: July 2009
Senior Member
On 01/02/2013 05:16 PM, Tommaso De Sica wrote:
> I've added method getSimpleName() in VariableImpl.java, but I think this
> isn't the best solution beacuse it was a generated class.

you must provide your implementation of

public String getSimpleName(JvmIdentifiableElement element)

in a subclass of the class you refer to in your original post

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Previous Topic:[Xtext] IllegalStateException "Stack of grammar elements seems to be corrupt."
Next Topic:Xtext grammar for real literals and filenames with a . dot extension
Goto Forum:
  


Current Time: Thu Aug 21 12:18:48 EDT 2014

Powered by FUDForum. Page generated in 0.01711 seconds