[xcore] generated code should implements an existing interface [message #1775752] |
Sun, 05 November 2017 09:27  |
Eclipse User |
|
|
|
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 #1775778 is a reply to message #1775754] |
Mon, 06 November 2017 04:20  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.08918 seconds