Skip to main content



      Home
Home » Modeling » TMF (Xtext) » RuntimeException: Cannot root twice
RuntimeException: Cannot root twice [message #1740970] Sun, 21 August 2016 18:07 Go to next message
Eclipse UserFriend
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] Sun, 21 August 2016 23:44 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: RuntimeException: Cannot root twice [message #1740992 is a reply to message #1740973] Mon, 22 August 2016 05:14 Go to previous messageGo to next message
Eclipse UserFriend
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 05:21 Go to previous message
Eclipse UserFriend
i dont know the drawbacks.
unfortunately i dont have the time to setup a reproducing example
Previous Topic:Model inferrer assign non final content to body
Next Topic:Validating a Keyword
Goto Forum:
  


Current Time: Thu Jul 10 06:59:38 EDT 2025

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

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

Back to the top