public class StaticCompilationVisitor
extends StaticTypeCheckingVisitor
This visitor is responsible for amending the AST with static compilation metadata or transform the AST so that a class or a method can be statically compiled. It may also throw errors specific to static compilation which are not considered as an error at the type check pass. For example, usage of spread operator is not allowed in statically compiled portions of code, while it may be statically checked. Static compilation relies on static type checking, which explains why this visitor extends the type checker visitor.
| Modifiers | Name | Description |
|---|---|---|
static MethodNode |
ARRAYLIST_ADD_METHOD |
ArrayList.add method node. |
static ClassNode |
ARRAYLIST_CLASSNODE |
Class node for ArrayList. |
static MethodNode |
ARRAYLIST_CONSTRUCTOR |
No-arg ArrayList constructor node. |
static ClassNode |
COMPILESTATIC_CLASSNODE |
Class node for CompileStatic. |
static ClassNode |
TYPECHECKED_CLASSNODE |
Class node for TypeChecked. |
| Constructor and description |
|---|
StaticCompilationVisitor(SourceUnit unit, ClassNode node)Creates a static compilation visitor for the supplied source unit and class. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected boolean |
existsProperty(PropertyExpression pexp, boolean checkForReadOnly, ClassCodeVisitorSupport visitor)Resolves a property reference and records the owning type for later static compilation. |
|
protected MethodNode |
findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode args)Stores binary-expression target metadata alongside the resolved method. |
|
protected ClassNode[] |
getTypeCheckingAnnotations()Returns the annotations that trigger static type checking in this visitor. |
|
public static boolean |
isStaticallyCompiled(AnnotatedNode node)Indicates whether the supplied node is marked for static compilation. |
|
public void |
visitClass(ClassNode node)Visits a class and attaches the metadata required by the static compiler. |
|
public void |
visitConstructor(ConstructorNode node)Visits a constructor and records static-compilation metadata for it. |
|
public void |
visitConstructorCallExpression(ConstructorCallExpression call)Resolves and stores the direct target for a statically compiled constructor call. |
|
public void |
visitForLoop(ForStatement statement)Finalizes inferred loop-variable types for statically compiled for loops. |
|
public void |
visitLambdaExpression(LambdaExpression expression)Removes post-type-checking lambda rewrites that are incompatible with static compilation. |
|
public void |
visitMethod(MethodNode node)Visits a method and records static-compilation metadata for it. |
|
public void |
visitMethodCallExpression(MethodCallExpression call)Resolves and stores the direct target for a statically compiled method call. |
|
public void |
visitPropertyExpression(PropertyExpression expression)Marks receivers for property expressions that still require dynamic resolution. |
ArrayList.add method node.
No-arg ArrayList constructor node.
Class node for CompileStatic.
Class node for TypeChecked.
Creates a static compilation visitor for the supplied source unit and class.
unit - the source unit being processednode - the class node to visitResolves a property reference and records the owning type for later static compilation.
pexp - the property expression being resolvedcheckForReadOnly - whether read-only properties should be consideredvisitor - an optional callback for the matched membertrue if a matching property-like member existsStores binary-expression target metadata alongside the resolved method.
expr - the expression being resolvedreceiver - the candidate receiver typename - the method nameargs - the argument typesnull if resolution failsReturns the annotations that trigger static type checking in this visitor.
Indicates whether the supplied node is marked for static compilation.
node - the class or method node to inspecttrue if the node is statically compiledVisits a class and attaches the metadata required by the static compiler.
node - the class node to processVisits a constructor and records static-compilation metadata for it.
node - the constructor to processResolves and stores the direct target for a statically compiled constructor call.
call - the constructor call expression to inspect Finalizes inferred loop-variable types for statically compiled for loops.
statement - the loop statement to processRemoves post-type-checking lambda rewrites that are incompatible with static compilation.
expression - the lambda expression to processVisits a method and records static-compilation metadata for it.
node - the method to processResolves and stores the direct target for a statically compiled method call.
call - the method call expression to inspectMarks receivers for property expressions that still require dynamic resolution.
expression - the property expression to processCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.