|
|
|
|
Re: Reference Epackage [message #1851081 is a reply to message #1851079] |
Sun, 27 March 2022 14:13 |
|
maybe you might also customize scoping similar as it is done for Xtext itself
there seems also a diff when projects use src folders or not.
you may bypass this using
public class MyDslUiModule extends AbstractMyDslUiModule {
public MyDslUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
@Override
public Provider<IAllContainersState> provideIAllContainersState() {
return org.eclipse.xtext.ui.shared.Access.getWorkspaceProjectsState();
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sun, 27 March 2022 14:21] Report message to a moderator
|
|
|
|
Re: Reference Epackage [message #1851134 is a reply to message #1851085] |
Mon, 28 March 2022 14:56 |
John Henbergs Messages: 239 Registered: October 2020 |
Senior Member |
|
|
Hi Christian,
Unfortunately I am now having issues with eProxyURIs.
I added Library.ecore to the class path of the project where I have the concrete syntax of my textual DSL.
I also loaded the dsl in Xtend, as you suggested in my other post.
My Xtend code now looks like this.
resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new EcoreResourceFactoryImpl());
injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration;
resourceSet = injector.getInstance(ResourceSet)
resourceSet.getResource(URI.createFileURI(new File ("/Users/user/eclipse-workspace/Library/model/library.ecore").absolutePath), true)
resource = resourceSet.getResource( URI.createFileURI(new File("xtendinput.mydsl").getAbsolutePath()), true);
root = resource.contents.get(0);
modelRoot = root as ModelRoot;
println(modelRoot.package)
In the println I am expecting to get the EPackage of Library because that is what I have defined in the package attribute in the ModelRoot class of xtnedinput.mydsl.
However, I am getting the following
Quote:
org.eclipse.emf.ecore.impl.EPackageImpl@1e8823d2 (eProxyURI: file:/Users/user/runtime-XTend_xtends/xtend/xtendinput,mydsl#|0)
I also tried EcoreUtil.resolveAll(resourceSet), but no luck.
When I check the resourceSet I have
Quote:
org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1@1255b1d1 uri='file:/Users/user/eclipse-workspace/Library/model/library.ecore'
|
|
|
|
|
Re: Reference Epackage [message #1851140 is a reply to message #1851137] |
Mon, 28 March 2022 18:38 |
John Henbergs Messages: 239 Registered: October 2020 |
Senior Member |
|
|
I created another project to test it as follows:
In the eclipse workspace I created the following grammar:
grammar org.xtext.example.junit.JUnit with org.eclipse.xtext.common.Terminals
generate jUnit "http://www.xtext.org/example/junit/JUnit"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!'
pako = [ecore::EPackage | STRING]
;
Then I launched the runtime and I created a plugin project, a package, and inside an Xtend class. This is how the Xtend file looks like:
package xtendunit
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.emf.common.util.URI
import java.io.File
import com.google.inject.Injector
import org.xtext.example.junit.JUnitStandaloneSetup
import org.eclipse.emf.ecore.EObject
import org.xtext.example.junit.jUnit.Model
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.emf.ecore.EPackage
class xtend {
ResourceSet resourceSet
Injector injector
Resource resource
EObject root
EPackage p
Model m
def doEMFSetup(){
resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new EcoreResourceFactoryImpl());
injector = new JUnitStandaloneSetup().createInjectorAndDoEMFRegistration;
resourceSet = injector.getInstance(ResourceSet)
resourceSet.getResource(URI.createFileURI(new File ("/Users/user/eclipse-workspace/Calendar/model/calendar.ecore").absolutePath), true)
resourceSet.getResource(URI.createFileURI(new File ("/Users/user/eclipse-workspace/org.xtext.example.junit/model/generated/JUnit.ecore").absolutePath), true)
resource = resourceSet.getResource( URI.createFileURI(new File("textual.junit").getAbsolutePath()), true);
println(resourceSet)
println(resource)
}
def getRoot() {
doEMFSetup
root = resource.contents.get(0);
m = root as Model;
EcoreUtil.resolveAll(resourceSet)
for (greetings : m.greetings){
println (greetings.name)
println (greetings.pako.name)
}
}
def static void main(String[] args) {
new xtend().getRoot();
}
}
In the workspace I have another Ecore metamodel Calendar, which I also imported in the runtime and I added it to the class path of the Xtend project by using class folder.
I created the following instance of the grammar which is located inside the plugin. .
When I run Xtend I get the following:
org.eclipse.xtext.resource.SynchronizedXtextResourceSet@47747fb9 resources=[org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1@3113a37 uri='file:/Users/user/eclipse-workspace/Calendar/model/calendar.ecore', org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1@213e3629 uri='file:/Users/user/eclipse-workspace/org.xtext.example.junit/model/generated/JUnit.ecore', org.eclipse.xtext.linking.lazy.LazyLinkingResource@4e9658b5 uri='file:/Users/user/runtime-test/Xtendunit/textual.junit']
org.eclipse.xtext.linking.lazy.LazyLinkingResource@4e9658b5 uri='file:/Users/user/runtime-test/Xtendunit/textual.junit'
John
null
|
|
|
|
Re: Reference Epackage [message #1851145 is a reply to message #1851144] |
Tue, 29 March 2022 04:55 |
|
following main works for me
import java.io.IOException;
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.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.xtext.ecore.EcoreSupportStandaloneSetup;
import org.xtext.example.mydsl.MyDslStandaloneSetup;
import org.xtext.example.mydsl.myDsl.Model;
import com.google.inject.Injector;
public class Main {
public static void main(String[] args) throws IOException {
// register ecore to xtext, needs xtext.ecore on classpath
new EcoreSupportStandaloneSetup();
// register the dsl
Injector i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet resourceSet = i.getInstance(ResourceSet.class);
Resource ecoreResource = resourceSet.getResource(URI.createURI("/home/dietrich/eclipse-workspaces/la2222/org.xtext.example.mydsl/model/generated/MyDsl.ecore"), true);
Resource xtextResource = resourceSet.getResource(URI.createURI("/home/dietrich/eclipse-workspaces/la2222/org.xtext.example.mydsl.tests/test.mydsl"), true);
ecoreResource.load(null);
xtextResource.load(null);
EcoreUtil.resolveAll(resourceSet);
Model model = (Model)xtextResource.getContents().get(0);
System.out.println(model.getGreetings().get(0).getType().getNsURI());
}
}
see also https://www.eclipse.org/forums/index.php/m/1745239/?srch=EcoreSupportStandaloneSetup#msg_1745239
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Tue, 29 March 2022 04:58] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Reference Epackage [message #1851177 is a reply to message #1851171] |
Tue, 29 March 2022 13:28 |
|
your model file looks bad
Hello John! "jUnit" looks better.
alternatively you have to use the other ecore in test
ecoreResource = resourceSet.getResource(URI.createFileURI(new File ("/Users/cdietrich/eclipse-workspaces/runtime-New_configuration/ToReference/model/toReference.ecore").absolutePath), true)
// TODO adjust path to your machine
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.04819 seconds