繁体   English   中英

如何进行AST转换?

[英]How to run AST transformation?

我正在尝试从此示例运行AST转换:

http://melix.github.io/ast-workshop/exercise1-hints.html

但是,当我运行测试时,我的断言失败了。

我需要先编译类AuthorAdderASTTransformation吗? 我什至也这样做了,添加了main方法并对其进行了编译。 但是仍然测试失败说:

groovy.lang.MissingPropertyException: No such property: $AUTHOR for class: org.gr8conf.AuthorAdderASTTransformationTest
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:86)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
    at org.gr8conf.AuthorAdderASTTransformationTest.testThatAuthorExists(AuthorAdderASTTransformationTest.groovy:5)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


groovy.lang.MissingPropertyException: No such property: $AUTHOR for class: Foo
    at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:900)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1729)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1705)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3458)
    at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
    at TestScripttestASTTransformationShouldBeDebuggableFromIDE0.run(TestScripttestASTTransformationShouldBeDebuggableFromIDE0.groovy:4)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:537)
    at groovy.util.GroovyTestCase.assertScript(GroovyTestCase.java:203)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:272)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at org.gr8conf.AuthorAdderASTTransformationTest.testASTTransformationShouldBeDebuggableFromIDE(AuthorAdderASTTransformationTest.groovy:9)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

我在哪里犯错?

异常表明您的测试尝试读取属性$ AUTHOR,但未找到。 假设转换本身是正确的,并且您实际上要求的是正确的类,则意味着它没有运行。 我只能假设这两点,因为您没有提供任何信息。

那么,为什么不运行。 编译Foo时,需要预编译AuthorAdderASTTransformation。 但这还不够,还需要有元数据。 http://www.groovy-lang.org/metaprogramming.html#developing-ast-xforms页面建议为此创建一个jar。 尽管这不是严格要求的,但它可以防止您在编译常规源代码时正确地忘记元数据文件服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM