Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360364

Summary: Import of existing EPackages in grammars that inherit from Xbase
Product: [Modeling] TMF Reporter: Natalia Ossipova <mail>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: Holger.Schill, sebastian.zarnekow
Version: 2.0.1Flags: sebastian.zarnekow: indigo+
Target Milestone: SR2   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Example projects illustrating the issue
none
Screenshot Open Model Element dialog none

Description Natalia Ossipova CLA 2011-10-09 13:12:15 EDT
Build Identifier: 


It is impossible to make two different grammars import an existing EPackage if one of the grammars imports the other and a third grammar this EPackage was derived from inherits from Xbase. Look at the example below.

Types
--------
grammar org.xtext.example.dsl.types.Types with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations

generate types "http://www.xtext.org/example/dsl/Types"

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

Units
--------
grammar org.xtext.example.dsl.units.Units with org.xtext.example.dsl.types.Types

generate units "http://www.xtext.org/example/dsl/Units"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmtypes
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase

Expressions
----------------
grammar org.xtext.example.dsl.expressions.Expressions with org.xtext.example.dsl.units.Units

generate expressions "http://www.xtext.org/example/dsl/Expressions"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmtypes
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase

Pattern
----------
grammar org.xtext.example.dsl.pattern.Pattern with org.xtext.example.dsl.expressions.Expressions

generate pattern "http://www.xtext.org/example/dsl/Pattern"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmtypes
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.xtext.org/example/dsl/Types" as types

Function
-------------
grammar org.xtext.example.dsl.function.Function with org.xtext.example.dsl.types.Types

generate function "http://www.xtext.org/example/dsl/Function"

import "http://www.xtext.org/example/dsl/Types" as types
import "platform:/resource/org.xtext.example.dsl.pattern/src-gen/org/xtext/example/dsl/pattern/Pattern.ecore" as pattern

This last import statement causes an error:
"The referenced package 'http://www.xtext.org/example/dsl/Types'
was imported from a different location. Here: 'platform:/resource/org.xtext.example.dsl.types/src-gen/org/xtext/example/dsl/types/Types.ecore"

The MWE2-Workflow crashes with the same error.

Trying to use the Namespace URI results in another error:
"Couldn't resolve reference to EPackage 'http://www.xtext.org/example/dsl/Pattern'."

The MANIFEST file of the Function language contains all needed dependencies:
org.eclipse.xtext.xbase,
org.xtext.example.dsl.units,
org.xtext.example.dsl.types,
org.xtext.example.dsl.expressions,
org.xtext.example.dsl.pattern


Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2011-10-09 14:56:08 EDT
Which Xtext build do you use?
Comment 2 Sebastian Zarnekow CLA 2011-10-09 14:56:48 EDT
How do you configure your workflow? Please attach a reproducable example project if possible.
Comment 3 Natalia Ossipova CLA 2011-10-10 15:52:46 EDT
(In reply to comment #1)
> Which Xtext build do you use?

I've tried two different build versions in my target platform: the 2.0.1 release and a nightly N201110060342. Same result.

(In reply to comment #2)
> How do you configure your workflow? Please attach a reproducable example
> project if possible.

Ok, I'll try to reproduce the issue with some dummy projects.
Comment 4 Natalia Ossipova CLA 2011-10-10 18:20:22 EDT
Created attachment 204912 [details]
Example projects illustrating the issue

Steps to reproduce the issue:
1. Extract the projects into your Eclipse workspace.
2. Open the grammar Function.xtext.
3. Try to import the Pattern EPackage either by using a platform URI or a namespace URI (uncomment one of the import statements).

Note: These projects were created using Xtext release build 2.0.1.
Comment 5 Sebastian Zarnekow CLA 2011-10-10 18:23:50 EDT
Thanks for the reproducable example.
Comment 6 Sebastian Zarnekow CLA 2011-10-11 05:52:19 EDT
Natalia,

I could not reproduce the issue with the latest nightly of Xtext. Both with Xtext plugins in my workspace as with a fresh and shiny empty workspace the languages validated fine in the editor. The workflows missed some information, though. I had to add the following information to the standalone setup:


scanClassPath = true
registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"

In addition, the functions test lang required the PatternPackage to be registered:

registerGeneratedEPackage = "org.xtext.example.dsl.pattern.pattern.PatternPackage"

I even made the languages more complex. That is, I referenced other rules and types and the generator worked flawlessly. Please reopen, if I missed something.

Just as a sidenote: The eclipse build server is currently not responding / working. You may not be able to access the "latest" nightlies. However, there were no changes in the underlying implementation for a couple of weeks so I expect the thing to be fixed short after 2.0.1 was out (at least we worked on this one in those weeks).
Comment 7 Holger Schill CLA 2011-10-11 05:55:07 EDT
I this scanClassPath = true is the key.

That is what I also observed in my current project.
Comment 8 Natalia Ossipova CLA 2011-10-11 18:00:21 EDT
Sebastian,

I upgraded my Xtext build to the nightly N201110100446 and added the missing informations to all workflows. The workflows run smooth now. But the Function grammar still has an error at the Pattern import line: "Couldn't resolve reference to EPackage 'http://www.xtext.org/example/dsl/Pattern'."

By the way, if I let the Function language inherit from the Pattern language instead of Types (see below) the error disappears.

grammar org.xtext.example.dsl.function.Function with org.xtext.example.dsl.pattern.Pattern

generate function "http://www.xtext.org/example/dsl/Function"

import "http://www.xtext.org/example/dsl/Types" as types
import "http://www.xtext.org/example/dsl/Pattern" as pattern
Comment 9 Sebastian Zarnekow CLA 2011-10-11 18:07:43 EDT
(In reply to comment #8)
> Sebastian,
> 
> I upgraded my Xtext build to the nightly N201110100446 and added the missing
> informations to all workflows. The workflows run smooth now. But the Function
> grammar still has an error at the Pattern import line: "Couldn't resolve
> reference to EPackage 'http://www.xtext.org/example/dsl/Pattern'."

Looks like the ecore file with the Pattern package was not properly indexed. Can you find the package via ctrl+shift+f3 / cmd+shift+f3?

You have to make sure that the Pattern language was properly generated prior to being able to reference the package, but since you mentioned that all workflows run smoothly, I assume that you already did this.
Comment 10 Natalia Ossipova CLA 2011-10-11 18:30:03 EDT
Created attachment 204979 [details]
Screenshot Open Model Element dialog

Yes, I can find the package via cmd+shift+f3. Look at the screenshot please.
Comment 11 Natalia Ossipova CLA 2011-10-14 05:15:14 EDT
It works now. The strange behavior of the Xtext grammar editor was caused by the mix of different versions of Xtext plugins installed in Eclipse and in the target platform (Grrrr!).