Skip to main content



      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 05:05 Go to next message
Eclipse UserFriend
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 10:30] by Moderator

Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386000 is a reply to message #1385914] Thu, 12 June 2014 16:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

you can use EcoreUtil2.getContainerOfType(ctx, Model.class) to access the root type (i asume it is Model) from any eObject ctx
Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386142 is a reply to message #1386000] Fri, 13 June 2014 11:23 Go to previous messageGo to next message
Eclipse UserFriend
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 11:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

it is actually Stuttgart respectively Nuremberg
Re: How2 access top AST from Validator,Quickfix,Proposal [message #1386251 is a reply to message #1386146] Mon, 16 June 2014 03:49 Go to previous message
Eclipse UserFriend
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 03:50] by Moderator

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


Current Time: Tue Jul 08 14:20:38 EDT 2025

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

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

Back to the top