Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [XCORE] How to define a non cross reference
[XCORE] How to define a non cross reference [message #1268446] Mon, 10 March 2014 10:08 Go to next message
Simone Di Cola is currently offline Simone Di Cola
Messages: 44
Registered: February 2014
Member
Hi all,
according to the code below, could you please tell me how (and if it possible to) refer to the array defined inside the class ComputationUnit from the class Service?

class ComputationUnit{
contains Method[1..*] methods
}

class Method{
String name
String signature
Object sourceCode
contains Parameter[1..*] parameters
}

class Service{
contains Comment comment
contains Parameter[1..*] parameters
contains Contract[0..*] contracts
refers Method[] methods //How can I refer to the array defined inside the ComputationUnit class?
}
Re: [XCORE] How to define a non cross reference [message #1268566 is a reply to message #1268446] Mon, 10 March 2014 13:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25999
Registered: July 2009
Senior Member
Simone,

This is again a question of navigation and with only snippets of the
model, it's not clear how to answer...

On 10/03/2014 3:08 PM, Simone Di Cola wrote:
> Hi all,
> according to the code below, could you please tell me how (and if it
> possible to) refer to the array defined inside the class
> ComputationUnit from the class Service?
>
> class ComputationUnit{
> contains Method[1..*] methods }
>
> class Method{
> String name
> String signature
> Object sourceCode
> contains Parameter[1..*] parameters
> }
>
> class Service{
> contains Comment comment
> contains Parameter[1..*] parameters
> contains Contract[0..*] contracts
> refers Method[] methods //How can I refer to the array defined
> inside the ComputationUnit class?
> }
Re: [XCORE] How to define a non cross reference [message #1268579 is a reply to message #1268566] Mon, 10 March 2014 13:45 Go to previous messageGo to next message
Simone Di Cola is currently offline Simone Di Cola
Messages: 44
Registered: February 2014
Member
Thanks ED for your answer. Following your advice in my previous topic, I've come up with this implementation:

class ComputationUnit{
contains Method[1..*] methods
op Method getMethod(String methodSignature) {
for (Method method : methods) {
if(method.signature == methodSignature) return method
}
return null
}
}

class Method{
String signature
String sourceCode
contains Parameter[1..*] parameters
}


class MethodReference{
contains Method methodReference
}

class Service{
contains MethodReference[1..*] methodReferences
contains Comment comment
contains Parameter[1..*] parameters
contains Contract[0..*] contracts
}

So now I can assign a reference of a Method to a service by doing something like this:

Service s1 = factory.createService();
Method m1 = factory.createMethod();
MethodReference mr = factory.createMethodReference();

m1.setSignature("void increment ( int m, int &n )");
mr.setMethodReference(m1);
s1.getMethodReferences().add(mr);

Do you know a better way to do it?

Thanks
Simone



Re: [XCORE] How to define a non cross reference [message #1268595 is a reply to message #1268579] Mon, 10 March 2014 14:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25999
Registered: July 2009
Senior Member
Simone,

Comments below.

On 10/03/2014 6:45 PM, Simone Di Cola wrote:
> Thanks ED for your answer. Following your advice in my previous topic,
> I've come up with this implementation:
>
> class ComputationUnit{
> contains Method[1..*] methods
> op Method getMethod(String methodSignature) {
> for (Method method : methods) {
> if(method.signature == methodSignature) return method
That seems reasonable, but you'll want to be pretty sure that signatures
such as void increment ( int m, int &n ) use a consistent whitespace
convention if you're going to use String equality... Note too that
using Xbase's closures you can express this more elegantly... The Xtend
documentation shows some of these nice capabilities...
> }
> return null
> }
> }
>
> class Method{
> String signature
> String sourceCode
> contains Parameter[1..*] parameters
> }
>
>
> class MethodReference{
> contains Method methodReference
> }
>
> class Service{
> contains MethodReference[1..*] methodReferences
> contains Comment comment
> contains Parameter[1..*] parameters
> contains Contract[0..*] contracts
> }
>
> So now I can assign a reference of a Method to a service by doing
> something like this:
> Service s1 = factory.createService();
> Method m1 = factory.createMethod();
> MethodReference mr = factory.createMethodReference();
>
> m1.setSignature("void increment ( int m, int &n )");
> mr.setMethodReference(m1);
> s1.getMethodReferences().add(mr);
>
> Do you know a better way to do it?
> Thanks
> Simone
>
>
>
>
Re: [XCORE] How to define a non cross reference [message #1272391 is a reply to message #1268595] Mon, 17 March 2014 16:20 Go to previous messageGo to next message
Simone Di Cola is currently offline Simone Di Cola
Messages: 44
Registered: February 2014
Member
Hi Ed,
how can I define a not contained EReference? I mean, how can I define a reference without using the contains keyword? (if it is possible of course)

Simone
Re: [XCORE] How to define a non cross reference [message #1272399 is a reply to message #1272391] Mon, 17 March 2014 16:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25999
Registered: July 2009
Senior Member
Simone,

Keep in mind that context completion proposals will show you the
keywords (though very far down in the list). The "refers" keyword is
used to specify cross references.

On 17/03/2014 1:20 PM, Simone Di Cola wrote:
> Hi Ed,
> how can I define a not contained EReference? I mean, how can I define
> a reference without using the contains keyword? (if it is possible of
> course)
> Simone
Re: [XCORE] How to define a non cross reference [message #1272629 is a reply to message #1272399] Tue, 18 March 2014 07:15 Go to previous message
Simone Di Cola is currently offline Simone Di Cola
Messages: 44
Registered: February 2014
Member
Thanks Ed,
It was so obvious.

Thanks again
Simone
Previous Topic:[XCORE] Meaning of the command Contains resolving
Next Topic:Eclipse 4.3 Paste holding unwanted transitions
Goto Forum:
  


Current Time: Wed Aug 20 18:37:54 EDT 2014

Powered by FUDForum. Page generated in 0.01694 seconds