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

Bug 322875

Summary: Missing validation in xtext grammar when importing existing metamodels
Product: [Modeling] TMF Reporter: Sebastian Benz <sebastian.benz>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: clay, sebastian.zarnekow, sven.efftinge
Version: 1.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Sample project that demonstrates the problem.
none
proposed patch pls review none

Description Sebastian Benz CLA 2010-08-17 03:57:21 EDT
Created attachment 176761 [details]
Sample project that demonstrates the problem. 

I created a new Xtext language for an existing metamodel (Sample.ecore). In my model I reference elements in the Ecore metamodel (e.g. EClass):

import "platform:/resource/model/model/Sample.ecore" 

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

Model returns Model:
   reference=[ecore::EClass] //<- validation error
;

The problem is that I get a validation error for the "reference" feature("Cannot find referenced feature reference in sealed EClass model...:"). I took me a while to figure out that the problem was mixing imports by platform resource URI and NSURI. When I import my existing metamodel via its NSURI ("http://sample") everything works fine. I think it would help a lot here to have a corresponding validation. I attached also an example project that demonstrates the problem.
Comment 1 Sebastian Zarnekow CLA 2011-01-10 10:28:09 EST
Scheduled for M5 as grammar mixin and Ecore import will become more popular
with Xbase.
Comment 2 Michael Clay CLA 2011-01-31 16:40:49 EST
(In reply to comment #1)
> Scheduled for M5 as grammar mixin and Ecore import will become more popular
> with Xbase.

thats because Sample.ecore refers to Ecore.ecore as platform:/plugin-uri 

<eStructuralFeatures xsi:type="ecore:EReference" name="reference" eType="ecore:EClass platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EClass"/>

instead of its ns-uri form

    <eStructuralFeatures xsi:type="ecore:EReference" name="reference" eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EClass"/>

should we add an additional check for this kind of errors  

see 

http://www.eclipse.org/forums/index.php?t=msg&goto=551227&S=b33a349f818bb2e41cfceb0b7048056b

and

http://www.eclipse.org/forums/index.php?t=msg&goto=540574&S=85734ae7f35dff9fae4e185c63d0dc08
Comment 3 Sven Efftinge CLA 2011-02-01 03:02:16 EST
(In reply to comment #2)
> should we add an additional check for this kind of errors  

Yes. How would you do it?
Comment 4 Sebastian Zarnekow CLA 2011-02-01 03:06:19 EST
(In reply to comment #3)
> (In reply to comment #2)
> > should we add an additional check for this kind of errors  
> 
> Yes. How would you do it?

I'd assume something along 

if (eClass.ePackage.nsURI == otherEClass.ePackage.nsURI && eClass.fragment == otherEClass.fragment && eClass.uri != otherEClass.uri) {
  ... 
}

would work.
Comment 5 Sebastian Zarnekow CLA 2011-02-01 03:08:24 EST
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > should we add an additional check for this kind of errors  
> > 
> > Yes. How would you do it?
> 
> I'd assume something along 
> 
> if (eClass.ePackage.nsURI == otherEClass.ePackage.nsURI && eClass.fragment ==
> otherEClass.fragment && eClass.uri != otherEClass.uri) {
>   ... 
> }
> 
> would work.

As for the other validation issues that cover misleading errors in the Xtext grammar editor, this would require changes in the grammar inference code.
Comment 6 Sven Efftinge CLA 2011-02-01 03:13:50 EST
We could just check whether any EPackages are referenced twice instead of checking the EClass references. The EPackage reference should be flagged with an error not the EClass reference.
Comment 7 Michael Clay CLA 2011-02-07 07:51:32 EST
Created attachment 188432 [details]
proposed patch pls review
Comment 8 Sebastian Zarnekow CLA 2011-02-07 10:13:48 EST
Michael,

I had to refactor the patch to support grammar inheritance.

Pushed fix to master.
Comment 9 Karsten Thoms CLA 2017-09-19 17:59:53 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 10 Karsten Thoms CLA 2017-09-19 18:10:37 EDT
Closing all bugs that were set to RESOLVED before Neon.0