views:

123

answers:

1

Hi,

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.

+1  A: 

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.

Frank Grimm
Hi Frank, the project is not part of my eclipse project space. I've took the source jars of the corresponding packages and tried to add them manually to my workspace (import projects, etc.) but this hasn't change anything at all. How do I check if a bundle is activated or not? Thanks in advance!
mfrey
To check if a bundle is activated go to menu Help > About Eclipse > Installation details > Plug-ins tab and check if the plug-in/bundle containing the Ecore model file is listed.
Frank Grimm
Here's anther way to check whether a bundle is activated or not: You could also start Eclipse with the OSGi console enabled (by appending '-console' to your eclipse start command) and then use the 'ss' OSGi console command to get a list (and activation state) of the available bundles. Using the console you could also force a bundle to be activated (using the 'start' command).
Frank Grimm
Okay, the package which contains the ecore file is listed in the plugin tabs :-(
mfrey
You might try to check whether the EPackage is actually registered in the global EPackage registry. Try something likeorg.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEPackage("http://www.eclipse.org/ocl/3.0.0/BaseCST")in a small plug-in project and check whether it returns an EPackage. Make sure that the bundle which contains the ecore file is part of your launch configuration that executes the plug-in project above.
Frank Grimm
Hi, I've created a plugin project and tried to get a epackage instance and it's working.
mfrey
Sorry, but I'm running out of ideas. You should probably post to the Xtext news group. I guess they should know whats going on...
Frank Grimm
Hi Frank, thank you for your help!
mfrey
You are quite welcome! BTW: In case you do post to the Xtext news group, it might be beneficial for others having similar problems when you could provide a link to your post here on SO.
Frank Grimm