У меня проблема с преобразованием модели EMF обратно в исходный исходный код Java с использованием JaMoPP .
Я выполнил действия, описанные в этом руководстве:
http://www.primordion.com/Xholon/wiki/JaMoPP_Basic_Tutorial/
Но когда я запускаю JaMoPPC.java на первом шаге, я получаю следующее:
Parsing .\src\test\Elephant.java
Resolving cross-references of 177 EObjects.
177/177 done: Resolved 22 crossrefs, 0 crossrefs could not be resolved.
Resolving cross-references of 1650 EObjects.
org.apache.bcel5_2_0.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
Can not find referenced element in classpath: pathmap:/javaclass/java.util.Comparator.java#//@classifiers[name='Comparator']
at org.apache.bcel5_2_0.classfile.Constant.readConstant(Constant.java:147)
at org.apache.bcel5_2_0.classfile.ConstantPool.<init>(ConstantPool.java:68)
at org.apache.bcel5_2_0.classfile.ClassParser.readConstantPool(ClassParser.java:229)
at org.apache.bcel5_2_0.classfile.ClassParser.parse(ClassParser.java:137)
at org.emftext.language.java.resource.ClassFileModelLoader.parse(ClassFileModelLoader.java:85)
at org.emftext.language.java.resource.JavaSourceOrClassFileResource.doLoad(JavaSourceOrClassFileResource.java:106)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1284)
at org.emftext.language.java.resource.java.mopp.JavaResource.load(JavaResource.java:579)
at org.emftext.language.java.resource.JavaSourceOrClassFileResource.load(JavaSourceOrClassFileResource.java:143)
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.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:220)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:197)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:257)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
at org.emftext.language.java.types.impl.ClassifierReferenceImpl.getTarget(ClassifierReferenceImpl.java:124)
at org.emftext.language.java.types.impl.ClassifierReferenceImpl.eGet(ClassifierReferenceImpl.java:186)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1011)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1003)
at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:403)
at org.emftext.language.java.jamoppc.JaMoPPC.resolveAllProxies(JaMoPPC.java:272)
at org.emftext.language.java.jamoppc.JaMoPPC.resolveAllProxies(JaMoPPC.java:292)
at org.emftext.language.java.jamoppc.JaMoPPC.main(JaMoPPC.java:86)
org.apache.bcel5_2_0.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
at org.apache.bcel5_2_0.classfile.Constant.readConstant(Constant.java:147)
at org.apache.bcel5_2_0.classfile.ConstantPool.<init>(ConstantPool.java:68)
at org.apache.bcel5_2_0.classfile.ClassParser.readConstantPool(ClassParser.java:229)
at org.apache.bcel5_2_0.classfile.ClassParser.parse(ClassParser.java:137)
at org.emftext.language.java.resource.ClassFileModelLoader.parse(ClassFileModelLoader.java:85)
at org.emftext.language.java.resource.JavaSourceOrClassFileResource.doLoad(JavaSourceOrClassFileResource.java:106)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1284)
at org.emftext.language.java.resource.java.mopp.JavaResource.load(JavaResource.java:579)
at org.emftext.language.java.resource.JavaSourceOrClassFileResource.load(JavaSourceOrClassFileResource.java:143)
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.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:220)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:197)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:257)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
at org.emftext.language.java.types.impl.ClassifierReferenceImpl.getTarget(ClassifierReferenceImpl.java:124)
at org.emftext.language.java.types.impl.ClassifierReferenceImpl.eGet(ClassifierReferenceImpl.java:186)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1011)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1003)
at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:403)
at org.emftext.language.java.jamoppc.JaMoPPC.resolveAllProxies(JaMoPPC.java:272)
at org.emftext.language.java.jamoppc.JaMoPPC.resolveAllProxies(JaMoPPC.java:292)
at org.emftext.language.java.jamoppc.JaMoPPC.main(JaMoPPC.java:86)
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.CharSequence.java#//@classifiers[name='CharSequence']
1000/1650 done: Resolved 137 crossrefs, 11 crossrefs could not be resolved.
org.apache.bcel5_2_0.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
at org.apache.bcel5_2_0.classfile.Constant.readConstant(Constant.java:147)
at org.apache.bcel5_2_0.classfile.ConstantPool.<init>(ConstantPool.java:68)
at org.apache.bcel5_2_0.classfile.ClassParser.readConstantPool(ClassParser.java:229)
at org.apache.bcel5_2_0.classfile.ClassParser.parse(ClassParser.java:137)
at org.emftext.language.java.resource.ClassFileModelLoader.parse(ClassFileModelLoader.java:85)
at org.emftext.language.java.resource.JavaSourceOrClassFileResource.doLoad(JavaSourceOrClassFileResource.java:106)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1284)
at org.emftext.language.java.resource.java.mopp.JavaResource.load(JavaResource.java:579)
at org.emftext.language.java.resource.JavaSourceOrClassFileResource.load(JavaSourceOrClassFileResource.java:143)
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.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:220)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:197)
at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:257)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
at org.emftext.language.java.types.impl.ClassifierReferenceImpl.getTarget(ClassifierReferenceImpl.java:124)
at org.emftext.language.java.types.impl.ClassifierReferenceImpl.eGet(ClassifierReferenceImpl.java:186)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1011)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1003)
at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:403)
at org.emftext.language.java.jamoppc.JaMoPPC.resolveAllProxies(JaMoPPC.java:272)
at org.emftext.language.java.jamoppc.JaMoPPC.resolveAllProxies(JaMoPPC.java:292)
at org.emftext.language.java.jamoppc.JaMoPPC.main(JaMoPPC.java:86)
Can not find referenced element in classpath: pathmap:/javaclass/java.lang.reflect.AnnotatedElement.java#//@classifiers[name='AnnotatedElement']
1650/1650 done: Resolved 319 crossrefs, 12 crossrefs could not be resolved.
Resolution of some Proxies failed...
кстати модель будет создана в конце.
Затем я использовал этот код для генерации модели:
package org.emftext.language.java.jamoppc;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.emftext.language.java.JavaPackage;
import org.emftext.language.java.resource.JavaSourceOrClassFileResourceFactoryImpl;
import org.emftext.language.java.resource.java.IJavaOptions;
import org.emftext.language.java.resource.java.mopp.JavaResourcePostProcessor;
public class Generate {
protected static final ResourceSet rs = new ResourceSetImpl();
public static void main(String[] args) {
setUp();
Resource xmiResource = rs.getResource(URI.createFileURI("src/test/Elephant.java.xmi"), true);
Resource javaResource = rs.createResource(URI.createFileURI("src/generated/Elephant.java"));
javaResource.getContents().addAll(xmiResource.getContents());
try {
// why does it generate Elephant.java in JamoppTest1/Elephant/test ?
javaResource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
protected static void setUp() {
EPackage.Registry.INSTANCE.put("http://www.emftext.org/java",
JavaPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"java", new JavaSourceOrClassFileResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
rs.getLoadOptions().put(
IJavaOptions.RESOURCE_POSTPROCESSOR_PROVIDER, new JavaResourcePostProcessor());
}
}
, и сгенерированный файл .java:
package test;
/**
* An Elephant can be used to eat
* bananas and carry heavy loads.
*/
public class Elephant {
private boolean tired = false;
public static void main( //@classifiers.0[] args) {
// here we go
Elephant dumbo = new Elephant();
if (dumbo.isTired()) {
return;
}
dumbo.eatBananas();
}
public boolean isTired() {
return tired;
}
public void eatBananas() {
// TODO implement eating
}
}
Вы видите // @classifiers.0 генерируется вместо String
Как я могу решить эту проблему?
Мои использованные инструменты:
- Инструменты моделирования Eclipse 2018-12 (4.10.0)
- JaMoPP (1.4.0)
- JRE (1.8.0_202)