load model by using EMF API [message #1836676] |
Mon, 11 January 2021 17:15  |
Eclipse User |
|
|
|
Hello together,
excuse me, if I might lack of knowledge or skill, the topic is new and my coding is not the best.
Currently, I am on a project that deals with Test Description Language (TDL). For that I have wrote a Test Purpose and a Test Description which can be represented in XMI format (.tdlan2.tdl and .tplan2.tdl) as in Xtext (.tdlan2 and .tplan2). File names are TDExample. and TPExample.
The task I have struggle with is to load and navigate the model programmatically by using the EMF API. The following code is from the first section of https://wiki.eclipse.org./Xtext/FAQ.
package loadpackage;
import java.io.ByteArrayInputStream;
import java.io.InvalidObjectException;
import java.util.HashMap;
import org.eclipse.emf.mwe.utils.*;
import org.eclipse.emf.common.util.*;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
//this import does not resolve
import org.xtext.example.mydsl.MyDslStandaloneSetup;
import com.google.inject.Injector;
public class alone {
public static void main (String [] args) {
new StandaloneSetup().setPlatformUri("../");
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(
URI.createURI("platform:/resource/org.xtext.example.mydsl/src/example.mydsl"), true);
Model model = (Model) resource.getContents().get(0);
}
}
For the last days I roamed through the forum, hunting down every clue I could find - without any productive results. For now it would be nice just to understand why the
"import org.text.example.mydsl.MyDslStanaloneSetup;" is not working. And if you have the time to spare, explaining what the code does and how it can work with the XMI and Xtext Model Representation.
I have not used Xtext so far, and furthermore, my supervisor has not provided any hints to use Xtext besides the FAQ.
|
|
|
Re: load model by using EMF API [message #1836681 is a reply to message #1836676] |
Tue, 12 January 2021 01:07  |
Eclipse User |
|
|
|
For questions specifically about Xtext it's best to use the TMF forum:
https://www.eclipse.org/forums/index.php/f/27/
I can't say, for example, what new StandaloneSetup().setPlatformUri("../"); is supposed to do. Maybe it's supposed to help make "platform:/resource" work, but I don't know how it would or does that.
In general, if an import doesn't resolve, you need to add the plugin/library with that class to the project's classpath. Assuming the project is a plugin, which definitely makes managing the classpath easier, you add another plugin to the classpath by editing the MANIFEST.MF and using the Dependencies to add dependencies.
|
|
|
Powered by
FUDForum. Page generated in 0.03124 seconds