Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [xcore] generated code should implements an existing interface
[xcore] generated code should implements an existing interface [message #1775752] Sun, 05 November 2017 14:27 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Is there a way to have the generated classes and interfaces implementing an existing API?

---

Take an example:
With this IUser interface (let assume it is defined in a java project that you should not touch):
package existing.api;

public interface IUser {

  String getName();

  String sayHello(IUser user);
}


The User EMF-entity defined by this xcore model is a valid implementation of the "existing.api.IUser":
@GenModel(
    bundleManifest="false",
    modelDirectory="xcore-maven-example/src/main/java-gen",
    complianceLevel="8.0"
)
package sample.model

class User {
    String name

    op String sayHello(User user) {
        "Hello " + user.name
    }
}


If I look at the generated interface "sample.model.User", I would like to have an addition "extends existing.api.IUser" in the interface declaration. Something like:
package sample.model;

import org.eclipse.emf.ecore.EObject;

//<addition>
import existing.api.IUser;
//</addition>

/**
 * <!-- begin-user-doc -->
 * A representation of the model object '<em><b>User</b></em>'.
 * <!-- end-user-doc -->
 *
 * <p>
 * The following features are supported:
 * </p>
 * <ul>
 *   <li>{@link sample.model.User#getName <em>Name</em>}</li>
 * </ul>
 *
 * @see sample.model.ModelPackage#getUser()
 * @model
 * @generated
 */
public interface User extends EObject /*<addition>*/, IUser /*</addition>*/ {
	/**
	 * Returns the value of the '<em><b>Name</b></em>' attribute.
	 * <!-- begin-user-doc -->
	 * <p>
	 * If the meaning of the '<em>Name</em>' attribute isn't clear,
	 * there really should be more of a description here...
	 * </p>
	 * <!-- end-user-doc -->
	 * @return the value of the '<em>Name</em>' attribute.
	 * @see #setName(String)
	 * @see sample.model.ModelPackage#getUser_Name()
	 * @model unique="false"
	 * @generated
	 */
	String getName();

	/**
	 * Sets the value of the '{@link sample.model.User#getName <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @param value the new value of the '<em>Name</em>' attribute.
	 * @see #getName()
	 * @generated
	 */
	void setName(String value);

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @model unique="false" userUnique="false"
	 *        annotation="http://www.eclipse.org/emf/2002/GenModel body='<%java.lang.String%> _name = user.getName();\nreturn (\"Hello \" + _name);'"
	 * @generated
	 */
	String sayHello(User user);

} // User


How can I do this?

Thank you a lot for your inputs.
Re: [xcore] generated code should implements an existing interface [message #1775754 is a reply to message #1775752] Sun, 05 November 2017 16:07 Go to previous messageGo to next message
Jon Passki is currently offline Jon PasskiFriend
Messages: 31
Registered: November 2015
Member

Does the Implementing an Interface section in the Xcore wiki describe what you're trying to do?

import existing.api.IUser
interface IUser wraps IUser
class XcoreUser1 extends IUser {
  op String getName() {...}
  op String sayHello(IUser user) { ... }
}

Re: [xcore] generated code should implements an existing interface [message #1775778 is a reply to message #1775754] Mon, 06 November 2017 09:20 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Thank you a lot for your pointer! I missed it in the doc.

With your suggestion, I got this ERROR:
Quote:
mismatched input 'class' expecting '{' (file:/C:/****/git/xcore-maven-example/src/main/resources/model.xcore line : 11 column : 1)


But it works like this:
@GenModel(
    bundleManifest="false",
    modelDirectory="xcore-maven-example/src/main/java-gen",
    complianceLevel="8.0"
)
package sample.model

import existing.api.IUser
interface IUser wraps IUser {}

class User extends IUser {
    String name

    op String sayHello(IUser user) {
        "Hello " + user.name
    }
}


Thank you a lot.
Previous Topic:Extend EAttributeImpl
Next Topic:[CDO] High Available CDO servers
Goto Forum:
  


Current Time: Fri Apr 26 07:55:25 GMT 2024

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

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

Back to the top