我正在尝试为 Papyrus 编写一个转换 Alf 代码的插件。
我尝试使用已经包含在 Papyrus (org.eclipse.papyrus.uml.alf.*) 中的 Alf-parser。所以我试图实例化解析器,如下所示:
public class Activator extends Plugin {
// default Activator code here ...
public String ConvertAlfToSpecSharp(String alf)
{
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new AlfStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
// ...
}
}
但第一行 ( new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
) 抛出以下异常:
com.google.inject.CreationException: Guice creation errors:
1) Error injecting method, java.lang.IllegalStateException: No EPackages were registered for the validator org.eclipse.papyrus.uml.alf.validation.CommonJavaValidator please override and implement getEPackages().
at org.eclipse.xtext.validation.AbstractInjectableValidator.register(Unknown Source)
at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:55)
while locating org.eclipse.papyrus.uml.alf.validation.CommonJavaValidator
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:183)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at org.eclipse.papyrus.uml.alf.CommonStandaloneSetupGenerated.createInjector(CommonStandaloneSetupGenerated.java:28)
at org.eclipse.papyrus.uml.alf.CommonStandaloneSetupGenerated.createInjectorAndDoEMFRegistration(CommonStandaloneSetupGenerated.java:22)
at org.eclipse.papyrus.uml.alf.CommonStandaloneSetup.doSetup(CommonStandaloneSetup.java:23)
at org.eclipse.papyrus.uml.alf.AlfStandaloneSetupGenerated.createInjectorAndDoEMFRegistration(AlfStandaloneSetupGenerated.java:20)
at <packagenamehere>.Activator.ConvertAlfToSpecSharp(Activator.java:113)
我不知道如何解决这个问题,特别是因为我发现调试 eclipse 应用程序非常困难......
更新:这里是一些相关类的链接(全部来自 Papyrus 插件的 org.eclipse.papyrus.uml.alf.common 插件(链接)):