0

XText を EMF の ATL モデルからモデルへの変換と組み合わせようとしています。DSL を読んで、それを EMF の XMI リソースにダンプし、ATL API に入れます。ATL はエラーを表示せず、正しく実行されます。

Number of instructions executed: 38

何をしても、OutModel (palData) は空 (null) のままです。ここからすべてのファイル (hdl.ecore、pal.ecore、hdl.xmi) を取得してサンプル ATL プロジェクトに配置すると、正しい出力が得られます。

EMFVM ランチャーに投げる必要がある魔法のパラメータはありますか?

ATL をトリガーするための私のコード:

// create stuff
EMFModelFactory emfFactory = new EMFModelFactory();
XMIResourceFactoryImpl xmiFactory = new XMIResourceFactoryImpl();

EMFExtractor extractor = new EMFExtractor();
EMFInjector emfInjector = new EMFInjector();
ResourceSet resourceSet = new ResourceSetImpl();

// load model
EMFReferenceModel hdlMetaModel = (EMFReferenceModel) emfFactory.newReferenceModel();
emfInjector.inject(hdlMetaModel, resourceSet.getResource(URI.createFileURI("org.xtext.hal/model/generated/Hdl.ecore"), true));
EMFModel hdlData = (EMFModel) emfFactory.newModel(hdlMetaModel);

EMFReferenceModel palMetaModel = (EMFReferenceModel) emfFactory.newReferenceModel();
emfInjector.inject(palMetaModel, resourceSet.getResource(URI.createFileURI("org.xtext.hal/model/Pal.ecore"), true));
EMFModel palData = (EMFModel) emfFactory.newModel(palMetaModel);
palData.setIsTarget(true);

// load xtext content, convert to xmi
Resource xmiResource = xmiFactory.createResource(URI.createURI("org.xtext.hal/model/generated/Hdl.xmi"));
xmiResource.getContents().addAll(hdlModel.getContents());
emfInjector.inject(hdlData, xmiResource);

// ATL transformation
InputStream asm = new FileInputStream("org.xtext.hal/model/Pal.asm");
EMFVMLauncher launcher = new EMFVMLauncher();

HashMap<String,Object> options = new HashMap<String,Object>();
options.put("showSummary", "true");
options.put("step", "true");

launcher.initialize(Collections.<String, Object> emptyMap());
launcher.addInModel(hdlData, "IN", "hdl");
launcher.addOutModel(palData, "OUT", "pal");
launcher.launch(ILauncher.DEBUG_MODE, new NullProgressMonitor(), options, asm);

// get output
Resource t_palData = palData.getResource();
t_palData.setURI(URI.createURI("palData.xmi")); // Exception in thread "main" java.lang.NullPointerException
t_palData.save(null);

私はここにいますATL:

-- @path hdl=/org.xtext.hal/model/generated/Hdl.ecore
-- @path pal=/org.xtext.hal/model/Pal.ecore

module HDL2PAL;
create OUT : pal from IN : hdl;

rule Foobar
{
  from
    s : hdl!Model
  to
    t : pal!AddressSpace (
      name <- s.name
    )
}

HDL.ecore (入力メタモデル):

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="hdl" nsURI="http://www.xtext.org/hal/Hdl" nsPrefix="hdl">
  <eClassifiers xsi:type="ecore:EClass" name="Model">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>

PAL.ecore (出力メタモデル):

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="pal" nsURI="http://www.xtext.org/hal/Pal" nsPrefix="pal">
  <eClassifiers xsi:type="ecore:EClass" name="AddressSpace">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>

入力のモデル データ:

<?xml version="1.0" encoding="ASCII"?>
<hdl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:hdl="http://www.xtext.org/hal/Hdl" name="bar"/>

ATL サンプル プロジェクトからの出力:

<?xml version="1.0" encoding="ISO-8859-1"?>
<pal:AddressSpace xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:pal="http://www.xtext.org/hal/Pal" name="bar"/>

ATL アサンブラーからの出力:

main:0  getasm
  stack: HDL2PAL : ASMModule
  locals: self=HDL2PAL : ASMModule
main:1  push OclParametrizedType
  stack: HDL2PAL : ASMModule, 'OclParametrizedType'
  locals: self=HDL2PAL : ASMModule
main:2  push #native
  stack: HDL2PAL : ASMModule, 'OclParametrizedType', '#native'
  locals: self=HDL2PAL : ASMModule
main:3  new
  stack: HDL2PAL : ASMModule, <unnamed>(null)
  locals: self=HDL2PAL : ASMModule
main:4  dup
  stack: HDL2PAL : ASMModule, <unnamed>(null), <unnamed>(null)
  locals: self=HDL2PAL : ASMModule
main:5  push Collection
  stack: HDL2PAL : ASMModule, <unnamed>(null), <unnamed>(null), 'Collection'
  locals: self=HDL2PAL : ASMModule
main:6  pcall J.setName(S):V
  locals: self=HDL2PAL : ASMModule  Calling <unnamed>(null).setName('Collection')
  stack: HDL2PAL : ASMModule, Collection(null)
  locals: self=HDL2PAL : ASMModule
main:7  dup
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null)
  locals: self=HDL2PAL : ASMModule
main:8  push OclSimpleType
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null), 'OclSimpleType'
  locals: self=HDL2PAL : ASMModule
main:9  push #native
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null), 'OclSimpleType', '#native'
  locals: self=HDL2PAL : ASMModule
main:10 new
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null), <unnamed>
  locals: self=HDL2PAL : ASMModule
main:11 dup
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null), <unnamed>, <unnamed>
  locals: self=HDL2PAL : ASMModule
main:12 push OclAny
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null), <unnamed>, <unnamed>, 'OclAny'
  locals: self=HDL2PAL : ASMModule
main:13 pcall J.setName(S):V
  locals: self=HDL2PAL : ASMModule  Calling <unnamed>.setName('OclAny')
  stack: HDL2PAL : ASMModule, Collection(null), Collection(null), OclAny
  locals: self=HDL2PAL : ASMModule
main:14 pcall J.setElementType(J):V
  locals: self=HDL2PAL : ASMModule  Calling Collection(null).setElementType(OclAny)
  stack: HDL2PAL : ASMModule, Collection(OclAny)
  locals: self=HDL2PAL : ASMModule
main:15 set col
  stack: 
  locals: self=HDL2PAL : ASMModule
main:16 getasm
  stack: HDL2PAL : ASMModule
  locals: self=HDL2PAL : ASMModule
main:17 push TransientLinkSet
  stack: HDL2PAL : ASMModule, 'TransientLinkSet'
  locals: self=HDL2PAL : ASMModule
main:18 push #native
  stack: HDL2PAL : ASMModule, 'TransientLinkSet', '#native'
  locals: self=HDL2PAL : ASMModule
main:19 new
  stack: HDL2PAL : ASMModule, TransientLinkSet {}
  locals: self=HDL2PAL : ASMModule
main:20 set links
  stack: 
  locals: self=HDL2PAL : ASMModule
main:21 getasm
  stack: HDL2PAL : ASMModule
  locals: self=HDL2PAL : ASMModule
main:22 pcall A.__matcher__():V
  locals: self=HDL2PAL : ASMModule  Calling HDL2PAL : ASMModule.__matcher__()


__matcher__:0   getasm
  stack: HDL2PAL : ASMModule
  locals: self=HDL2PAL : ASMModule
__matcher__:1   pcall A.__matchFoobar():V
  locals: self=HDL2PAL : ASMModule  Calling HDL2PAL : ASMModule.__matchFoobar()
__matchFoobar:0 push Model
  stack: 'Model'
  locals: self=HDL2PAL : ASMModule
__matchFoobar:1 push hdl
  stack: 'Model', 'hdl'
  locals: self=HDL2PAL : ASMModule
__matchFoobar:2 findme
  stack: hdl!Model
  locals: self=HDL2PAL : ASMModule
__matchFoobar:3 push IN
  stack: hdl!Model, 'IN'
  locals: self=HDL2PAL : ASMModule
__matchFoobar:4 call MMOF!Classifier;.allInstancesFrom(S):QJ
  locals: self=HDL2PAL : ASMModule  Calling hdl!Model.allInstancesFrom('IN')
  stack: OrderedSet {}
  locals: self=HDL2PAL : ASMModule
__matchFoobar:5 iterate
  stack: 
  locals: 
  stack: 
  locals: 
  stack: 
  locals: self=HDL2PAL : ASMModule


main:23 getasm
  stack: HDL2PAL : ASMModule
  locals: self=HDL2PAL : ASMModule
main:24 pcall A.__exec__():V
  locals: self=HDL2PAL : ASMModule  Calling HDL2PAL : ASMModule.__exec__()
__exec__:0  getasm
  stack: HDL2PAL : ASMModule
  locals: self=HDL2PAL : ASMModule
__exec__:1  get links
  stack: TransientLinkSet {}
  locals: self=HDL2PAL : ASMModule
__exec__:2  push Foobar
  stack: TransientLinkSet {}, 'Foobar'
  locals: self=HDL2PAL : ASMModule
__exec__:3  call NTransientLinkSet;.getLinksByRule(S):QNTransientLink;
  locals: self=HDL2PAL : ASMModule  Calling TransientLinkSet {}.getLinksByRule('Foobar')
  stack: []
  locals: self=HDL2PAL : ASMModule
__exec__:4  iterate
  stack: 
  locals: 
  stack: 
  locals: 
4

1 に答える 1