Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Splitting to multiple resources( No EObjectDescription could be found in Scope)
Splitting to multiple resources [message #703057] Wed, 27 July 2011 05:39 Go to next message
Balazs Varnai is currently offline Balazs VarnaiFriend
Messages: 21
Registered: June 2011
Junior Member
Hi,

The model content is created programatically, in the final step I would like to split the content to multiple xtext resources.
The grammar defines Package as top-level element and initally the model consist a single Package with multiple Modules. For each new resource, I create a new Package and put the corresponding Module there.

This does not work, exception is thrown 'java.lang.RuntimeException: No EObjectDescription could be found is Scope ...'.

If I save to a single resource, all works fine. I guess references are broken. Any idea? Thanks!

ResourceSet resourceSet = new ResourceSetImpl();
for (AbstractPackageElement element : package.getElements()) {
  if (element instanceof Module) {
    Module moduleElement = (Module) element;
    Resource resource=resourceSet.createResource(moduleElement.getName() + ".tsx");

    Package container = Factory.eINSTANCE.createPackage();
    container .getElements().add(moduleElement);

    resource.getContents().add(container);

    try {
        resource.save(null);
    } catch (IOException e) {
	e.printStackTrace();
    }
}
Re: Splitting to multiple resources [message #703716 is a reply to message #703057] Wed, 27 July 2011 21:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

in which context do you execute this? (eclipse/standalone)
what is the exact error message you get?
if standalone: to you call the standalonesetup of your dsl
which serializer do you use?

~Christian
Re: Splitting to multiple resources [message #703722 is a reply to message #703716] Wed, 27 July 2011 21:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

and if you have cross refs you have to split resource creation and saving

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.xtext.example.mydsl.MyDslStandaloneSetup;
import org.xtext.example.mydsl.myDsl.Module;
import org.xtext.example.mydsl.myDsl.MyDslFactory;

public class Main {

	public static void main(String[] args) {
		org.xtext.example.mydsl.myDsl.Package p = MyDslFactory.eINSTANCE
				.createPackage();
		p.setName("p1");
		Module m1 = MyDslFactory.eINSTANCE.createModule();
		Module m2 = MyDslFactory.eINSTANCE.createModule();
		Module m3 = MyDslFactory.eINSTANCE.createModule();
		m1.setName("m1");
		m2.setName("m2");
		m3.setName("m3");
		m1.setRefs(m2);
		m2.setRefs(m3);
		m3.setRefs(m1);
		p.getModules().add(m1);
		p.getModules().add(m2);
		p.getModules().add(m3);

		MyDslStandaloneSetup.doSetup();
		ResourceSet resourceSet = new ResourceSetImpl();
		List<Resource> tbs = new ArrayList<Resource>();

		List<Module> modules = new ArrayList<Module>();
		modules.addAll(p.getModules());

		for (Module moduleElement : modules) {
			Resource resource = resourceSet.createResource(URI
					.createURI(moduleElement.getName() + ".mydsl"));

			org.xtext.example.mydsl.myDsl.Package container = MyDslFactory.eINSTANCE
					.createPackage();
			container.setName(moduleElement.getName() + "_package");
			container.getModules().add(moduleElement);

			resource.getContents().add(container);
			tbs.add(resource);

		}

		for (Resource r : tbs) {
			try {
				r.save(null);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

}


~Christian
Re: Splitting to multiple resources [message #704057 is a reply to message #703722] Thu, 28 July 2011 08:33 Go to previous messageGo to next message
Balazs Varnai is currently offline Balazs VarnaiFriend
Messages: 21
Registered: June 2011
Junior Member
Thanks Christian!

Running in eclipse, inside a wizard which calls a service to retrieve the model content from a DB. Xtext is initialized correctly, see stack trace.

I am trying out now the splitting of creation and saving.

Caused by: java.lang.RuntimeException: No EObjectDescription could be found in Scope Typedef.maps for Package.elements[75]->Module'Platform_Types'.elements[13]->Typedef'uint'
Semantic Object: Package.elements[0]->Module'Adc'.elements[0]->Typedef'Adc_ChannelType'
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:66)
	at org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer.getCrossReferenceNameFromScope(CrossReferenceSerializer.java:143)
	at org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer.serializeCrossRef(CrossReferenceSerializer.java:116)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.acceptSemantic(GenericSemanticSequencer.java:626)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$AllocationValue.accept(GenericSemanticSequencer.java:98)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$Quantity.accept(GenericSemanticSequencer.java:348)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$GroupAllocation.accept(GenericSemanticSequencer.java:195)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$Quantity.accept(GenericSemanticSequencer.java:348)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.createSequence(GenericSemanticSequencer.java:774)
	at mydsl.serializer.AbstractTsxSemanticSequencer.sequence_Typedef_Typedef(AbstractTsxSemanticSequencer.java:376)
	at mydsl.serializer.AbstractTsxSemanticSequencer.createSequence(AbstractTsxSemanticSequencer.java:150)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.acceptEObjectRuleCall(GenericSemanticSequencer.java:609)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.acceptSemantic(GenericSemanticSequencer.java:620)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$AllocationValue.accept(GenericSemanticSequencer.java:98)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$Quantity.accept(GenericSemanticSequencer.java:348)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$GroupAllocation.accept(GenericSemanticSequencer.java:195)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$Quantity.accept(GenericSemanticSequencer.java:348)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.createSequence(GenericSemanticSequencer.java:774)
	at mydsl.serializer.AbstractTsxSemanticSequencer.sequence_Module_Module(AbstractTsxSemanticSequencer.java:256)
	at mydsl.serializer.AbstractTsxSemanticSequencer.createSequence(AbstractTsxSemanticSequencer.java:89)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.acceptEObjectRuleCall(GenericSemanticSequencer.java:609)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.acceptSemantic(GenericSemanticSequencer.java:620)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$AllocationValue.accept(GenericSemanticSequencer.java:98)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$Quantity.accept(GenericSemanticSequencer.java:348)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$GroupAllocation.accept(GenericSemanticSequencer.java:195)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer$Quantity.accept(GenericSemanticSequencer.java:348)
	at org.eclipse.xtext.serializer.sequencer.GenericSemanticSequencer.createSequence(GenericSemanticSequencer.java:774)
	at mydsl.serializer.AbstractTsxSemanticSequencer.sequence_Package_Package(AbstractTsxSemanticSequencer.java:269)
	at mydsl.serializer.AbstractTsxSemanticSequencer.createSequence(AbstractTsxSemanticSequencer.java:101)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:68)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:80)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:95)
	at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:286)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1406)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:993)
...
Re: Splitting to multiple resources [message #704061 is a reply to message #704057] Thu, 28 July 2011 08:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

just make sure:

add everything that is referenced to a resource in the resourceset.
then it will work.

In your case the typedefs may be missing

~Christian
Re: Splitting to multiple resources [message #704225 is a reply to message #704061] Thu, 28 July 2011 11:58 Go to previous messageGo to next message
Balazs Varnai is currently offline Balazs VarnaiFriend
Messages: 21
Registered: June 2011
Junior Member
Hi,

Still not working. When the serializer hits a cross reference, it tries look in the scopes.
String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target, final IScope scope, Acceptor errors)

Scope instance is ImportScope, which iterates on local elements and parents respectively.

My setup

Resource 1 file:/Adc.tsx -> Module Adc
Resource 2 file:/Platform_Types.tsx -> Module Platform_Types

An element [semanticObject] in Adc crossrefs [crossref] to an element [target] in Platfrom_Types. The problem is ImportScope does not contain any information on Platfrom_Types?

Thanks!



Re: Splitting to multiple resources [message #704236 is a reply to message #704225] Thu, 28 July 2011 12:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
So how does you code look like now?
Re: Splitting to multiple resources [message #704240 is a reply to message #704236] Thu, 28 July 2011 12:11 Go to previous messageGo to next message
Balazs Varnai is currently offline Balazs VarnaiFriend
Messages: 21
Registered: June 2011
Junior Member

private void saveToFiles(MyDsl.Package pkg, String destination, IProgressMonitor monitor) throws InterruptedException {
		monitor.subTask("Creating files");
		ResourceSet resourceSet = new ResourceSetImpl();
		List<Resource> tbs = new ArrayList<Resource>();
		List<AbstractPackageElement> elements = new ArrayList<AbstractPackageElement>();
		elements.addAll(pkg.getElements());
		
		for (AbstractPackageElement element : elements) {
			if (element instanceof Module) {
				Module moduleElement = (Module) element;
				Resource resource = resourceSet.createResource(URI.createFileURI(destination + File.separator + moduleElement.getName() + ".tsx"));

				MyDsl.Package containerPkg = TsxFactory.eINSTANCE.createPackage();
				containerPkg.getElements().add(moduleElement);

				resource.getContents().add(containerPkg);
				tbs.add(resource);

				if (monitor.isCanceled())
					throw new InterruptedException("Canceled by user");
			}
		}

		monitor.subTask("Saving files");
		for (Resource resource : tbs) {
			try {
				resource.save(null);
				if (monitor.isCanceled())
					throw new InterruptedException("Canceled by user");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

Re: Splitting to multiple resources [message #704245 is a reply to message #704240] Thu, 28 July 2011 12:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

can you share a reproduceable grammar and test class?

~Christian
Re: Splitting to multiple resources [message #704886 is a reply to message #704245] Fri, 29 July 2011 07:07 Go to previous messageGo to next message
Balazs Varnai is currently offline Balazs VarnaiFriend
Messages: 21
Registered: June 2011
Junior Member
Hi,

Thank You, Christian! I created some tests to post and quickly spotted the something. Regardless of running in Eclipse, if I call StandaloneSetup.doSetup() the serialization begins to work.
I had the impression, that the plugin activation does this automatically. Could this be a configuration issue?

B
Re: Splitting to multiple resources [message #704896 is a reply to message #704886] Fri, 29 July 2011 07:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

you should not call standalonesetup.dosetup from a plugin.

~Christian
Previous Topic:Xtend help
Next Topic:"shaddow" errors
Goto Forum:
  


Current Time: Fri Dec 19 21:45:14 GMT 2014

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

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