ClassUtils class final
A utility class that provides static methods for working with class hierarchies and type relationships in Dart's reflection system.
This class offers functionality to traverse and analyze class inheritance structures, including superclasses, interfaces, and special handling for arrays and enums.
Usage
// Get the complete class hierarchy for a type
final hierarchy = ClassUtils.getClassHierarchy(Class<String>());
// The hierarchy will include:
// - The original class (String)
// - All superclasses up to Object
// - All implemented interfaces
// - Special handling for arrays and enums
print('Class hierarchy for String:');
for (final clazz in hierarchy) {
print(' ${clazz.getName()}');
}
Features
- Complete hierarchy traversal: Walks up the entire inheritance chain
- Interface inclusion: Includes all implemented interfaces at each level
- Array support: Special handling for array component types
- Enum support: Proper enum hierarchy with Enum base class
- Duplicate prevention: Ensures no duplicate classes in the hierarchy
- Ordered results: Returns hierarchy in a logical traversal order
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
findMethodCandidatesByName(
Class clazz, String methodName) → Set< Method> - Retrieves the set of methods with the specified name from the given class.
-
getClassHierarchy(
Class type) → Iterable< Class> - Retrieves the complete class hierarchy for the specified type, including all superclasses, interfaces, and special type relationships.
-
getMethodIfAvailable(
Class clazz, String methodName, [List< Class> ? paramTypes]) → Method? - Retrieves the method with the specified name and parameter types from the given class.
-
getMethodOrNull(
Class clazz, String methodName, List< Class> paramTypes) → Method? - Retrieves the method with the specified name and parameter types from the given class.
-
getPackage(
Object object) → Package? -
Returns the Jetleaf package associated with the given
object. -
getPackageName(
Object object) → String -
Returns the qualified package name of the given
object. -
getProxiedClass(
Class proxyClass, [Object? instance]) → Class - Retrieves the original (non-proxied) Class representation for a given proxy type or instance within the Jetleaf runtime.
-
getQualifiedName(
Object object) → String -
Returns the fully qualified Jetleaf name of the given
object. -
getStaticMethod(
Class target, String methodName) → Method? - Retrieves the static method with the specified name from the given class.
-
isAssignable(
Class left, Class right) → bool - Check if the right-hand side type may be assigned to the left-hand side type.
-
isAssignableToError(
Object object) → bool -
Determines whether the given
objectrepresents or is assignable to a Dart error type within the Jetleaf runtime type system. -
isAsync(
Object object) → bool -
Determines whether the given
objectrepresents or is assignable to a Dart Future or FutureOr type within Jetleaf’s reflective runtime. -
isClass(
String name) → bool -
Checks whether a class with the given
nameexists and can be loaded. -
isProxyClass(
Class type) → bool -
Checks whether the given
typerepresents a generated proxy class. -
isVoid(
dynamic object) → bool -
Checks whether the given
objectis of typevoid. -
loadClass(
Object object) → Class? -
Attempts to resolve and load a
`Class`instance from a givenobject.
Constants
- CLASS_HIERARCHY_GARBAGE_KEY → const String
- Garbage collector key for class hierarchy cache.
- COMMON_CLASS_CACHE_GARBAGE_KEY → const String
- Garbage collector key for common class cache.
- PRIMITIVE_GARBAGE_KEY → const String
- Garbage collector key for primitive type to wrapper type cache.
- PRIMITIVE_TYPE_NAME_GARBAGE_KEY → const String
- Garbage collector key for primitive type to name cache.
- PRIMITIVE_TYPE_TO_WRAPPER_GARBAGE_KEY → const String
- Garbage collector key for primitive type to wrapper cache.