Skip to main content



      Home
Home » Modeling » EMF » [Xcore] access field instead of getter
[Xcore] access field instead of getter [message #1759756] Tue, 18 April 2017 04:51 Go to next message
Eclipse UserFriend
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 04:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi you should ask questions on xcore in the emf forum
Re: [Xcore] access field instead of getter [message #1759759 is a reply to message #1759757] Tue, 18 April 2017 04:59 Go to previous messageGo to next message
Eclipse UserFriend
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] Mon, 17 April 2017 21:05 Go to previous messageGo to next message
Eclipse UserFriend
i dont know
Re: [Xcore] access field instead of getter [message #1759765 is a reply to message #1759759] Tue, 18 April 2017 05:37 Go to previous messageGo to next message
Eclipse UserFriend
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...
Re: [Xcore] access field instead of getter [message #1759769 is a reply to message #1759765] Tue, 18 April 2017 06:46 Go to previous messageGo to next message
Eclipse UserFriend
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 06:54] by Moderator

Re: [Xcore] access field instead of getter [message #1759777 is a reply to message #1759769] Tue, 18 April 2017 08:44 Go to previous messageGo to next message
Eclipse UserFriend
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)
	}
}
Re: [Xcore] access field instead of getter [message #1759836 is a reply to message #1759777] Tue, 18 April 2017 15:09 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 22:04:34 EDT 2025

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

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

Back to the top