-->

How can I add xText editor to Eclipse (e4) RCP App

2019-05-10 04:54发布

问题:

I've already made a xtext editor (2.5). I try to use this editor in a part in my RCP application.

I use this code:

Injector injector = MyDslActivator.getInstance().getInjector(MyDslActivator.XTEXT_DSL_MYDSL);
EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
editor = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations().withParent(container);

But I got an error

java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "com/google/inject/Injector"

UPD1

The bundle "eclipse.m2e.maven.runtime" has the package "org.google.inject" with another version. The solution was exclude this bundle from the project.

But now I got new error.

Caused by: java.lang.NullPointerException
at org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorActions.initialize(EmbeddedEditorActions.java:124)
at org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorActions.<init>(EmbeddedEditorActions.java:119)
at org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorActions$Factory.createActions(EmbeddedEditorActions.java:63)
at org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory$Builder.initializeActions(EmbeddedEditorFactory.java:397)
at org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory$Builder.withParent(EmbeddedEditorFactory.java:233)

It happend because the google injector doesn't inject IWorkbench into EmbeddedEditorActions.Factory.

I haven't idea how to fix it. The e4 application has org.eclipse.e4.ui.workbench.IWorkbench, bot doesn't have org.eclipse.ui.IWorkbench.

回答1:

You have to make sure that your RCP contains the bundle com.google.inject only once. Somehow it was loaded in two different versions and both were made available to your DSL plugin.