RuntimeException: Cannot root twice [message #1740970] |
Sun, 21 August 2016 22:07 |
|
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 #1740992 is a reply to message #1740973] |
Mon, 22 August 2016 09:14 |
|
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?
|
|
|
|
Powered by
FUDForum. Page generated in 0.02189 seconds