MethodDeclaration class abstract

Represents a method declaration in a Dart class, extension, mixin, or top-level scope.

Provides full metadata about the method's return type, parameters, type parameters, and modifiers (static, abstract, getter, setter). Also allows invoking the method at runtime with named arguments.

Example

class Calculator {
  int add(int a, int b) => a + b;
}

final method = reflector.reflectMethod(Calculator, 'add');
print(method.getReturnType().getName()); // int

final result = method.invoke(Calculator(), {'a': 3, 'b': 4});
print(result); // 7

This class is also used for getters and setters:

class Example {
  String get title => 'Jet';
  set title(String value) {}
}

final getter = reflector.reflectMethod(Example, 'title');
print(getter.getIsGetter()); // true
Inheritance
Available extensions

Constructors

MethodDeclaration()
Represents a method declaration in a Dart class, extension, mixin, or top-level scope.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

canOverride(MethodDeclaration other) bool

Available on MethodDeclaration, provided by the MethodOverrideExtensions extension

Check if this method can override another method (considering covariance)
getAnnotations() List<AnnotationDeclaration>
Returns all annotations applied to this declaration.
inherited
getDartType() → DartType?
The analyzer DartType of the entity for enhanced type operations.
inherited
getDebugIdentifier() String
The debug identifier for the entity.
inherited
getElement() → Element?
The analyzer element associated with this declaration.
inherited
getIsAbstract() bool
Returns true if this member is declared abstract.
inherited
getIsConst() bool
Whether this method is a const.
getIsFactory() bool
Whether this method is a factory.
getIsGetter() bool
Whether this method is a getter.
getIsPublic() bool
Checks if this declaration is a public declaration.
inherited
getIsSetter() bool
Whether this method is a setter.
getIsStatic() bool
Returns true if this member is marked static.
inherited
getIsSynthetic() bool
Checks if a declaration is a synthetic declaration.
inherited
getName() String
Gets the name of the declared element.
inherited
getParameters() List<ParameterDeclaration>
Returns all parameters accepted by this method.
getParentClass() LinkDeclaration?
Returns the LinkDeclaration that owns this member.
inherited
getParentLibrary() LibraryDeclaration
Returns the LibraryDeclaration in which this declaration is defined.
inherited
getReturnType() LinkDeclaration
Returns the return type of the method.
getSourceLocation() Uri?
Returns the source code location (e.g., file path or URI) where this declaration is defined, or null if not available in the current reflection context.
inherited
getType() Type
Gets the runtime type of the declared element.
inherited
hasAnalyzerSupport() bool
Returns true if this declaration has analyzer information available.
inherited
hasSameSignature(MethodDeclaration other) bool

Available on MethodDeclaration, provided by the MethodOverrideExtensions extension

Check if this method has the same signature as another method
invoke(dynamic instance, Map<String, dynamic> arguments) → dynamic
Invokes this method on the given instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object>
Returns a JSON representation of this entity.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited