public class MethodNode
extends AnnotatedNode
Represents a method declaration.
| Constructor and description |
|---|
protected MethodNode() |
MethodNode(String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)Creates a method node representing a method or constructor declaration. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public Statement |
getCode()Returns the method body as a Statement. |
|
public ClassNode[] |
getExceptions()Returns the list of checked exceptions declared in the method's throws clause. |
|
public Statement |
getFirstStatement()Returns the first statement in this method's code block. |
|
public GenericsType[] |
getGenericsTypes()Returns the generic type parameters for this method. |
|
public int |
getModifiers()Returns the ASM modifier flags for this method. |
|
public String |
getName()Returns the method name. |
|
public Parameter[] |
getParameters()Returns the parameter list for this method. |
|
public ClassNode |
getReturnType()Returns the method's return type as a ClassNode. |
|
public String |
getText() |
|
public String |
getTypeDescriptor()The type descriptor for a method node is a string containing the name of the method, its return type, and its parameter types in a canonical form. |
|
public String |
getTypeDescriptor(boolean pretty)
|
|
public VariableScope |
getVariableScope()Returns the variable scope for this method. |
|
public boolean |
hasAnnotationDefault()
|
|
public boolean |
hasDefaultValue()Checks whether any parameter of this method has a default value. |
|
public boolean |
isAbstract()Checks whether this method is declared as abstract. |
|
public boolean |
isConstructor()Checks whether this method is a constructor (<init>). |
|
public boolean |
isDefault()Checks whether this method is a default method. |
|
public boolean |
isDynamicReturnType()Checks whether this method has a dynamically typed return type. |
|
public boolean |
isFinal()Checks whether this method is declared as final. |
|
public boolean |
isPackageScope()Checks whether this method has package scope (no explicit visibility modifier). |
|
public boolean |
isPrivate()Checks whether this method is declared as private. |
|
public boolean |
isProtected()Checks whether this method is declared as protected. |
|
public boolean |
isPublic()Checks whether this method is declared as public. |
|
public boolean |
isScriptBody()Checks whether this method is the run method from a script execution. |
|
public boolean |
isStatic()Checks whether this method is declared as static. |
|
public boolean |
isStaticConstructor()Checks whether this method is a static initializer (<clinit>). |
|
public boolean |
isSyntheticPublic()Checks whether this method was synthesized as public by Groovy's default visibility rule. |
|
public boolean |
isVoidMethod()Checks whether this method returns void. |
|
public void |
setAnnotationDefault(boolean hasDefaultValue)Sets the annotation default flag for this method. |
|
public void |
setCode(Statement code)Sets the method body statement. |
|
public void |
setGenericsTypes(GenericsType[] genericsTypes)Sets the generic type parameters for this method. |
|
public void |
setIsScriptBody()Sets the flag for this method to indicate it is a script body implementation. |
|
public void |
setModifiers(int modifiers)Sets the ASM modifier flags for this method. |
|
public void |
setParameters(Parameter[] parameters)Sets the method's parameter list. |
|
public void |
setReturnType(ClassNode returnType)Sets the method's return type. |
|
public void |
setSyntheticPublic(boolean syntheticPublic)Marks this method as having synthetic public visibility. |
|
public void |
setVariableScope(VariableScope variableScope)Sets the variable scope for this method. |
|
public String |
toString() |
| Methods inherited from class | Name |
|---|---|
class AnnotatedNode |
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Creates a method node representing a method or constructor declaration. The parameters array defines the method signature and may include default values. The exceptions array lists checked exceptions declared in the method's throws clause.
name - the method name (use "<init>" for constructors, "<clinit>" for static initializers)modifiers - ASM modifier flags (public, static, abstract, final, etc.)returnType - the return type as a ClassNodeparameters - the method parameters as an array of Parameterexceptions - the checked exception types thrown by this methodcode - the method body as a Statement (typically a BlockStatement)Returns the method body as a Statement. Typically a BlockStatement containing the method's instructions. Returns null for abstract methods or interface methods with no implementation.
Returns the list of checked exceptions declared in the method's throws clause.
Returns the first statement in this method's code block. Recursively unwraps nested BlockStatements to find the first actual statement. Returns null if the code is null or consists only of empty blocks.
Returns the generic type parameters for this method. Used for generic method declarations (e.g., <T> T getValue()).
Returns the ASM modifier flags for this method. Flags include visibility (public/protected/private), static, abstract, final, synchronized, etc.
Returns the method name. Special names: "<init>" for constructors, "<clinit>" for static initializers.
Returns the parameter list for this method. Each Parameter may have an initial value expression for default parameters.
Returns the method's return type as a ClassNode.
The type descriptor for a method node is a string containing the name of the method, its return type, and its parameter types in a canonical form. For simplicity, we use the format of a Java declaration without parameter names or generics.
Returns the variable scope for this method. The scope tracks declared variables and parameters.
true if annotation method has a default valueChecks whether any parameter of this method has a default value. A default value is an initializer expression for a parameter.
Checks whether this method is declared as abstract. Abstract methods have no implementation and must be overridden in subclasses.
Checks whether this method is a constructor (<init>).
Checks whether this method is a default method. Default methods are public methods in interfaces with no abstract modifier.
Checks whether this method has a dynamically typed return type. Dynamic typing occurs when the exact return type cannot be determined at compile time.
Checks whether this method is declared as final. Final methods cannot be overridden.
Checks whether this method has package scope (no explicit visibility modifier).
Checks whether this method is declared as private.
Checks whether this method is declared as protected.
Checks whether this method is declared as public.
Checks whether this method is the run method from a script execution. Scripts have their module-level statements compiled into a synthetic run() method.
Checks whether this method is declared as static.
Checks whether this method is a static initializer (<clinit>).
Checks whether this method was synthesized as public by Groovy's default visibility rule. Groovy makes methods public by default, even if no public modifier was explicitly written. This flag tracks whether the public modifier was synthetic versus explicit. This information is primarily of interest to AST transform writers.
Checks whether this method returns void.
Sets the annotation default flag for this method. Used when this method is part of an annotation interface.
hasDefaultValue - true if this annotation method has a default valueSets the method body statement. Typically a BlockStatement. Setting null indicates an abstract method.
code - the statement representing the method bodySets the generic type parameters for this method. Invalidates cached data like the type descriptor.
genericsTypes - array of GenericsType for this methodSets the flag for this method to indicate it is a script body implementation.
Sets the ASM modifier flags for this method. Invalidates cached data (like type descriptor) when modifiers change. Updates the variable scope's static context to match the new modifiers.
modifiers - ASM opcode flags to setSets the method's parameter list. Updates variable scope to register all parameters and detects default values. Invalidates cached data like the type descriptor.
parameters - array of Parameter objectsSets the method's return type. If the type is null, defaults to ClassHelper.OBJECT_TYPE. Marks the method as having dynamic return type if appropriate.
returnType - the return ClassNodeMarks this method as having synthetic public visibility.
syntheticPublic - true to mark as synthetically publicSets the variable scope for this method. The scope is updated to match the method's static context.
variableScope - the VariableScope to setCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.