Dispatch inferrer to child elements [message #1735158] |
Thu, 16 June 2016 00:18 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Mansour Al![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=mansour.alakeel%40gmail.com) 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 #1735280 is a reply to message #1735170] |
Thu, 16 June 2016 22:14 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Mansour Al![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=mansour.alakeel%40gmail.com) 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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02627 seconds