Introspection<T extends Object> class final

Everything the generator knows about an introspected class: its properties, methods, constructor and annotations, with closures to use them.

It replaces reflection: BeanWrapper, data binding, validation, SpEL and ObjectMapper read and create objects through it. The generator writes one per @Introspected class (and per class the build finds in use, see IntrospectionPart) and the module registers it in an Introspector; you write one by hand only for a class the generator cannot see. It describes a class, not a bean: the container's beans are BeanDefinitions. Micronaut's BeanIntrospection is the same idea.

// A hand-written introspection of Address, then used by name.
final addressIntrospection = Introspection<Address>(
  properties: [
    IntrospectedProperty<Address>(
      'city',
      type: String,
      get: (address) => address.city,
      set: (address, value) => address.city = value! as String,
    ),
  ],
  instantiate: Address.new,
);

final address = addressIntrospection.instantiate();
addressIntrospection.getProperty('city')!.setValue(address, 'Lyon');

Spring (Java): no direct counterpart. Spring uses runtime reflection (BeanUtils, java.beans.BeanInfo, PropertyDescriptor):

BeanInfo info = Introspector.getBeanInfo(Address.class);
Address address = BeanUtils.instantiateClass(Address.class);

Constructors

Introspection({List<IntrospectedProperty<T>> properties = const [], List<IntrospectedMethod<T>> methods = const [], List<Object> annotations = const [], Set<IntrospectionPart> parts = const {IntrospectionPart.read, IntrospectionPart.write, IntrospectionPart.methods}, T instantiate()?, IntrospectedConstructor<T>? constructor, T fromJson(Object? json)?, Object? toJson(T object)?, String? className, Introspection<Object> specialize(List<TypeInfo<Object?>> arguments)?, ObjectMethods<T>? objectMethods})
The description of T. instantiate calls the no-argument constructor, if there is one; the other closures are written by the generator. parts lists what the description holds (the generator leaves out what the build saw nothing use); a hand-written one holds everything.
const

Properties

annotations → List<Object>
The const annotations on the class.
final
className → String
The simple name of the class, without type arguments (written by the generator, so it survives minification; e.g. the default JSON type id).
no setter
classType → ClassType<T>
The TypeInfo of the class, to read a JSON tree as one when only this description is at hand (a value kept on disk by the name of its type).
no setter
constructor → IntrospectedConstructor<T>?
The constructor to create instances from data (ObjectMapper), when the class has a usable one.
final
hasFromJson → bool
Whether the class has its own fromJson constructor (e.g. from json_serializable or freezed), which ObjectMapper then uses.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasToJson → bool
Whether the class has its own toJson() method.
no setter
isGeneric → bool
Whether this describes a generic class with its type parameters erased (Page<Object?> for Page<T>) that can be specialized.
no setter
isInstantiable → bool
Whether instantiate is available (a no-argument constructor).
no setter
methods → Iterable<IntrospectedMethod<T>>
All public instance methods, in declaration order.
no setter
objectMethods → ObjectMethods<T>?
The ==, hashCode and toString() the generator wrote for the class's @EqualsAndHashCode and @ToString, which IntrospectedObject calls; null without those annotations.
final
parts → Set<IntrospectionPart>
What this description holds of the class; the generator leaves out the parts it saw nothing use (see IntrospectionPart).
final
properties → Iterable<IntrospectedProperty<T>>
All properties, in declaration order.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
type → Type
The introspected class.
no setter

Methods

describes<S>() → bool
Whether S is T or T?.
describesPart(IntrospectionPart part) → bool
Whether this description holds part.
fromJson(Object? json) → T
Calls the class's own fromJson with json.
getMethod(String name) → IntrospectedMethod<T>?
The method named name, or null (Dart has no overloads).
getProperty(String name) → IntrospectedProperty<T>?
The property named name, or null.
instantiate() → T
Creates a new instance with the no-argument constructor; throws StateError when isInstantiable is false, an IntrospectionPartError when the description has no IntrospectionPart.write.
isInstance(Object? value) → bool
Whether value is a T (or a subtype).
isRawTypeOf<S>() → bool
Whether S is a parameterization of the class this describes (Page<Book> for Page<Object?>).
isSubtypeOf(Introspection<Object> other) → bool
Whether T is a subtype of the class other describes.
listOf(Iterable<Object?> items) → List<T>
items, each a T, as a List<T>.
mapOf(Map<String, Object?> entries) → Map<String, T>
entries, each value a T, as a Map<String, T>.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
requirePart(IntrospectionPart part, String use) → void
Throws an IntrospectionPartError unless this description holds part; use says what needs it (it is written out as JSON).
setOf(Iterable<Object?> items) → Set<T>
items, each a T, as a Set<T>.
specialize(List<TypeInfo<Object?>> arguments) → Introspection<Object>
The introspection of this generic class with the type arguments (Page<Book> for [ClassType<Book>()]): constructor parameters and properties typed with them. Throws StateError when not isGeneric.
toJson(Object object) → Object?
Calls the class's own toJson() on object.
toString() → String
A string representation of this object.
override

Operators

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