Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » manage eopposite references coming from imported metamodel
manage eopposite references coming from imported metamodel [message #1765199] Wed, 07 June 2017 13:13 Go to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi everybody,

I have this metamodel
index.php/fa/29579/0/

I create a Xtext grammar from this metamodel

// automatically generated by Xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "http://www.xtext.org/example/mydsl/MyDsl" 
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model returns Model:
	{Model}
	'Model'
	name=ID
	'{'
		('classAs' '{' classAs+=ClassA ( "," classAs+=ClassA)* '}' )?
	'}';
	
ClassA returns ClassA:
	{ClassA}
	'ClassA'
	name=ID
	'{'
	//	('referingbs' '(' referingbs+=[ClassB|ID] ( "," referingbs+=[ClassB|ID])* ')' )?
		('classb' '{' classb+=ClassB ( "," classb+=ClassB)* '}' )?
	'}';

ClassB returns ClassB:
	'ClassB'
	name=ID
	'{'
		'target' target=[ClassA|ID]
	'}';


My models are saved as XMI using a mechanism described in previous posts (That is not the issue).

The problem comes from the "referingbs" reference which is an eopposite reference to "target" reference.

When I create a model containing an instance of ClassB that refers to ClassA instance via target reference,
Xtext throws an error
java.lang.RuntimeException: Could not serialize ClassA:
ClassA.referingbs violates the upper bound: It holds 1 values, but only 0 are allowed.
Semantic Object: Model'model1'.classAs[0]->ClassA'class1'
URI: temp.my
Context: ClassA returns ClassA
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:503)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_ClassA(MyDslSemanticSequencer.java:59)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:38)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:352)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:263)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:434)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:501)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_Model(MyDslSemanticSequencer.java:92)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:44)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:115)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:128)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:192)
	at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:386)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)


I found this message https://www.eclipse.org/forums/index.php?t=msg&th=1079030&goto=1737136&#msg_1737136
that proposes to customize ITransientValueService feature.

I customize it by adding the following
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	
	def Class<? extends LegacyTransientValueService> bindITransientValueService2() {
		MyDslTransientValueService
	}
}


public class MyDslTransientValueService extends LegacyTransientValueService {
	@Override
	public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) {
		if (feature == MyDslPackage.Literals.CLASS_A__REFERINGBS) {
			return ValueTransient.YES;
		}
		return super.isValueTransient(semanticObject, feature);
	}

}


However the original error always appears (ClassA.referingbs violates the upper bound: It holds 1 values, but only 0 are allowed).

My question: how can I resolve this eopposite issue in Xtext?

I share the complete case-study containing an example (in the org.eclipse.example.mydsl.example project)
if someone is interested to reproduce.

best regards
Re: manage eopposite references coming from imported metamodel [message #1765223 is a reply to message #1765199] Wed, 07 June 2017 16:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
does this unittest reproduce your problem?

package org.xtext.example.mydsl.tests

import com.google.inject.Inject
import com.google.inject.Provider
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.serializer.ISerializer
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.Test
import org.junit.runner.RunWith
import myDsl.MyDslFactory

@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest {
	@Inject
	extension ISerializer ser
	
	@Inject Provider<ResourceSet> rsp
	
	@Test
	def void loadModel() {
		val rs = rsp.get
		val r = rs.createResource(URI.createURI("dummy.my"))
		val m = MyDslFactory.eINSTANCE.createModel => [
			name = "m"
			val a = MyDslFactory.eINSTANCE.createClassA => [
				name = "a"
			]
			val b = MyDslFactory.eINSTANCE.createClassB => [
				name = "b"
			]
			classAs += a
			a.classb += b
			b.target = a
		]
		r.contents += m
		println(m.serialize)
	}
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: manage eopposite references coming from imported metamodel [message #1765224 is a reply to message #1765223] Wed, 07 June 2017 16:11 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Thank you Chrisitan for reply
The test shows the same error

java.lang.RuntimeException: Could not serialize ClassA:
ClassA.referingbs violates the upper bound: It holds 1 values, but only 0 are allowed.
Semantic Object: Model'm'.classAs[0]->ClassA'a'
URI: dummy.my
Context: ClassA returns ClassA
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:503)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_ClassA(MyDslSemanticSequencer.java:59)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:38)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:352)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:263)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:434)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:501)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_Model(MyDslSemanticSequencer.java:92)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:44)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:115)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:128)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:178)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:55)
	at org.xtext.example.mydsl.tests.MyDslParsingTest.loadModel(MyDslParsingTest.java:62)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.eclipse.xtext.testing.XtextRunner$1.evaluate(XtextRunner.java:49)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)



[Updated on: Wed, 07 June 2017 16:13]

Report message to a moderator

Re: manage eopposite references coming from imported metamodel [message #1765226 is a reply to message #1765224] Wed, 07 June 2017 16:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
@Override
public ListTransient isListTransient(EObject semanticObject, EStructuralFeature feature) {
if (feature == MyDslPackage.Literals.CLASS_A__REFERINGBS) {
return ListTransient.YES;
}
return super.isListTransient(semanticObject, feature);
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: manage eopposite references coming from imported metamodel [message #1765232 is a reply to message #1765224] Wed, 07 June 2017 17:17 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Thank you Christian.

[Updated on: Wed, 07 June 2017 20:21]

Report message to a moderator

Re: manage eopposite references coming from imported metamodel [message #1765246 is a reply to message #1765232] Wed, 07 June 2017 20:29 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
A new error appears now :( .
I create this EMF model
<?xml version="1.0" encoding="UTF-8"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:myDsl="http://www.xtext.org/example/mydsl/MyDsl" name="model1">
  <classAs name="classa1" referingbs="//@classAs.0/@classb.0">
    <classb name="classb1" target="//@classAs.0"/>
  </classAs>
</myDsl:Model>


I open it with the textual editor.
It shows this model

Model model1 { classAs { ClassA classa1 { classb { ClassB classb1 { target classa1 } } } } }


When I edit the textual model (just add white space and save),
the xmi becomes
<?xml version="1.0" encoding="UTF-8"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:myDsl="http://www.xtext.org/example/mydsl/MyDsl" name="model1">
  <classAs name="classa1">
    <classb name="classb1" target="//@classAs.0"/>
  </classAs>
</myDsl:Model>


The reference referingbs="//@classAs.0/@classb.0" is removed.
And this error appears

java.lang.RuntimeException: A value for feature 'target' is missing but required.
Semantic Object: Model'model1'.classAs[0]->ClassA'classa1'.classb[0]->ClassB'classb1'
URI: temp.my
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_ClassB(MyDslSemanticSequencer.java:75)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:41)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:352)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:263)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:434)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:501)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_ClassA(MyDslSemanticSequencer.java:59)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:38)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptEObjectRuleCall(SequenceFeeder.java:325)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.acceptRuleCall(SequenceFeeder.java:352)
	at org.eclipse.xtext.serializer.acceptor.SequenceFeeder.accept(SequenceFeeder.java:263)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.accept(BacktrackingSemanticSequencer.java:434)
	at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:501)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence_Model(MyDslSemanticSequencer.java:92)
	at org.xtext.example.mydsl.serializer.MyDslSemanticSequencer.sequence(MyDslSemanticSequencer.java:44)
	at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:115)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:128)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:192)
	at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:386)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
	at org.xtext.example.mydsl.ui.MyDslDocumentProvider.setDocumentContent(MyDslDocumentProvider.java:57)
	at org.eclipse.ui.editors.text.FileDocumentProvider.setDocumentContent(FileDocumentProvider.java:425)
	at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.setDocumentContent(XtextDocumentProvider.java:183)
	at org.eclipse.ui.editors.text.FileDocumentProvider.handleElementContentChanged(FileDocumentProvider.java:814)
	at org.eclipse.ui.editors.text.FileDocumentProvider.doSynchronize(FileDocumentProvider.java:526)
	at org.eclipse.ui.texteditor.AbstractDocumentProvider$1SynchronizeOperation.execute(AbstractDocumentProvider.java:951)
	at org.eclipse.ui.texteditor.AbstractDocumentProvider$DocumentProviderOperation.run(AbstractDocumentProvider.java:72)
	at org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation.execute(WorkspaceModifyDelegatingOperation.java:67)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:107)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:128)
	at org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner.run(WorkspaceOperationRunner.java:73)
	at org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner.run(WorkspaceOperationRunner.java:63)
	at org.eclipse.ui.texteditor.AbstractDocumentProvider.executeOperation(AbstractDocumentProvider.java:536)
	at org.eclipse.ui.texteditor.AbstractDocumentProvider.synchronize(AbstractDocumentProvider.java:960)
	at org.eclipse.ui.texteditor.AbstractTextEditor.handleEditorInputChanged(AbstractTextEditor.java:4730)
	at org.eclipse.ui.texteditor.StatusTextEditor.handleEditorInputChanged(StatusTextEditor.java:252)
	at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.handleEditorInputChanged(AbstractDecoratedTextEditor.java:1485)
	at org.eclipse.ui.texteditor.AbstractTextEditor.sanityCheckState(AbstractTextEditor.java:4870)
	at org.eclipse.ui.texteditor.StatusTextEditor.sanityCheckState(StatusTextEditor.java:245)
	at org.eclipse.ui.texteditor.AbstractTextEditor.safelySanityCheckState(AbstractTextEditor.java:4848)
	at org.eclipse.ui.texteditor.AbstractTextEditor$ActivationListener.handleActivation(AbstractTextEditor.java:961)
	at org.eclipse.ui.texteditor.AbstractTextEditor$ActivationListener.partActivated(AbstractTextEditor.java:926)
	at org.eclipse.ui.internal.PartService$1.run(PartService.java:84)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.PartService.partActivated(PartService.java:81)
	at org.eclipse.ui.internal.WorkbenchWindow$WWinPartService.partActivated(WorkbenchWindow.java:3002)
	at org.eclipse.ui.internal.WorkbenchPage$14.run(WorkbenchPage.java:4977)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.WorkbenchPage.firePartActivated(WorkbenchPage.java:4974)
	at org.eclipse.ui.internal.WorkbenchPage.access$19(WorkbenchPage.java:4962)
	at org.eclipse.ui.internal.WorkbenchPage$E4PartListener.partActivated(WorkbenchPage.java:210)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$3.run(PartServiceImpl.java:250)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.firePartActivated(PartServiceImpl.java:247)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:757)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:682)
	at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:95)
	at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer$1.handleEvent(ContributedPartRenderer.java:63)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
	at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1612)
	at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1575)
	at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:3428)
	at org.eclipse.swt.widgets.Canvas.sendFocusEvent(Canvas.java:76)
	at org.eclipse.swt.widgets.Display.checkFocus(Display.java:672)
	at org.eclipse.swt.widgets.Shell.makeFirstResponder(Shell.java:1294)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5843)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:227)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2140)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2402)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5797)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5226)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5375)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3703)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1492)


Please any suggestion/idea?

best
Re: manage eopposite references coming from imported metamodel [message #1765247 is a reply to message #1765246] Wed, 07 June 2017 20:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
No you have ask ed. Did you have a look at the model before saving to xmi
Is it ok are both refs set. Afaik you have to do this manually right?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: manage eopposite references coming from imported metamodel [message #1765249 is a reply to message #1765247] Wed, 07 June 2017 20:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
So to say: is the model correct after Xtext (re)parsed it

Another thing for a simple unit test

And I have a dejavue feeling that you already had solved this a week ago


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Wed, 07 June 2017 20:45]

Report message to a moderator

Re: manage eopposite references coming from imported metamodel [message #1765251 is a reply to message #1765249] Wed, 07 June 2017 20:47 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
the re-parsed model doesn't show errors but a wizard appears showing the error.

Christian, the attachment shows a demo explaining the complete scenario
Re: manage eopposite references coming from imported metamodel [message #1765255 is a reply to message #1765251] Wed, 07 June 2017 21:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
no i meant this


import com.google.inject.Inject
import myDsl.Model
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest {
	@Inject
	ParseHelper<Model> parseHelper
	
	@Test
	def void loadModel() {
		val result = parseHelper.parse('''
			Model model1 { classAs { ClassA classa1 { classb { ClassB classb1 { target classa1 } } } } }
		''')
		Assert.assertNotNull(result)
		Assert.assertTrue(result.eResource.errors.isEmpty)
		println(result.classAs.head.referingbs)
	}
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: manage eopposite references coming from imported metamodel [message #1765258 is a reply to message #1765255] Wed, 07 June 2017 21:05 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
The test is correct.
However, the println shows
[]
Re: manage eopposite references coming from imported metamodel [message #1765260 is a reply to message #1765258] Wed, 07 June 2017 21:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
yes and this means the test is not correct, it should print the b right?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: manage eopposite references coming from imported metamodel [message #1765262 is a reply to message #1765260] Wed, 07 June 2017 21:09 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Yes. it should print the classb1 object
Re: manage eopposite references coming from imported metamodel [message #1765263 is a reply to message #1765262] Wed, 07 June 2017 21:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
and i thought we were already at this point 2 weeks ago with the fsm stuff.

class MyDslDerivedStateComputer implements IDerivedStateComputer {

	override discardDerivedState(DerivedStateAwareResource resource) { 
		if (!resource.contents.empty) {
			val model = resource.contents.head as Model
			for (a : model.classAs) {
				a.referingbs.clear
			}
		}
	}

	override installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
		if (!resource.contents.empty) {
			val model = resource.contents.head as Model
			for (a : model.classAs) {
				println(a.name)
				for (ai : model.classAs) {
					for (bi : ai.classb) {
						val name = NodeModelUtils.findNodesForFeature(bi, MyDslPackage.Literals.CLASS_B__TARGET).head?.text?.trim
						println(name)
						if (a.name == name) {
							println("found")
							val EObject proxy = EcoreUtil.create(MyDslPackage.Literals.CLASS_B)							(proxy as InternalEObject).eSetProxyURI(EcoreUtil.getURI(a));
							(proxy as InternalEObject).eSetProxyURI(EcoreUtil.getURI(bi))
							a.referingbs += proxy as ClassB
						}
					}
				}
			}
		}
	}

}


(dont know how this stuff will behave cross file, maybe you need another approach for that - maybe ed can help)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: manage eopposite references coming from imported metamodel [message #1765264 is a reply to message #1765263] Wed, 07 June 2017 21:35 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Quote:

and i thought we were already at this point 2 weeks ago with the fsm stuff.

Yes Christian, but in the fsm stuff, the first part MyDslTransientValueService misses

Quote:

(dont know how this stuff will behave cross file, maybe you need another approach for that - maybe ed can help)

what do you mean when you say "cross file"?
Re: manage eopposite references coming from imported metamodel [message #1765268 is a reply to message #1765264] Wed, 07 June 2017 21:52 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14721
Registered: July 2009
Senior Member
If b and a are in a different file you cannot search matching a and bs the way I do

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:import and scope provider
Next Topic:An internal error occurred during: "calculating highlighting".
Goto Forum:
  


Current Time: Mon Oct 07 14:30:46 GMT 2024

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

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

Back to the top