Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » "shaddow" errors(problem with scoping in multiple files)
"shaddow" errors [message #703358] Wed, 27 July 2011 13:42 Go to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hello,
I am getting very strange behaviour of my Xtext generated application. I have defined my grammar, e.g.:

MyModel:
entities += Entity*;

Entity:
EntityA|EntityB|EntityC;

EntityA,..,EntityC are defined.

Objects of EntityA refer to objects of EntityB and EntityC.
Everything works perfect, while I have all objects of EntityA, EntityB, EntityC defined in single file. However, if I put the EntityA objects into file1.ext, EntityB objects into file2.ext and EntityC objects into file3.ext (all these files are in src folder of MyModel project), there are references errors. The errors disappear after re-save of these files. The strange is: there is still "shaddow" (gray color) error in front of refferencing lines and I can't get rid of it.

Note: Scoping of files works perfect, as the code completion allways gives me reasonable possibilities.

What could cause this problem? How could I solve it?

Thank you & Best regards,
Michal
Re: "shaddow" errors [message #703372 is a reply to message #703358] Wed, 27 July 2011 13:59 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi.

If the error icon is red it means that the error is present in the editor and in the file.
As you change the code within the eclipse editor the error only is removed in the editor-document but it is still present within the file. Thats because it's not saved and written to the file yet. To indicate the error still exists within the file a gray error icon is shown.

The gray errors should disappear after you save the file which seems not to work at your project. Are there any exceptions printed to your debugging-eclipse? Probably eclipse can't save the editor contents back to the file which would explain why the gray error icon persist.

Cheers Daniel

-
Re: "shaddow" errors [message #703407 is a reply to message #703372] Wed, 27 July 2011 14:37 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hi Daniel,
I didn't get debug output, but meanwhile I tried to remove some of my code and it solved the problem. Unfortunatelly, the code, which I have to remove is needed:

in file MyParserToXML.java saved in my.package.name/src/my.package.name/
package de.bmw.testcase;

import java.io.IOException;
import java.util.HashMap;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;

public class MyParserToXML implements IGenerator{


	public void doGenerate(Resource input, IFileSystemAccess fsa) {
		 new TestCaseStandaloneSetup().createInjectorAndDoEMFRegistration();
	     Resource resource = input;
	     ResourceSet rs = resource.getResourceSet();
	     System.out.println(rs.getResources().size());
	     EObject eobject = resource.getContents().get(0);
	     XMIResourceFactoryImpl resFactory = new XMIResourceFactoryImpl();
	     
	     String [] splitted_path = ((String) resource.getURI().toPlatformString(true)).split("/");
	     String newpath = "";
	     for (int i = 1; i<splitted_path.length;i++){
	    	 if(i!=2){
	    		 newpath += "/";
	    		 newpath += splitted_path[i];
	    	 } else {
	    		 newpath += "/src-gen";
	    	 }
	     }
	     newpath = newpath.replace(".tcf", ".xmi");
	     URI xmiuri = URI.createFileURI(newpath);
	     System.out.println(xmiuri.toString());
	     
	     
	     XMIResource xmiresource = (XMIResource) resFactory.createResource(xmiuri);
	     try {
			xmiresource.delete(new HashMap());
		} catch (IOException e1) {
			System.out.println("DELETE NOT SUCCESSFULL");
			e1.printStackTrace();
		}
	     xmiresource.getContents().add(eobject);
	     
	     
	     
	     try {
	         xmiresource.save(new HashMap());
	     } catch (IOException e) {
	         System.out.println("SAVE NOT MADE");
	         e.printStackTrace();
	     }
	}
}


And binding to this code saved in MyProjectNameRuntimeModule.java
	@Override
	public Class<? extends IGenerator> bindIGenerator() {
		return MyParserToXML.class;
	}


What is wrong with my code?
Thank you in advance.
Regards,
Michal
Re: "shaddow" errors [message #703409 is a reply to message #703407] Wed, 27 July 2011 14:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
Hi

xmiresource.getContents().add(eobject);
i don't know if it is a good idea to steal the xtext resources contents
=> make a copy (EcoreUtil) of eobject
and add the copy to the resource

~Christian


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

[Updated on: Wed, 27 July 2011 14:43]

Report message to a moderator

Re: "shaddow" errors [message #703438 is a reply to message #703409] Wed, 27 July 2011 15:15 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hi Christian,
I changed the code this way:
  Copier copier = new Copier();
  EObject result = copier.copy(resource.getContents().get(0));
  copier.copyReferences();
  ........
  xmiresource.getContents().add(result);

But still having same problem Sad. Any idea?
Thank you,
Michal
Re: "shaddow" errors [message #703452 is a reply to message #703438] Wed, 27 July 2011 15:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
Hi,

calling new TestCaseStandaloneSetup().createInjectorAndDoEMFRegistration();
from an eclipse runtime is a deadly idea.

since i do not know your Copier class, have no other hints
but i will try this today evening

~Christian


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

[Updated on: Wed, 27 July 2011 15:41]

Report message to a moderator

Re: "shaddow" errors [message #703533 is a reply to message #703452] Wed, 27 July 2011 17:07 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hi Christian,

thank you for your answer.
I took Copier class from org.eclipse.emf.ecore.util.EcoreUtil. I don't need to use Copier class -> If you have any other suggestion, I appreciate it, as Java is not my "cup of coffee" and I use it only when I have no other choice...

Best regards,
Michal
Re: "shaddow" errors [message #703535 is a reply to message #703533] Wed, 27 July 2011 17:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
HI,

i ll have a look. btw why do you need this xmi stuff at all?

~Christian


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: "shaddow" errors [message #703554 is a reply to message #703535] Wed, 27 July 2011 17:27 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hi Christian,
I need to create XML from my model, as the data are neccesary in external application, where they will be used (with other data) to create the output.
There would be possible to process plain text of my model, but in this case I would have to parse it as text, what is more difficult.
I like the Save As function of "Sample Reflective Ecore Model Editor" in Eclipse, but I need it done automatically (that's why I am implementing generator) or just with the Build button in Eclipse. Any of these two possibilities will solve my issue.

Best regards,
Michal
Re: "shaddow" errors [message #703559 is a reply to message #703554] Wed, 27 July 2011 17:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
Hi,

Quote:

There would be possible to process plain text of my model, but in this case I would have to parse it as text, what is more difficult.


this is for free Wink see the link you have the xmi stuff from

~Christian


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: "shaddow" errors [message #703638 is a reply to message #703559] Wed, 27 July 2011 19:23 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hi Christian,
I have the XMI stuff from link you sent me yesterday. But I can't see answer, which I need. I need my mode in any XML-like format, as it is very comfortable to parse with built-ins of many languages...
Regards,
Michal
Re: "shaddow" errors [message #703647 is a reply to message #703559] Wed, 27 July 2011 19:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
Hi,

when leaving off the standalonesetup it works for me.
but if you have several model files you still have the problem
with the crossrefs in the xmi files (they ll still point to the xtext files)

~Christian


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: "shaddow" errors [message #703651 is a reply to message #703647] Wed, 27 July 2011 19:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
So together with http://kthoms.wordpress.com/2011/07/12/xtend-generating-from-multiple-input-models/

package org.xtext.example.mydsl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
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.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.generator.IFileSystemAccess;

import com.google.inject.Inject;
import com.google.inject.Provider;

public class MyParserToXML implements IGenerator2 {
	
	@Inject Provider<ResourceSet> rsp;


	public void doGenerate(ResourceSet rs, IFileSystemAccess fsa) {
		ResourceSet rs2 = rsp.get();
		EcoreUtil2.clone(rs2,rs); 
		XMIResourceFactoryImpl resFactory = new XMIResourceFactoryImpl();
		List<Resource> toSave = new ArrayList<Resource>();
	    for (Resource resource : rs2.getResources()) {
	    	String [] splitted_path = ((String) resource.getURI().toPlatformString(true)).split("/");
		     String newpath = "";
		     for (int i = 1; i<splitted_path.length;i++){
		    	 if(i!=2){
		    		 newpath += "/";
		    		 newpath += splitted_path[i];
		    	 } else {
		    		 newpath += "/src-gen";
		    	 }
		     }
		     newpath = newpath.replace(".tcf", ".xmi");
		     URI xmiuri = URI.createFileURI(newpath);
		     XMIResource xmiresource = (XMIResource) resFactory.createResource(xmiuri);
		     try {
				xmiresource.delete(new HashMap());
			} catch (IOException e1) {
				System.out.println("DELETE NOT SUCCESSFULL");
				e1.printStackTrace();
			}
		     xmiresource.getContents().addAll(resource.getContents());
		     toSave.add(xmiresource);
	    }
		
	     for (Resource xmiresource : toSave) {
	    	 try {
		         xmiresource.save(new HashMap());
		     } catch (IOException e) {
		         System.out.println("SAVE NOT MADE");
		         e.printStackTrace();
		     }
	     }
	     
	    
	     
	     
	     
	     
	}


	@Override
	public void doGenerate(Resource input, IFileSystemAccess fsa) {
		// TODO Auto-generated method stub
		
	}
}


Works perfect for me



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: "shaddow" errors [message #703989 is a reply to message #703651] Thu, 28 July 2011 06:44 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
Hi Christian,
I followed the instruction from you and from the blog mentioned above. Shaddow errors are not there any more, but I am not getting XML output: just this error whenever I save any of my model files:

0    [Worker-3] ERROR org.eclipse.xtext.builder.impl.XtextBuilder  - 
java.util.ConcurrentModificationException
	at org.eclipse.emf.common.util.AbstractEList$EIterator.checkModCount(AbstractEList.java:762)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:710)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:696)
	at org.eclipse.xtext.EcoreUtil2.clone(EcoreUtil2.java:102)
	at de.bmw.testcase.MyParserToXML.doGenerate(MyParserToXML.java:29)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant2.invokeGenerator(JavaProjectBasedBuilderParticipant2.java:69)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant2.handleChangedContents(JavaProjectBasedBuilderParticipant2.java:44)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant.build(JavaProjectBasedBuilderParticipant.java:86)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant2.build(JavaProjectBasedBuilderParticipant2.java:37)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:160)
	at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:141)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:91)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
!SESSION 2011-07-28 08:22:07.291 -----------------------------------------------
eclipse.buildId=I20110613-1736
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=de_DE
Framework arguments:  -product org.eclipse.sdk.ide
Command-line arguments:  -product org.eclipse.sdk.ide -data U:\xtext/../runtime-EclipseApplication -dev file:U:/xtext/.metadata/.plugins/org.eclipse.pde.core/Eclipse Application/dev.properties -os win32 -ws win32 -arch x86 -consoleLog

!ENTRY org.apache.log4j 4 0 2011-07-28 08:22:46.994
!MESSAGE org.eclipse.xtext.builder.impl.XtextBuilder  - 

!STACK 0
java.util.ConcurrentModificationException
	at org.eclipse.emf.common.util.AbstractEList$EIterator.checkModCount(AbstractEList.java:762)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:710)
	at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:696)
	at org.eclipse.xtext.EcoreUtil2.clone(EcoreUtil2.java:102)
	at de.bmw.testcase.MyParserToXML.doGenerate(MyParserToXML.java:29)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant2.invokeGenerator(JavaProjectBasedBuilderParticipant2.java:69)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant2.handleChangedContents(JavaProjectBasedBuilderParticipant2.java:44)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant.build(JavaProjectBasedBuilderParticipant.java:86)
	at org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant2.build(JavaProjectBasedBuilderParticipant2.java:37)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:160)
	at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:141)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:91)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


I have only 3 model files and it copies 52 resources. It falls always on resource with following URI:
java:/Objects/org.eclipse.xtext.generator.serializer.GeneratedFile


I used the code from clone() function definition to debug this. The error is strange to me, as the error happens on the line:
for (Resource resource : resources) {

and if I put first command into this cycle some simple System.out.println(...), I never get to state, that is written.

Thank you for any help...
Michal
Re: "shaddow" errors [message #703991 is a reply to message #703989] Thu, 28 July 2011 06:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13644
Registered: July 2009
Senior Member
Hi,

strange, maybe you should not use a builder for this stuff at all,
it makes no sence. maybe a simple stupid action does the same
better cleaner and easier.

~Christian


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: "shaddow" errors [message #704007 is a reply to message #703991] Thu, 28 July 2011 07:15 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 74
Registered: July 2011
Member
I found following solution: If I use this:
EList<Resource> resources = rs.getResources();
EcoreUtil.Copier copier = new EcoreUtil.Copier();


for (int i = 0; i<resources.size();i++ ){
	try{
		Resource resource = resources.get(i);
		if (resource.getURI().isPlatform()){
			Resource resource2 = rs2.createResource(resource.getURI());
			resource2.getContents().addAll(copier.copyAll(resource.getContents()));
		}
	} catch (ConcurrentModificationException e){
		
	}
}

copier.copyReferences();

instead of EcoreUtil2.clone function, it seems to me working!

Thank you Christian for your help!

Michal
Re: &quot;shaddow&quot; errors [message #704972 is a reply to message #703533] Fri, 29 July 2011 09:18 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi Michal,

don't do this in an OSGi environment:

new TestCaseStandaloneSetup().createInjectorAndDoEMFRegistration();

It is not necessary. All the registration / injector config should
happen in the plugin.xml / activator / by means of @Inject in the
generator itself.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 27.07.11 19:07, Michal wrote:
> Hi Christian,
>
> thank you for your answer.
> I took Copier class from org.eclipse.emf.ecore.util.EcoreUtil. I don't
> need to use Copier class -> If you have any other suggestion, I
> appreciate it, as Java is not my "cup of coffee" and I use it only when
> I have no other choice...
>
> Best regards,
> Michal
Previous Topic:Splitting to multiple resources
Next Topic:Is such warning important?
Goto Forum:
  


Current Time: Sat Oct 31 04:35:54 GMT 2020

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

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

Back to the top