|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectkotka.groovy.zweig.ZweigBuilder
class ZweigBuilder
ZweigBuilder translates a high-level AST description
into the actual groovy AST representation. The sole entry point is
the fromSpec method. All of the below described structures
nest arbitrarily.
Also fromSpec is idempotent. So you
may provide your custom created ASTNodes directly should
the need arise. In this case fromSpec will leave them
alone.
The following constants are immediately translated to constant expressions:
null
ClassExpressions)
More complicated specifications are described by maps. The following describes the available structures. Each key in the map describes part of the information required to build the structure.
Note: The first key described is always the one used to decide which type of structure is actually meant.
Note: In case there is the default value given for a keyword, this keyword is optional. If it is not contained in the specification map, then the default value will apply.
list
Example:
// spec
[list: ["foo", "bar"]]
// corresponding code
["foo", "bar"]
map
Example:
// spec
[map: [foo: "bar", baz: 5]]
// corresponding code
[foo: "bar", baz: 5]
variable
Example:
// spec
[variable: "foo"]
// corresponding code
foo
return
Example:
//spec
[return: [variable "foo"]]
// corresponding code
return foo
set
to
Example:
// spec
[set: [variable: foo]
to: 5]
// corresponding code
foo = 5
property
of
this
Example:
// spec
[property: "bar"
of: [variable: "foo"]]
// corresponding code
foo.bar
this (not via getter/setter)field
of
this
Example:
// spec
[field: "size"
of: String]
// corresponding code
this.size
call
on
with
Example:
// spec
[call: "bar",
on: [variable: "foo"],
with: ["baz", 5]]
// corresponding code
foo.bar("baz", 5)
staticCall
on
with
Example:
// spec
[staticCall: "format",
on: String,
with: ["%d", 5]]
// corresponding code
String.format("%d", 5)
construct
with
Example:
// spec
[construct: String,
with: [[variable: "inputBytes"]]]
// corresponding code
new String(inputBytes)
method
returnType
Object
modifier
public or static. This
can be a string for a single modifier, an integer (as per
java.lang.reflect.Modifier) or a list of thereof.arguments
exceptions
body
Example:
// spec
[method: "frobnicateFoo"
modifier: "static"
returnType: Boolean,
arguments: [[foo: AFoo], [bar: Integer], [baz: Integer]],
body: [
[call: "frobnicate",
on: [variable: "foo"],
with [[variable: "bar"]]],
[call: "frobnicate",
on: [variable: "foo"],
with: [[variable: "baz"]]],
true
]]
// corresponding code
def static Boolean frobnicateFoo(Integer bar, Integer baz) {
foo.frobnicate bar
foo.frobnicate baz
true
}
constructor
modifier
public or static. This
can be a string for a single modifier, an integer (as per
java.lang.reflect.Modifier) or a list of thereof.arguments
exceptions
body
Example:
// spec
[construct: "Foo"
arguments: [[bar: Integer]],
body: [
[construct: ClassNode.SUPER,
with ["foo", [variable: "bar"]]]
]]
// corresponding code
Foo(Integer bar) {
super("foo", bar)
}
| Method Summary | |
|---|---|
static java.lang.Object
|
fromSpec(java.lang.Object spec)
Converts a high-level description of the desired outcome into the actual groovy AST structure. |
| Methods inherited from class java.lang.Object | |
|---|---|
| java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
| Method Detail |
|---|
static java.lang.Object fromSpec(java.lang.Object spec)
fromSpec is
idempotent.
spec - a high-level AST specification
Groovy Documentation