Java模型到源代码转换的问题

时间:2019-03-15 12:41:12

标签: java eclipse code-generation modeling acceleo

我对 Modisco Java模型的Java源代码生成有疑问。

我在下面的Modisco文档中使用了本指南:
https://help.eclipse.org/2018-12/topic/org.eclipse.modisco.java.doc/mediawiki/java_generation/user.html?cp=67_0_1_1_2

首先,我在工作区中导入了插件 org.eclipse.gmt.modisco.java.generation
然后我在src文件夹中添加了一个这样的类:

import java.io.File;
import java.io.IOException;
import java.util.*;

import org.eclipse.emf.common.util.URI;

import org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended;

public class Generation {

    public static void main(String[] args) throws IOException {

    GenerateJavaExtended javaGenerator = new GenerateJavaExtended(URI.createFileURI("mymodel.xmi"),
            new File("myOutputFolder"), new ArrayList<Object>());

    javaGenerator.doGenerate(null);
    }

}    

但是当我将此代码作为Java应用程序运行时,出现此错误:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 67, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at org.eclipse.emf.ecore.impl.EPackageImpl.eObjectForURIFragmentNameSegment(EPackageImpl.java:1970)
at org.eclipse.emf.ecore.impl.EModelElementImpl.eObjectForURIFragmentSegment(EModelElementImpl.java:473)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:811)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:787)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setValueFromId(XMLHandler.java:2868)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2773)
at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:79)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2247)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTypeName(XMLHandler.java:2150)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2085)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:151)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1868)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1048)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:82)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1026)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:720)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:190)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.acceleo.model.mtl.resource.EMtlResourceImpl.doLoad(EMtlResourceImpl.java:93)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1563)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1342)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:391)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:356)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:485)
at org.eclipse.gmt.modisco.java.generation.files.GenerateJava.<init>(GenerateJava.java:92)
at org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended.<init>(GenerateJavaExtended.java:39)
at Generation.main(Generation.java:13)

如何将Java模型转换回原始Java源代码?


我使用的工具:

  • Eclipse建模工具2018-12(4.10.0)
  • MoDisco SDK(1.2.0)
  • JRE 1.8.0_202

1 个答案:

答案 0 :(得分:0)

您可以在https://www.eclipse.org/forums/index.php?t=msg&th=1098046&goto=1804354&#msg_1804354

处重复发布此消息,找到答案。