|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.codehaus.groovy.ast.builder.AstBuilder
class AstBuilder extends java.lang.Object
The AstBuilder provides several ways to build an abstract syntax tree (AST) of Groovy code. You can convert a String into AST using the buildFromString method. You can convert code into AST using the buildFromCode method. You can use the AST DSL with the buildFromSpec method. For more information, see the resources on the Groovy wiki pages.
Method Summary | |
---|---|
java.util.List
|
buildFromCode(CompilePhase phase = CompilePhase.CLASS_GENERATION, boolean statementsOnly = true, Closure block)
Builds AST based on the code within the Closure parameter. |
java.util.List
|
buildFromSpec(Closure specification)
Builds AST based on the DSL data within the Closure parameter. |
java.util.List
|
buildFromString(CompilePhase phase = CompilePhase.CLASS_GENERATION, boolean statementsOnly = true, java.lang.String source)
Builds AST based on the code within the String parameter. |
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 |
---|
java.util.List buildFromCode(CompilePhase phase = CompilePhase.CLASS_GENERATION, boolean statementsOnly = true, Closure block)
def builder = new AstBuilder()
builder.buildFromCode {
// some code
}
While this code will:
new AstBuilder().buildFromCode {
// some code
}
The compiler rewrites buildFromCode invocations into AstBuilder.buildFromString
invocations. An exception raised during AST generation will show a stack trace from AstBuilder.buildFromString
and not from AstBuilder.buildFromCode .
The compiler saves the source code of the closure as a String within the Java class file. The String source
of the closure will be visible and un-obfuscated within the class file. If your Closure parameter contains
sensitive data such as a hard-coded password then that data is free to be seen by anyone with the class file.
Do not store sensitive data within the closure parameter.phase
- the CompilePhase the AST will be targeted towards. Default is CompilePhase.CLASS_GENERATIONstatementsOnly
- when true, only the script statements are returned. WHen false, you will
receive back a Script class node also. Default is true.block
- the code that will be converted
java.util.List buildFromSpec(Closure specification)
specification
- the contents to create
java.util.List buildFromString(CompilePhase phase = CompilePhase.CLASS_GENERATION, boolean statementsOnly = true, java.lang.String source)
phase
- the CompilePhase the AST will be targeted towards. Default is CompilePhase.CLASS_GENERATIONstatementsOnly
- when true, only the script statements are returned. WHen false, you will
receive back a Script class node also. Default is true.source
- The source code String that will be compiled.
Groovy Documentation