Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dispatch inferrer to child elements
Dispatch inferrer to child elements [message #1735158] Thu, 16 June 2016 00:18 Go to next message
Mansour Al is currently offline Mansour AlFriend
Messages: 44
Registered: June 2016
Member
I have this grammar:

SuiteDeclaration:
	'suite' name=ValidID ('using' '(' configFiles=Files ')')? '{'
	(actions+=Action)*
	prepare=PrepareDeclaraion
	(actions+=Action)*
	'}';

PrepareDeclaraion:
	'prepare' ('using' '(' configFiles=Files ')')? '{'
	handlers+=EventHandlerDefinition*
	actions+=Action*
	testCases+=TestDefinition+
	'}';

TestDefinition:
	"test" name=ValidID ('using' '(' configFiles=Files ')')? '{'
	actions+=(Action)+
	'}';


In my inferrer :
	
	def dispatch void infer(SuiteDeclaration suite, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {

		acceptor.accept(suite.toClass(suite.fullyQualifiedName)) [
			abstract = true
			members += suite.toMethod("beforeSuite", Void.TYPE.typeRef) [
				static = true
				annotations += annotationRef("org.junit.BeforeClass");
			]

			members += suite.toMethod("afterSuite", typeRef(void)) [
				static = true
				annotations += annotationRef("org.junit.AfterClass");
			]

			for (TestDefinition test : suite.prepare.testCases) 
				infer(test, acceptor, isPreIndexingPhase)
		]
	}



1- I need to get the actions inside the SuiteDeclaration. The actions my appear before and after PrepareDeclartion. How can I process them separately ?

2- How do I infer other Elements as in:

for (TestDefinition test : suite.prepare.testCases)
infer(test, acceptor, isPreIndexingPhase)


Thank you

[Updated on: Thu, 16 June 2016 01:15]

Report message to a moderator

Re: Dispatch inferrer to child elements [message #1735170 is a reply to message #1735158] Thu, 16 June 2016 04:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13181
Registered: July 2009
Senior Member
1 what about putting them into separate lists in the grammar
2 don't get that point - you create a def dispatch infer (Mytype ...) method for each Mytype you want to infer stuff from


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Dispatch inferrer to child elements [message #1735280 is a reply to message #1735170] Thu, 16 June 2016 22:14 Go to previous messageGo to next message
Mansour Al is currently offline Mansour AlFriend
Messages: 44
Registered: June 2016
Member
1- I solved it as per your advice.
2- This will work:

def dispatch void infer(SuiteDeclaration suite, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		acceptor.accept(suite.toClass(suite.fullyQualifiedName)) [	
			packageName = suite.eContainer.fullyQualifiedName.toString
			....
			for (TestDefinition test : suite.prepare.testCases) {
				members += test.toMethod(test.name, typeRef(void)) [
					annotations += annotationRef("org.junit.Test");
				]
			}
		]
	}


But this, will not work:



def dispatch void infer(SuiteDeclaration suite, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		acceptor.accept(suite.toClass(suite.fullyQualifiedName)) [	
			packageName = suite.eContainer.fullyQualifiedName.toString
			....
			for (TestDefinition test : suite.prepare.testCases) {
	                infer(test, acceptor, isPreIndexingPhase)
		}
		]
	}

	def dispatch void infer(TestDefinition testCase, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		testCase.toMethod(testCase.name + "Test", typeRef(void)) [
			annotations += annotationRef("org.junit.Test");
		]
	}


The second one, because I need to add the method to the class as a member (for example "member+= ..." . However, this means that I need to implement all the inferring login inside infer(SuiteDelaration).
Is there a better way, to create a class without having to iterate over all the file at once.

Thank you.
Re: Dispatch inferrer to child elements [message #1735289 is a reply to message #1735280] Fri, 17 June 2016 03:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13181
Registered: July 2009
Senior Member
I don't understand

You can of course split up code to multiple methods. You should name them accordingly.
And no you have to iterate from a starting point if you want to infer multiple stuff into one target


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Dispatch inferrer to child elements [message #1735381 is a reply to message #1735289] Sat, 18 June 2016 00:49 Go to previous message
Mansour Al is currently offline Mansour AlFriend
Messages: 44
Registered: June 2016
Member
This is what I wanted to know. I thought I can use it like a visitor.

Thank you.
Previous Topic:Learning about the type compiler
Next Topic:Scoping the same EObject in an EObject in two contexts
Goto Forum:
  


Current Time: Mon Nov 11 19:46:17 GMT 2019

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

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

Back to the top