Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Solved] How2 access top AST from Validator,Quickfix,Proposal(How to access top AST from the Validator and Quickfix.xtend)
[Solved] How2 access top AST from Validator,Quickfix,Proposal [message #1385914] Thu, 12 June 2014 09:05 Go to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
I'm a newbie in XTEXT as well as in JAVA,
so I need some detailed example for a kickstart:

I customise Validator and Quickfix for an issue deep down in the AST levels.

There I need to access to an attribute of the topmost (Model) level.

Something like:
if (model.isSimple) ....

In the generator, I use
makeTheCif(resource.contents.head as Model)

What is the easiest way to do so in Validator, Proposal and QuickFix?

[Updated on: Tue, 17 June 2014 14:30]

Report message to a moderator

Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386000 is a reply to message #1385914] Thu, 12 June 2014 20:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

you can use EcoreUtil2.getContainerOfType(ctx, Model.class) to access the root type (i asume it is Model) from any eObject ctx


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386142 is a reply to message #1386000] Fri, 13 June 2014 15:23 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Christian, thanks for the hint. Greetings from Frankfurt to Kiel, Uli
Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386146 is a reply to message #1386142] Fri, 13 June 2014 15:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

it is actually Stuttgart respectively Nuremberg


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386251 is a reply to message #1386146] Mon, 16 June 2014 07:49 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
ok, here is the code that works for me:
Both are based on the EcoreUtil2.getRootContainer method

in the validator:

	def checkMergefileVariablesShouldNotBeEmpty(Mergefile mergefile) {
			val EObject myObject = mergefile
			var rootContainer = EcoreUtil2.getRootContainer(myObject) as Model
			System.out.println(rootContainer.name)


in the quickfix, I had to extend the arguments to include "element" to make it work:

	def addMergefileValues(Issue issue, IssueResolutionAcceptor acceptor) {
		acceptor.accept(issue, 'variables set empty', 'Generate variable set.', '') 
		[ element, context |
			var rootContainer = EcoreUtil2.getRootContainer(element) as Model
			System.out.println("quickfix-calls: " + rootContainer.name)

[Updated on: Mon, 16 June 2014 07:50]

Report message to a moderator

Previous Topic:NPE in GlobalURIEditorOpener
Next Topic:NullPointer when generating parser
Goto Forum:
  


Current Time: Thu Mar 28 22:55:45 GMT 2024

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

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

Back to the top