Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] access field instead of getter
[Xcore] access field instead of getter [message #1759756] Tue, 18 April 2017 08:51 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
In my DSL I am using a boolean property which is set true if a keyword occurs. The keyword should mark this element as invalid which means the element can be used in cross-references but a validator will generate a warning (like @Deprecated in Java)

GroupRule returns Group:
	(invalid?="@Invalid")?
	name=ID "{"
		(groups+=GroupRule)*
		...


In my case groups can be nested so I needed to check if the parent group (eContainer) is invalid as well

So I defined the following in Xcore

class Group
	boolean invalid
	derived boolean valid get {
		!invalid && (eContainer instanceof Group && (eContainer as Group).valid)
	}


Unfortunately this model is not very safe: if someone calls invalid in a generator for example the invariant check parent group for validity isnt applied.

So I tried to override the generated getter for invalid and skip the derived valid.
class Group
	boolean invalid get {
		this.invalid && (eContainer instanceof Group && (eContainer as Group).invalid)
	}


Unfortunately the generated GroupImpl will calls this.invalid() method instead of accessing the field.
I know that Xcore doesnt support everything which would be possible in Java. I assume I have to fall back to an Xtend-extension method but I hope that there is a way to define this kind of rules in my model.

Re: [Xcore] access field instead of getter [message #1759757 is a reply to message #1759756] Tue, 18 April 2017 08:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi you should ask questions on xcore in the emf forum

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xcore] access field instead of getter [message #1759759 is a reply to message #1759757] Tue, 18 April 2017 08:59 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Whoops, sorry. Thought that Xcore is part of Xtext.
Can this thread be moved over by a moderator?
Re: [Xcore] access field instead of getter [message #1759760 is a reply to message #1759759] Tue, 18 April 2017 01:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont know

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xcore] access field instead of getter [message #1759765 is a reply to message #1759759] Tue, 18 April 2017 09:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
No you can't move things, only repost them, but I see the questions in this forum too. As you say, Xcore has its limitations. So, for example, the body of any operation or derived accessor is effectively scoped/compiled against the API (interface) of that XClass, so things that are visible only in the actual Impl class are not visible in the bodies. E.g., fields, or protected methods or anything else not visible in the interface (even suppressed visibility features).

I'm not actually sure what exactly you're trying to express. It seems you model @Invalid explicitly, so you need something that models exactly this state, without derivation based on containers. And that you need a different operation that determines "effectively valid" based on the explicit state of the Group itself and the explicit state of each containing Group. But that's what you did with your first example, which you say isn't very safe in a generator, but I don't understand why that's a problem. Of course the overall derived computation depends on the overall state at that point in time...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] access field instead of getter [message #1759769 is a reply to message #1759765] Tue, 18 April 2017 10:46 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Thanks Ed

The problem with my first approach is code-completion: a developer might just call invalid which would be the state of the current group where he should call the operation valid.

I tried using @GenModel(suppressedGetVisibility="true") on invalid in order to hide the getter, but then the derived getter for valid also doesnt have access to it (there already is a bug for this). This should be what I need, the getter is unavailable on the interface and the setter still is, so Xtext can manipulate the state.

I was hoping there is another way.

[Updated on: Tue, 18 April 2017 10:54]

Report message to a moderator

Re: [Xcore] access field instead of getter [message #1759777 is a reply to message #1759769] Tue, 18 April 2017 12:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Its not totally pretty, but I think this works:
class Group {
	@GenModel(suppressedGetVisibility='true', suppressedSetVisibility='true')
	boolean invalid
	derived boolean valid get {
		!eGet(XyzPackage.Literals.GROUP__INVALID) as Boolean && (eContainer instanceof Group && (eContainer as Group).valid)
	}
}


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] access field instead of getter [message #1759836 is a reply to message #1759777] Tue, 18 April 2017 19:09 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Perfect! A little low-level EMF but who cares Smile
Thank you very much Ed.
Previous Topic:Unable to resolve some references in .mwe2 file
Next Topic:[CDO] Getting UnsupportedOperationException While running OCL query on mongodb
Goto Forum:
  


Current Time: Fri Apr 19 22:11:55 GMT 2024

Powered by FUDForum. Page generated in 0.03686 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top