Dispatch inferrer to child elements [message #1735158] |
Wed, 15 June 2016 20:18  |
Eclipse User |
|
|
|
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: Wed, 15 June 2016 21:15] by Moderator
|
|
|
|
Re: Dispatch inferrer to child elements [message #1735280 is a reply to message #1735170] |
Thu, 16 June 2016 18:14   |
Eclipse User |
|
|
|
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.03255 seconds