|
|
Re: Unit Test for XAnnotation validation shows unresolved reference [message #1734276 is a reply to message #1734243] |
Mon, 06 June 2016 17:03 |
Marek Stankiewicz Messages: 11 Registered: June 2016 |
Junior Member |
|
|
Hi Christian,
Thanks for looking into my problem.
Here is validation:
/*
* Checking action block annotation
*/
@Check
def checkActionBlockAnnotation(JGActionBlock actionBlock) {
actionBlock.annotations.forEach[annotation |
println("checkActionBlockAnnotation=" + annotation.annotationType)
if(annotation.annotationType instanceof JYActionBlock) {
val pair = annotation.elementValuePairs
println(pair)
}
]
}
package eu.jgen.gen.open.mdl.tests
import com.google.inject.Inject
import eu.jgen.gen.open.mdl.jGModel.JGModel
import org.eclipse.xtext.generator.InMemoryFileSystemAccess
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.eclipse.xtext.junit4.validation.ValidationTestHelper
import org.eclipse.xtext.util.JavaVersion
import org.eclipse.xtext.xbase.compiler.InMemoryJavaCompiler
import org.eclipse.xtext.xbase.compiler.InMemoryJavaCompiler.Result
import org.eclipse.xtext.xbase.compiler.JavaSource
import org.eclipse.xtext.xbase.compiler.JvmModelGenerator
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(XtextRunner)
@InjectWith(JGModelInjectorProvider)
class JGModelAnnotation //extends AbstractXbaseEvaluationTest
{
@Inject extension ParseHelper<JGModel>
@Inject extension ValidationTestHelper
// @Inject InMemoryJavaCompiler javaCompiler
@Inject JvmModelGenerator generator
@Test
def void testActionBlockWithAnnotation() {
// val setup = new StandaloneSetup ()
// setup.setPlatformUri("/Users/Marek/git/stage-two/eu.jgen.gen.open.mdl.tests");
//
// JGModelStandaloneSetup.doSetup()
var InMemoryJavaCompiler javaCompiler = new InMemoryJavaCompiler(this.class.classLoader, JavaVersion.JAVA7)
val model = '''
package example.one
system myx
commands {
cmd is EXIT
}
@JYActionBlock (bussys1="My")
action SelectPerson {
main {
}
}
'''.parse
model.assertNoError("")
val fsa = new InMemoryFileSystemAccess()
generator.doGenerate(model.eResource(), fsa)
val JavaSource[] s = newArrayOfSize(4)
val map = fsa.allFiles
s.set(0,
new JavaSource("DEFAULT_OUTPUTexample/one/Command.java",
map.get("DEFAULT_OUTPUTexample/one/Command.java").toString()))
s.set(1,
new JavaSource("DEFAULT_OUTPUTexample/one/Global.java",
map.get("DEFAULT_OUTPUTexample/one/Global.java").toString()))
s.set(2,
new JavaSource("DEFAULT_OUTPUTexample/one/ActionBlock.java",
map.get("DEFAULT_OUTPUTexample/one/ActionBlock.java").toString()))
s.set(3,
new JavaSource("DEFAULT_OUTPUTexample/one/SelectPerson.java",
map.get("DEFAULT_OUTPUTexample/one/SelectPerson.java").toString()))
val Result result = javaCompiler.compile(s)
result.compilationProblems.forEach [ problem |
println(problem)
]
}
}
and it prints when running inside unit test:
checkActionBlockAnnotation=JvmVoid: (eProxyURI: __synthetic0.mdl#|0)
Generated Java code is correct and compiles OK. It does not have annotation replicated and this is as designed. Annotations are just a device to influence code generation process. It looks like validation cannot resolve to Jvm when in unit test.
Regards
Marek
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04289 seconds