MemberDeclaration class abstract
Abstract base class representing a member of a class that extends Executable.
This class provides a default implementation for executable elements that are not actually executable (i.e., they don't accept parameters or arguments). It's typically used as a base class for class members like fields, properties, or other non-method elements that need to implement the Executable interface but don't have executable semantics.
Key Characteristics
- Non-executable: All parameter-related methods return empty/false values
- No Arguments: Cannot accept any positional or named arguments
- No Parameters: Has no parameter definitions or metadata
- Marker Implementation: Serves as a marker for non-executable class members
Usage
Extend this class for class members that implement Executable but are not methods:
class Field extends Member {
final String name;
final Class type;
final dynamic value;
Field(this.name, this.type, [this.value]);
@override
String getName() => name;
@override
Class getReturnType() => type;
}
Property Implementation
class Property extends Member {
final String propertyName;
final Class propertyType;
final bool isReadOnly;
Property(this.propertyName, this.propertyType, {this.isReadOnly = false});
@override
String getName() => propertyName;
@override
Class getReturnType() => propertyType;
bool canWrite() => !isReadOnly;
}
Annotation Support
class AnnotatedMember extends Member {
final List<Annotation> annotations;
AnnotatedMember(this.annotations);
bool hasDirectAnnotation<T>() {
return annotations.any((a) => a is T);
}
T? getDirectAnnotation<T>() {
return annotations.whereType<T>().firstOrNull;
}
}
- Inheritance
-
- Object
- Declaration
- EntityDeclaration
- SourceDeclaration
- MemberDeclaration
- Implementers
Constructors
- MemberDeclaration()
-
Abstract base class representing a member of a class that extends Executable.
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
-
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.
override
-
getElement(
) → Element? -
The analyzer element associated with this declaration.
inherited
-
getIsAbstract(
) → bool -
Returns
true
if this member is declaredabstract
. -
getIsPublic(
) → bool -
Checks if this declaration is a public declaration.
inherited
-
getIsStatic(
) → bool -
Returns
true
if this member is markedstatic
. -
getIsSynthetic(
) → bool -
Checks if a declaration is a synthetic declaration.
inherited
-
getName(
) → String -
Gets the name of the declared element.
inherited
-
getParentClass(
) → LinkDeclaration? - Returns the LinkDeclaration that owns this member.
-
getParentLibrary(
) → LibraryDeclaration -
Returns the LibraryDeclaration in which this declaration is defined.
inherited
-
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
-
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.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited