Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] wrapping an existing enum
[Xcore] wrapping an existing enum [message #1776541] Fri, 17 November 2017 13:32 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1250
Registered: October 2011
Senior Member
I try to realize an implementation of an existing API with Xcore. In addition to interfaces, this API has also a classic enumeration.

Take this example: Rating.java
package existing.api;

public enum Rating {
	A_RATING,
	B_RATING,
	C_RATING
}


I was hoping to be able to do something like this in Ecore:
package simple.model
interface Rating wraps existing.api.Rating {}

class Book {
    String name
    Rating rating
}


But this doesn't seem to work. It generates an error in the Switch class.
In my example in: simple.model.util.ModelSwitch.doSwitch(int, EObject):

@Override
protected T doSwitch(int classifierID, EObject theEObject) {
    switch (classifierID) {
        case ModelPackage.RATING: {
            Rating rating = (Rating)theEObject; //compiler Error: Cannot cast from EObject to Rating
            T result = caseRating(rating);
            if (result == null) result = defaultCase(theEObject);
            return result;
        }
    ...


Any Idea what I can do?

Thank you in advance.
Re: [Xcore] wrapping an existing enum [message #1776550 is a reply to message #1776541] Fri, 17 November 2017 15:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29116
Registered: July 2009
Senior Member
It doesn't make sense to wrap something that isn't a Java interface as an Xcore interface. Also, if you want to use the classifier to define a non-transient attribute's type, you need to use a data type, not a class/interface. There is no support for wrapping an existing enum as anything another than a data type. I.e., an EEnum/xEnum can't be a wrapper. So you can use "type Foo wraps A.b.c" and you can define the create/convert operations in the type definition. Ctrl-Space is your friend.
Previous Topic:[CDO] Exception when switching to Oxygen
Next Topic:Exception when resolving Cross References
Goto Forum:
  


Current Time: Wed Jan 17 18:29:19 GMT 2018

Powered by FUDForum. Page generated in 0.01637 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software