@@ -48,48 +48,62 @@ abstract class TypeResolver {
4848 Future <StaticType > resolve (TypeAnnotationCode type);
4949}
5050
51- /// The api used to introspect on a [ClassDeclaration] .
51+ /// The api used to introspect on any [TypeDeclaration] which also has the
52+ /// marker interface [IntrospectableType] .
5253///
53- /// Available in the declaration and definition phases, but limited in the
54- /// declaration phase to immediately annotated [ClassDeclaration] s. This is
55- /// done by limiting the access to the [TypeDeclarationResolver] to the
56- /// definition phase.
57- abstract class ClassIntrospector {
58- /// The fields available for [clazz] .
54+ /// Available in the declaration and definition phases.
55+ abstract class TypeIntrospector {
56+ /// The fields available for [type] .
5957 ///
60- /// This may be incomplete if in the declaration phase and additional macros
61- /// are going to run on this class .
62- Future <List <FieldDeclaration >> fieldsOf (covariant ClassDeclaration clazz );
58+ /// This may be incomplete if additional declaration macros are going to run
59+ /// on [type] .
60+ Future <List <FieldDeclaration >> fieldsOf (covariant IntrospectableType type );
6361
64- /// The methods available so far for the current class .
62+ /// The methods available for [type] .
6563 ///
66- /// This may be incomplete if additional declaration macros are running on
67- /// this class .
68- Future <List <MethodDeclaration >> methodsOf (covariant ClassDeclaration clazz );
64+ /// This may be incomplete if additional declaration macros are going to run
65+ /// on [type] .
66+ Future <List <MethodDeclaration >> methodsOf (covariant IntrospectableType type );
6967
70- /// The constructors available so far for the current class .
68+ /// The constructors available for [type] .
7169 ///
72- /// This may be incomplete if additional declaration macros are running on
73- /// this class .
70+ /// This may be incomplete if additional declaration macros are going to run
71+ /// on [type] .
7472 Future <List <ConstructorDeclaration >> constructorsOf (
75- covariant ClassDeclaration clazz);
76-
77- /// The class that is directly extended via an `extends` clause.
78- Future <ClassDeclaration ?> superclassOf (covariant ClassDeclaration clazz);
79-
80- /// All of the classes that are mixed in with `with` clauses.
81- Future <List <ClassDeclaration >> mixinsOf (covariant ClassDeclaration clazz);
73+ covariant IntrospectableType type);
74+ }
8275
83- /// All of the classes that are implemented with an `implements` clause.
84- Future <List <ClassDeclaration >> interfacesOf (covariant ClassDeclaration clazz);
76+ /// The interface used by [Macro] s to resolve any [Identifier] s pointing to
77+ /// types to their type declarations.
78+ ///
79+ /// Only available in the declaration and definition phases of macro expansion.
80+ abstract class TypeDeclarationResolver {
81+ /// Resolves an [identifier] to its [TypeDeclaration] .
82+ ///
83+ /// If [identifier] does not resolve to a [TypeDeclaration] , then an
84+ /// [ArgumentError] is thrown.
85+ ///
86+ /// In the declaration phase, this will return [IntrospectableType] instances
87+ /// only for those types that are introspectable. Specifically, types are only
88+ /// introspectable of the macro is running on a class declaration, and the
89+ /// type appears in the type hierarchy of that class.
90+ ///
91+ /// In the definition phase, this will return [IntrospectableType] instances
92+ /// for all type definitions which can have members (ie: not type aliases).
93+ Future <TypeDeclaration > declarationOf (covariant Identifier identifier);
8594}
8695
8796/// The api used by [Macro] s to contribute new (non-type)
8897/// declarations to the current library.
8998///
9099/// Can also be used to do subtype checks on types.
91100abstract class DeclarationBuilder
92- implements Builder , IdentifierResolver , TypeResolver , ClassIntrospector {
101+ implements
102+ Builder ,
103+ IdentifierResolver ,
104+ TypeIntrospector ,
105+ TypeDeclarationResolver ,
106+ TypeResolver {
93107 /// Adds a new regular declaration to the surrounding library.
94108 ///
95109 /// Note that type declarations are not supported.
@@ -102,18 +116,6 @@ abstract class ClassMemberDeclarationBuilder implements DeclarationBuilder {
102116 void declareInClass (DeclarationCode declaration);
103117}
104118
105- /// The interface used by [Macro] s to resolve any [Identifier] s pointing to
106- /// types to their type declarations.
107- ///
108- /// Only available in the definition phase of macro expansion.
109- abstract class TypeDeclarationResolver {
110- /// Resolves an [identifier] to its [TypeDeclaration] .
111- ///
112- /// If [identifier] does resolve to a [TypeDeclaration] , then an
113- /// [ArgumentError] is thrown.
114- Future <TypeDeclaration > declarationOf (covariant Identifier identifier);
115- }
116-
117119/// The interface used by [Macro] s to get the inferred type for an
118120/// [OmittedTypeAnnotation] .
119121///
@@ -133,10 +135,10 @@ abstract class DefinitionBuilder
133135 implements
134136 Builder ,
135137 IdentifierResolver ,
136- TypeResolver ,
137- ClassIntrospector ,
138+ TypeIntrospector ,
138139 TypeDeclarationResolver ,
139- TypeInferrer {}
140+ TypeInferrer ,
141+ TypeResolver {}
140142
141143/// The apis used by [Macro] s that run on classes, to fill in the definitions
142144/// of any external declarations within that class.
0 commit comments