在独立模式下使用 sysml2 xtext 插件时出现“org.eclipse.emf.ecore.xmi.PackageNotFoundException”

问题描述 投票:0回答:1

对于公司 POC 软件,我尝试在独立模式下使用 sysml2 xtext 插件和 ANTLR 语法,以便解析和标记化 sysml2 文件并最终导航标记并进行一些简单的代码生成。 到目前为止,我已经设法构建了不同的 JAR 并开始了一些基本代码,但是在实例化解析器时我遇到了以下错误:

org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.omg.org/spec/UML/20161101' not found. (classpath:/org/omg/sysml.xmi, 3, 100)

我想 UML XMI 在运行时不可用,但我不知道如何加载它......遗憾的是,我找不到任何

UmlStandAloneSetupGenerated
或类似的东西。
任何帮助将不胜感激,我不熟悉 EMF 框架,我找不到任何解释如何加载 XMI 并将其映射到 URI 的代码片段。 (作为参考,xtext 插件的源代码位于 https://github.com/Systems-Modeling/SysML-v2-Pilot-Implementation/tree/master/org.omg.sysml.xtext

package company.sysml2_tools;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.service.GrammarProvider;
import org.omg.sysml.xtext.SysMLStandaloneSetupGenerated;
import org.omg.sysml.xtext.parser.antlr.internal.InternalSysMLLexer;
import org.omg.sysml.xtext.parser.antlr.internal.InternalSysMLParser;
import org.omg.sysml.xtext.services.SysMLGrammarAccess;
import com.google.inject.Injector;

public class App {
    public static void main(String[] args) {

        try {
            String test = "package banana{}";
            InternalSysMLLexer lexer = new InternalSysMLLexer(new ANTLRStringStream(test));
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SysMLStandaloneSetupGenerated standalone = new SysMLStandaloneSetupGenerated();
            Injector injector = standalone.createInjectorAndDoEMFRegistration();

            InternalSysMLParser parser = new InternalSysMLParser(tokens, new SysMLGrammarAccess(
                    new GrammarProvider("org.omg.sysml", injector.getProvider(XtextResourceSet.class)), null));

        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
    }
}    
eclipse antlr xtext sysml sysml2
1个回答
0
投票

EMF FAQ听起来你只是缺少UML ePackage的初始化。

© www.soinside.com 2019 - 2024. All rights reserved.