Skip to content

Instantly share code, notes, and snippets.

@grimrose
Last active December 15, 2015 01:29
Show Gist options
  • Save grimrose/5180760 to your computer and use it in GitHub Desktop.
Save grimrose/5180760 to your computer and use it in GitHub Desktop.
ASTTestの実行結果
package ast
import groovy.transform.*
@ASTTest(value = {
def owner = node.declaringClass
assert owner.fields.any { it.name == 'x' }
})
@Field int y
y = 10
def x = 10
assert x + y == 20
groovy> package ast
groovy> import groovy.transform.*
groovy> @ASTTest(value = {
groovy> def owner = node.declaringClass
groovy> assert owner.fields.any { it.name == 'x' }
groovy> })
groovy> @Field int y
groovy> y = 10
groovy> def x = 10
groovy> assert x + y == 20
Exception thrown
3 17, 2013 6:01:15 午後 org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
Assertion failed:
assert owner.fields.any { it.name == 'x' }
| | |
| | false
| [org.codehaus.groovy.ast.FieldNode@600f3277]
ast.ConsoleScript3
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:399)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:655)
at Script1.run(Script1.groovy:2)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:527)
at groovy.lang.GroovyShell$evaluate.call(Unknown Source)
at org.codehaus.groovy.transform.ASTTestTransformation$1.call(ASTTestTransformation.groovy:78)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:532)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613)
at groovy.lang.GroovyShell.run(GroovyShell.java:480)
at groovy.lang.GroovyShell.run(GroovyShell.java:163)
at groovy.lang.GroovyShell$run.call(Unknown Source)
at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy:951)
at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at groovy.lang.Closure.call(Closure.java:411)
at groovy.lang.Closure.call(Closure.java:405)
at groovy.lang.Closure.run(Closure.java:492)
at java.lang.Thread.run(Thread.java:722)
Assertion failed:
assert owner.fields.any { it.name == 'x' }
| | |
| | false
| [org.codehaus.groovy.ast.FieldNode@600f3277]
ast.ConsoleScript3
at Script1.run(Script1.groovy:2)
package ast
import groovy.transform.*
public class ast.script1363513503077 extends groovy.lang.Script {
java.lang.Integer y
public ast.script1363513503077() {
}
public ast.script1363513503077(groovy.lang.Binding context) {
super.setBinding(context)
}
public static void main(java.lang.String[] args) {
org.codehaus.groovy.runtime.InvokerHelper.runScript(ast.script1363513503077, args)
}
public java.lang.Object run() {
null
y = 10
java.lang.Object x = 10
assert x + y == 20 : null
}
}
Unable to produce AST for this phase due to an error:
assert owner.fields.any { it.name == 'x' }
| | |
| | false
| [org.codehaus.groovy.ast.FieldNode@54fad185]
ast.script1363513503077
Fix the above error(s) and then press Refresh
package ast
import groovy.transform.*
@ASTTest(value = {
def owner = node.declaringClass
assert owner.fields.any { it.name == 'x' }
})
@Field int x
package ast
import groovy.transform.*
public class ast.script1363513620666 extends groovy.lang.Script {
java.lang.Integer x
public ast.script1363513620666() {
}
public ast.script1363513620666(groovy.lang.Binding context) {
super.setBinding(context)
}
public static void main(java.lang.String[] args) {
org.codehaus.groovy.runtime.InvokerHelper.runScript(ast.script1363513620666, args)
}
public java.lang.Object run() {
null
}
}
import groovy.transform.*
List awe = [1, 2, 3]
def awesum() { awe.sum() }
assert awesum() == 6
groovy> import groovy.transform.*
groovy> List awe = [1, 2, 3]
groovy>
groovy> def awesum() { awe.sum() }
groovy> assert awesum() == 6
Exception thrown
3 17, 2013 6:29:47 午後 org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
groovy.lang.MissingPropertyException: No such property: awe for class: ConsoleScript6
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at ConsoleScript6.awesum(ConsoleScript6:6)
at ConsoleScript6$awesum.callCurrent(Unknown Source)
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:137)
at ConsoleScript6.run(ConsoleScript6:8)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)
at groovy.lang.GroovyShell.run(GroovyShell.java:481)
at groovy.lang.GroovyShell.run(GroovyShell.java:163)
at groovy.lang.GroovyShell$run.call(Unknown Source)
at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy:951)
at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at groovy.lang.Closure.call(Closure.java:411)
at groovy.lang.Closure.call(Closure.java:405)
at groovy.lang.Closure.run(Closure.java:492)
at java.lang.Thread.run(Thread.java:722)
groovy.lang.MissingPropertyException: No such property: awe for class: ConsoleScript6
at ConsoleScript6.awesum(ConsoleScript6:6)
at ConsoleScript6$awesum.callCurrent(Unknown Source)
at ConsoleScript6.run(ConsoleScript6:8)
import groovy.transform.*
public class script1363513318284 extends groovy.lang.Script {
public script1363513318284() {
}
public script1363513318284(groovy.lang.Binding context) {
super.setBinding(context)
}
public static void main(java.lang.String[] args) {
org.codehaus.groovy.runtime.InvokerHelper.runScript(script1363513318284, args)
}
public java.lang.Object run() {
java.util.List awe = [1, 2, 3]
assert this.awesum() == 6 : null
}
public java.lang.Object awesum() {
awe.sum()
}
}
import groovy.transform.*
@Field
List awe = [1, 2, 3]
def awesum() { awe.sum() }
assert awesum() == 6
import groovy.transform.*
public class script1363513157544 extends groovy.lang.Script {
java.util.List awe
public script1363513157544() {
}
public script1363513157544(groovy.lang.Binding context) {
super.setBinding(context)
}
public static void main(java.lang.String[] args) {
org.codehaus.groovy.runtime.InvokerHelper.runScript(script1363513157544, args)
}
public java.lang.Object run() {
null
assert this.awesum() == 6 : null
}
public java.lang.Object awesum() {
awe.sum()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment