[XCORE] Hide attribute getter/setter from interface [message #1395864] |
Mon, 07 July 2014 14:02 |
xjn Mising name Messages: 20 Registered: May 2010 |
Junior Member |
|
|
Hi,
I'm trying to hide the generated attribute getter/setter methods from the interface using XCore.
Using the ECore editor to create a model with "suppressedGetVisibility" and "suppressedSetVisibility" annotations everything ist fine, the getXxx/setXxx methods are hidden in the interface and usable in body annotations.
Using the XCore editor has the same effect on the interface, but the attributes are not available to "op" operations in the .xcore.
Here my code snippet (a "test.xcore" in "./model" directory of a XCore-Project):
package test
class A
{
// should hide attribute getter/setter methods from interface
@GenModel(suppressedGetVisibility="true", suppressedSetVisibility="true")
// only local/protected access expected
String protectedText
/* */
op void clearProtectedText() {
// test "attribute" setter
protectedText = null // !error! protectedText(Object) not found
protectedText = "" // !error! protectedText(String) not found
// test "method" setter
setProtectedText(null) // !error! setProtectedText(Object) not found
setProtectedText("") // !error! setProtectedText(String) not found
}
/* */
op String myProtectedText_1() {
// do something with protectedText
// ...
// and return the modified value
return protectedText // !error!
}
/* */
op String myProtectedText_2() {
// do something with protectedText
// ...
// and return the modified value
return getProtectedText() // !error!
}
}
I would expect that the declaring/derived classes have access to both, attribute and getter/setter methods.
Otherwise the attribute could not be used for any purpose ...
thx for help
br
xjn
|
|
|
Re: [XCORE] Hide attribute getter/setter from interface [message #1395927 is a reply to message #1395864] |
Mon, 07 July 2014 16:09 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Xin,
Yes, it's kind of nasty. The bodies of expressions are Xbase-compiled
against the inferred interface (which matches the generated ones), so
when not present in the interface they won't be available. I'm not sure
how best to fix that. Ideally they'd be Xbase-compiled against the
inferred implementation, which would make other proper implementation
details available as well, but, because of multiple inheritance, the
same compiled body must function in any implementation and if the class
is marked as an interface, there is no obvious implementation to compile
relative to. Please open a bugzilla (though it's a long standing
problem without an obvious solution).
On 07/07/2014 4:02 PM, xjn Mising name wrote:
> Hi,
>
> I'm trying to hide the generated attribute getter/setter methods from
> the interface using XCore.
>
> Using the ECore editor to create a model with
> "suppressedGetVisibility" and "suppressedSetVisibility" annotations
> everything ist fine, the getXxx/setXxx methods are hidden in the
> interface and usable in body annotations.
>
> Using the XCore editor has the same effect on the interface, but the
> attributes are not available to "op" operations in the .xcore.
>
>
> Here my code snippet (a "test.xcore" in "./model" directory of a
> XCore-Project):
>
>
> package test
>
> class A
> {
> // should hide attribute getter/setter methods from interface
> @GenModel(suppressedGetVisibility="true",
> suppressedSetVisibility="true")
> // only local/protected access expected
> String protectedText
> /* */
> op void clearProtectedText() {
> // test "attribute" setter
> protectedText = null // !error! protectedText(Object) not found
> protectedText = "" // !error! protectedText(String) not found
>
> // test "method" setter
> setProtectedText(null) // !error! setProtectedText(Object) not
> found
> setProtectedText("") // !error! setProtectedText(String) not found
> }
> /* */
> op String myProtectedText_1() {
> // do something with protectedText
> // ...
> // and return the modified value
> return protectedText // !error!
> }
> /* */
> op String myProtectedText_2() {
> // do something with protectedText
> // ...
> // and return the modified value
> return getProtectedText() // !error!
> }
> }
>
>
> I would expect that the declaring/derived classes have access to both,
> attribute and getter/setter methods. Otherwise the attribute could not
> be used for any purpose ...
>
>
> thx for help
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03883 seconds