Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351292 - [EOL] Add support for properties based on context operations
Summary: [EOL] Add support for properties based on context operations
Status: NEW
Alias: None
Product: Epsilon
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Antonio Garcia-Dominguez CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-06 05:32 EDT by Antonio Garcia-Dominguez CLA
Modified: 2012-02-06 10:59 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Garcia-Dominguez CLA 2011-07-06 05:32:36 EDT
One nice thing about accessing Java objects from EOL is that if we have the usual pair of getX/setX methods, we can use variable.x to get and set the property. For example, if type A has getName() and setName(String), we can just do:

var x = new Native("A");
("My name is: " + x.name).println();
x.name := 'OtherName';

This is quite convenient. To be consistent, perhaps we should allow the same convenience for model types and their context operations. For instance, we could alias the "name" attribute in type A to "title" with:

operation A getTitle() : String {
  return self.name;
}

operation A setTitle(newTitle : String) {
  self.name := newTitle;
}

And then we could do something like this:

var x = new A;
("Title: " + x.title).println();
x.title := 'B';
Comment 1 Louis Rose CLA 2011-07-06 08:56:50 EDT
I'm not sure about this one. I can't think of a time when I would use this (though I am worryingly low on caffeine right now). Did you have a specific example in mind Antonio?

If we do decide to implement this, we'll need to be careful not to break existing code. For example, at the minute the following code prints data from the model:

x.name.println();

operation A getName() : String {
  return "foo";
}

We'd need to ensure that implementing this feature does not result in the above program invoking getName() and hence printing "foo".
Comment 2 Antonio Garcia-Dominguez CLA 2011-07-06 12:09:53 EDT
One case for this is when the value is not directly available in a model element: since we need to go through several other objects that are connected to the model element and compute some information, we will usually define our get/set methods for this case.

For instance, I have a "ServiceActivity" class which can be annotated by a separate "PerformanceAnnotation", which has a timeLimit attribute. Some ServiceActivities may lack an annotation: in that case, getTimeLimit() must return a default value. Likewise, setTimeLimit(limit) may need to create a PerformanceAnnotation and link it to the ServiceActivity on the fly, before changing the timeLimit attribute in the annotation. Simply using "timeLimit" as if it were a regular attribute would look much cleaner.

As for the risk of calling the wrong method, we could follow the same approach as in the JavaPropertyGetter and JavaPropertySetter. First, we try to access the proper attribute. If that doesn't work, then we check the property. That would get rid of the ambiguity.
Comment 3 Antonio Garcia-Dominguez CLA 2011-07-06 12:10:54 EDT
(In reply to comment #2)
> For instance, I have a "ServiceActivity" class which can be annotated by a
> separate "PerformanceAnnotation", which has a timeLimit attribute. Some
> ServiceActivities may lack an annotation: in that case, getTimeLimit() must
> return a default value. Likewise, setTimeLimit(limit) may need to create a
> PerformanceAnnotation and link it to the ServiceActivity on the fly, before
> changing the timeLimit attribute in the annotation. Simply using "timeLimit" as
> if it were a regular attribute would look much cleaner.

I forgot to mention that getTimeLimit/setTimeLimit would use a ServiceActivity as their context, rather than a PerformanceAnnotation.
Comment 4 Louis Rose CLA 2011-07-06 15:46:15 EDT
(In reply to comment #2)
> As for the risk of calling the wrong method, we could follow the same approach
> as in the JavaPropertyGetter and JavaPropertySetter. First, we try to access
> the proper attribute. If that doesn't work, then we check the property. That
> would get rid of the ambiguity.

Great, I think that this would definitely be preferable.

I must admit that I'm still not sure whether I'd use this or not, but if it doesn't break existing code or complicate maintenance in the future, I think there's absolutely no harm in adding it.
Comment 5 Dimitris Kolovos CLA 2011-07-07 05:29:58 EDT
I'm only worried that this will slow down execution as for every property invokation all the user-defined operations will need to be introspected as well. 

Antonio: Would this help for your scenario? http://www.springerlink.com/content/q353020983320427/
Comment 6 Antonio Garcia-Dominguez CLA 2011-07-21 17:04:52 EDT
Hi Dimitris,

(In reply to comment #5)
> I'm only worried that this will slow down execution as for every property
> invokation all the user-defined operations will need to be introspected as
> well. 
> 
> Antonio: Would this help for your scenario?
> http://www.springerlink.com/content/q353020983320427/

Well, that is a very interesting approach! I'll note it down for later reference.

However, this still forces the user to use a separate custom metamodel, and I'm currently working with the MARTE metamodel from the Papyrus project, so I can't really use that approach in this case.

In any case, this would be a fallback case, so I believe performance should not really be affected except for the cases when we would throw an exception saying "property not found" right now. What do you think?

Another option is to run all test cases a few times, sum up the clock time, switch to the modified version, try it again and see if there are any important differences. Doing that with git-svn is quite easy: I just need to switch branches and try them out.
Comment 7 Antonio Garcia-Dominguez CLA 2011-08-31 04:40:36 EDT
Louis, Dimitris: have you thought a bit more about this?

Shall I give it a try and compare the average running times over 5 runs of both test suites?
Comment 8 Dimitris Kolovos CLA 2011-08-31 10:12:19 EDT
I'm happy with that.
Comment 9 Louis Rose CLA 2011-09-05 06:58:51 EDT
(In reply to comment #8)
> I'm happy with that.

+1
Comment 10 Antonio Garcia-Dominguez CLA 2011-09-19 06:20:40 EDT
In today's telecon, Dimitris has suggested that the EOL context operations take precedence over the Java ones.

If the Java operations took precedence over the EOL context operations, x.getTitle would call the Java operation, and x.title would call the getTitle context operations. We should have it call the getTitle context operation in both cases. This would introduce an inconsistency.

However, doing the right thing in this case might introduce a performance issue. I'll have to open a new branch in my Git mirror and evaluate its impact.