Last active
August 29, 2015 14:01
-
-
Save Alotor/9b30782aaa49d8c421a2 to your computer and use it in GitHub Desktop.
Test DSL Evaluator that doesn't work as I expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DslEvaluator { | |
def methodMissing(String name, args) { | |
println "M >> $name $args" | |
} | |
def propertyMissing(String name, args) { | |
println "P >> $name" | |
} | |
} | |
def clos = { | |
// This call doesn't call "propertyMissing" | |
String | |
// This does | |
Strin | |
// This will call "methodMissing" | |
String { | |
} | |
// This will not call neither methodMissing nor propertyMissing | |
"STRING" | |
// This will call methodMissing | |
"STRING"() | |
} | |
clos.delegate = new DslEvaluator() | |
clos.resolveStrategy = Closure.DELEGATE_ONLY | |
clos() |
I don't see any solution apart from an AST transformation. Your issue, here, is basically that String
is a valid expression, which returns a Class
, so it's like any other piece of code, it compiles and evaluates fine...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What I mean by "existing class" is a class in the current scope.
I want "hooks" when the DSL looks like...