TypeDeclarationExtension extension
Extension providing type casting and declaration resolution for TypeDeclaration.
Adds convenience methods for safely casting to specific declaration types and finding the most specific declaration type.
{@template type_declaration_extension_features}
Key Features
- Safe type casting methods
- Declaration type resolution
- Null-safe operations
- Covers all TypeDeclaration variants
Example Usage
TypeDeclaration decl = getSomeDeclaration();
// Safe casting
final classDecl = decl.asClass();
if (classDecl != null) {
print('Found class: ${classDecl.getName()}');
}
// Declaration resolution
final sourceDecl = decl.getDeclaration();
{@endtemplate}
Methods
-
asClass(
) → ClassDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Safely casts to ClassDeclaration if possible. -
asEnum(
) → EnumDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Safely casts to EnumDeclaration if possible. -
asMixin(
) → MixinDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Safely casts to MixinDeclaration if possible. -
asRecord(
) → RecordDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Safely casts to RecordDeclaration if possible. -
asTypedef(
) → TypedefDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Safely casts to TypedefDeclaration if possible. -
asTypeVariable(
) → TypeVariableDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Safely casts to TypeVariableDeclaration if possible. -
getDeclaration(
) → SourceDeclaration? -
Available on TypeDeclaration, provided by the TypeDeclarationExtension extension
Resolves the most specific declaration type.