Thursday 15 April 2010

Groovy DSL getting annonymous String assignments -



Groovy DSL getting annonymous String assignments -

i have dsl looks this:

amethod { "a name" "another name" "and 3rd name" }

my problem i'm unable access 3 string, because calling closure returns lastly statement. tried override constructor of string(char[] value) called when annonymous string-statement occurs:

def original // primitive way string(char[])-constructor string.class.constructors.each { if(it.tostring() == "public java.lang.string(char[])") { original = } } // overriding constructor string.metaclass.constructor = { char[] value -> def instance = original.newinstance(value) // ... farther stuff instance ... println "created ${instance}" instance } // teststring phone call string(char[] value) "teststring"

unfortunately didn't work , thought anyway quite complicated. help

thank comments. great define without quotes. but: after having dsl can translated java objects i'd loved have additional annotations in language @ development time. want annotate duplicate names , on. ide's know better, intellij , eclipse handle strings "a name" 1 psi-elements. splitting these elements can inconvinient ... guess. think statements in closure amethod {a name} result in interpretation amethod {a.name}. mean instead of having stringliteral psi "a name", have object-psi , methodcall-psi or that. don't know, , next goal "parsing/creating" java objects. sure impossible override string-constructor?

is constructor called when have groovy script content:

"hello world"

groovy dsl

No comments:

Post a Comment