|
|
|
|
|
Re: [Xpand] Using dynamic emf metamodel with Xpand [message #740635 is a reply to message #740623] |
Tue, 18 October 2011 18:28 |
|
btw something like
package test;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.internal.xpand2.pr.ProtectedRegionResolver;
import org.eclipse.internal.xpand2.pr.ProtectedRegionResolverImpl;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.Output;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.typesystem.emf.EmfMetaModel;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
EPackage p = ecoreFactory.createEPackage();
p.setName("test");
p.setNsPrefix("test");
p.setNsURI("http://www.example.com/test");
EClass c = ecoreFactory.createEClass();
c.setName("Test");
p.getEClassifiers().add(c);
EAttribute a = ecoreFactory.createEAttribute();
a.setName("name");
a.setEType(EcorePackage.Literals.ESTRING);
c.getEStructuralFeatures().add(a);
EFactory instanceFactory = p.getEFactoryInstance();
EObject model = instanceFactory.create(c);
model.eSet(a, "Das ist ein Test");
Output output = new OutputImpl();
Outlet outlet = new Outlet("src-gen");
output.addOutlet(outlet );
ProtectedRegionResolver prs = new ProtectedRegionResolverImpl();
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, prs);
execCtx.registerMetaModel(new EmfMetaModel(p));
XpandFacade.create(execCtx).evaluate("test::test::main", model);
}
}
works for me - of course without editor support
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04948 seconds