Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » RuntimeException: Cannot root twice
RuntimeException: Cannot root twice [message #1740970] Sun, 21 August 2016 22:07 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
In my JvmModelInferrer, I want to determine if the XExpression associated to a function is a type literal.
public class FakeJvmModelInferrer extends XtendJvmModelInferrer {

       @Inject private TypesFactory typesFactory;

       @Inject private IJvmModelAssociator associator;

	protected void transform(final XtendFunction source, final JvmGenericType container, boolean allowDispatch) {
			final JvmOperation operation = this.typesFactory.createJvmOperation();
			container.getMembers().add(operation);
			this.associator.associatePrimary(source, operation);
			operation.setSimpleName(source.getName());
                        setBody(operation, source.getExpression());            
                         final List<XFeatureCall> calls =        EcoreUtil2.getAllContentsOfType(source.getExpression(), XFeatureCall.class);
	                boolean isType =  calls.isEmpty() ? false : calls.get(0).isTypeLiteral();
                        if (isType) {
                            // Append annotation
                        }
       }

}


The call to isTypeLiteral function causes the following exception:
java.lang.RuntimeException: Cannot root twice
	at org.eclipse.xtext.xbase.typesystem.internal.DefaultBatchTypeResolver$1.add(DefaultBatchTypeResolver.java:73)
	at org.eclipse.xtext.xbase.typesystem.internal.DefaultBatchTypeResolver$1.add(DefaultBatchTypeResolver.java:1)
	at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver$1.add(LogicalContainerAwareReentrantTypeResolver.java:325)
	at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver$1.add(LogicalContainerAwareReentrantTypeResolver.java:1)
	at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver.recordExpressions(LogicalContainerAwareReentrantTypeResolver.java:416)
	at org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver._recordExpressions(LogicalContainerAwareReentrantTypeResolver.java:446)


What is wrong in my approach?
Re: RuntimeException: Cannot root twice [message #1740973 is a reply to message #1740970] Mon, 22 August 2016 03:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13888
Registered: July 2009
Senior Member
are you sure you completely eliminated the superclasses transform method or is it called as well?
it it is called as well then the

setBody(operation, source.getExpression());

will be done twice?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: RuntimeException: Cannot root twice [message #1740992 is a reply to message #1740973] Mon, 22 August 2016 09:14 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear Christian.

I'm sure that setBody is called once time. And I do not call the super method. In my example, I remove a couple of lines related to the return type, the parameters, etc. I have assumed they have no impact on my problem.

When I comment out the setBody call, the exception disappears; but the Java function has no body at the end.

I have coded an extension of the XtendReentrantTypeResolver:
public class SARLReentrantTypeResolver extends XtendReentrantTypeResolver {

	@Override
	protected void setAllRootedExpressions(final Set<EObject> allRootedExpressions) {
		super.setAllRootedExpressions(allRootedExpressions);
		this.rootedInstances = new HashSet<EObject>() {
			private static final long serialVersionUID = 7251944818719556729L;

			@Override
			public boolean add(EObject element) {
				// FIXME: Fixing type resolution issue
				if (!allRootedExpressions.contains(element) && !allRootedExpressions.add(element)) {
					throw new IllegalStateException("Cannot root object twice: " + element); //$NON-NLS-1$
				}
				return super.add(element);
			}
		};
	}

}


I added the test "allRootedExpressions.contains(element)" for avoiding exceptions.
This patch seems to solve my problem.
I do not detect any additional issue applied by this change yet.

Do you see any drawback?
Re: RuntimeException: Cannot root twice [message #1740993 is a reply to message #1740992] Mon, 22 August 2016 09:21 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13888
Registered: July 2009
Senior Member
i dont know the drawbacks.
unfortunately i dont have the time to setup a reproducing example


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Model inferrer assign non final content to body
Next Topic:Validating a Keyword
Goto Forum:
  


Current Time: Thu Apr 22 16:31:20 GMT 2021

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

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

Back to the top