public abstract class MethodInvocationTrap
extends CodeVisitorSupport
Abstract base class for AST visitors that trap and intercept specific method invocations. Primarily used to detect AstBuilder "from code" invocations and convert them to the equivalent "from string" approach during compilation.
Subclasses implement isBuildInvocation() to identify target method calls and
handleTargetMethodCallExpression() to transform them. The base class provides utility methods
for error reporting and closure-to-source conversion.
| Modifiers | Name | Description |
|---|---|---|
protected ReaderSource |
source |
The source reader for extracting closure source code. |
protected SourceUnit |
sourceUnit |
The source unit for reporting errors and accessing compilation context. |
| Constructor and description |
|---|
MethodInvocationTrap(ReaderSource source, SourceUnit sourceUnit)Creates a method invocation trap with the given source and source unit. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
addError(String msg, ASTNode expr)Reports an error back to the source unit with line and column information. |
|
protected String |
convertClosureToSource(ClosureExpression expression)Converts a closure expression into its source code equivalent using the source reader. |
|
protected abstract boolean |
handleTargetMethodCallExpression(MethodCallExpression call)Handles a target method call expression by transforming or validating it. |
|
protected abstract boolean |
isBuildInvocation(MethodCallExpression call)Determines whether a method call expression is a target invocation for special handling. |
|
public void |
visitMethodCallExpression(MethodCallExpression call)Visits a method call expression, checking if it is a target build invocation. |
The source reader for extracting closure source code.
The source unit for reporting errors and accessing compilation context.
Creates a method invocation trap with the given source and source unit.
Both arguments are required; null values will raise IllegalArgumentException.
nullsource - the ReaderSource for extracting source code from closures, cannot be nullsourceUnit - the SourceUnit for error reporting, cannot be nullReports an error back to the source unit with line and column information. The error is collected and processing continues.
msg - the error messageexpr - the expression that caused the error Converts a closure expression into its source code equivalent using the source reader.
If an error occurs during conversion, adds an error to the source unit and returns null.
expression - the closure expression to convertnull if conversion failsHandles a target method call expression by transforming or validating it. Subclasses override to implement the transformation logic.
call - the target method call expressiontrue to continue tree walking, false to stopDetermines whether a method call expression is a target invocation for special handling. Subclasses override to identify invocations matching their specific criteria.
call - the method call expression to checktrue if this call is a target invocation requiring special handling Visits a method call expression, checking if it is a target build invocation.
If identified as a target invocation, calls handleTargetMethodCallExpression().
If that method returns true, resumes normal tree walking; otherwise stops.
For non-target method calls, continues normal tree walking regardless.
call - the method call expression that may or may not be an AstBuilder 'from code' invocationCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.