[Xcore] derived containment [message #1067579] |
Tue, 09 July 2013 08:29  |
Eclipse User |
|
|
|
Hello.
I'd like to express the following with xcore:
A function has a name and optionally a return type. If it has a return type then it contains an additional variable having the same name as the function and the same type as the function.
class Variable {
String varName
String varType
}
class Function {
String name
String returnType
contains Variable localVariables
contains derived Variable returnVariable get {
... how can i create a Variable here
}
// i'm content also with
op Variable getReturnVariable {
...
}
}
Is there a way to access the factory, in order to create a Variable instance?
|
|
|
Re: [Xcore] derived containment [message #1067618 is a reply to message #1067579] |
Tue, 09 July 2013 11:12  |
Eclipse User |
|
|
|
Ravasz,
Comments below.
On 09/07/2013 2:29 PM, Ravasz Roka wrote:
> Hello.
>
> I'd like to express the following with xcore:
> A function has a name and optionally a return type. If it has a return
> type then it contains an additional variable having the same name as
> the function and the same type as the function.
>
> class Variable {
> String varName
> String varType
> }
>
> class Function {
> String name
> String returnType
> contains Variable localVariables
> contains derived Variable returnVariable get {
> ... how can i create a Variable here
> }
In general, derived containment doesn't make sense. Such objects would
have be be contained somewhere else. It's also a problem that you have
no field in the implementation class in which to store the value once
you create it. So this type of thing is not well supported by the
features in Xcore today.
> // i'm content also with
> op Variable getReturnVariable {
> ...
> } }
>
>
> Is there a way to access the factory, in order to create a Variable
> instance?
What kind of editor are you building for this? You're likely better off
just modeling it like a normal containment reference and if you're using
a structured editor, always create the local variable as well. Another
approach (probably better) would be to create the variable automatically
when you set the return type or the name; but again, Xcore is not well
suited for expression that logic directly. You'll be better off
modifying the generated implementation class (which you can still do
with and Xcore model, but you should change the model directory folder
to src instead of src-gen so that it's never just deleted by a clean
build for example).
|
|
|
Powered by
FUDForum. Page generated in 0.26778 seconds