English 中文(简体)
Problem integrating OCL types in Xtext grammar
原标题:

I m working on a grammar (Xtext project) where I want to reuse OCL types. Usually you refer in Xtext to existing types with an import statement, e.g.

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

There is already an example Xtext project (CompleteOCL) which integrates OCL types in a grammar. Unfortunately the project refers in its import statements to local plugins, e.g.

import "platform:/resource/org.eclipse.ocl.examples.xtext.base/model/BaseCST.ecore" as base

So there are no dependencies defined in the Manifest.MF file. If I want to reuse OCL types in my grammar I have to write for example

import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

I ve added the org.eclipse.ocl.examples.xtext.base dependency and can write rules in my grammar which refer to (OCL) BaseCST types. If I try to generate the Xtext artifcats I get the following error:

     ... 3 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
    ... 36 more
Caused by: java.lang.IllegalStateException: Problem parsing  classpath:/org/xtext/example/mydsl/MyDsl.xtext :[XtextLinkingDiagnostic: null:5 Couldn t resolve reference to EPackage  http://www.eclipse.org/ocl/3.0.0/BaseCST .]
    at org.eclipse.xtext.generator.LanguageConfig.setUri(LanguageConfig.java:112)
    ... 41 more

So probably I missing something? The problem is quite easy to reproduce. Create a new Xtext project, add the dependency, edit the grammar and add the last import statement ("import "http://...") and try to generate the Xtext artifacts. Any ideas are welcome!

Thanks in advance!
Michael

EDIT: In order to use a grammar you have to refer in your MWE2 workflow (see section 3.2.2.2 of the the Xtext documentation (version 1.0.1)) to the corresponding genmodel file of the ecore model, for example

fragment = org.eclipse.xtext.generator.ecore.EcoreGeneratorFragement {
  referencedGenModels = "platform:/plugins/org.eclipse.ocl.examples.xtext.base/model/BaseCST.genmodel
} 

Nevertheless it s still not working for me.

问题回答

Is the CompleteOCL project part of the Eclipse workspace that contains your Xtext project? If so you could try to reference the Ecore file using the platform URI you mentioned:

import "platform:/resource/org.eclipse.ocl.examples.xtext.base/model/BaseCST.ecore" as base

instead of

import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

If the CompleteOCL project s bundles are part of your Eclipse target platform (e.g., part of your Eclipse installation), then the

Couldn t resolve reference to EPackage  http://www.eclipse.org/ocl/3.0.0/BaseCST 

error imho indicates that the bundle providing this EPackage is not activated.

Your best shot should be to install that grammar within your eclipse. Import your CompleteOCL project. Then right click on it>export>deployable plug-ins and fragments>check CompleteOCL project>and click the radio button install into host>Click finish and restart Eclipse.

Now your should be able to make your import as import "http://www.eclipse.org/ocl/3.0.0/BaseCST" as base

Regards,

Xavier





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签