首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Groovyshell上应用Newify

无法在Groovyshell上应用Newify
EN

Stack Overflow用户
提问于 2018-10-29 07:39:20
回答 1查看 44关注 0票数 0

我想在Groovyshell的帮助下运行一些动态脚本。但是,我不想在动态脚本中编写新关键字。因此,我想添加一个带有Newify关键字的CompilerConfiguration。但是,事情并没有像预期的那样运作。

代码语言:javascript
复制
CompilerConfiguration configuration = new CompilerConfiguration()
 configuration.addCompilationCustomizers(
            new ASTTransformationCustomizer(
                    [pattern: "[A-Za-z0-9].*"],
                    Newify
            ))
GroovyShell shell = new GroovyShell(profile, configuration)

但我还是会犯错误

找不到匹配方法sample#BoundingRegion(int,int)

其中BoundingRegion是一个类

EN

回答 1

Stack Overflow用户

发布于 2018-12-31 10:34:32

也许你需要提供更多的信息。这对我来说很管用:

代码语言:javascript
复制
import org.codehaus.groovy.control.*
import org.codehaus.groovy.control.customizers.*

def script = '''
class Main {
    static main(args) {
        assert BigInteger.new(42).toString() == '42' // Ruby style
        assert BigDecimal('3.14').toString() == '3.14' // Python style matching regex
    }
}
'''

def configuration = new CompilerConfiguration()
configuration.addCompilationCustomizers(
        new ASTTransformationCustomizer(
                [pattern: "[A-Za-z0-9].*"],
                Newify
        ))

new GroovyShell(configuration).evaluate(script)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53040829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档