@@ -14,6 +14,20 @@ import 'utils.dart';
1414abstract  class  TypeChecker  {
1515  const  TypeChecker ._();
1616
17+   /// Creates a new [TypeChecker]  that delegates to other [checkers] . 
18+   /// 
19+   /// This implementation will return `true`  for type checks if _any_ of the 
20+   /// provided type checkers return true, which is useful for deprecating an 
21+   /// API: 
22+   /// ```dart 
23+   /// const $Foo = const TypeChecker.fromRuntime(Foo);  
24+   /// const $Bar = const TypeChecker.fromRuntime(Bar);  
25+   /// 
26+   /// // Used until $Foo is deleted. 
27+   /// const $FooOrBar = const TypeChecker.forAny(const [$Foo, $Bar]);  
28+   /// ``` 
29+ const  factory  TypeChecker .any (Iterable <TypeChecker > checkers) =  _AnyChecker ;
30+ 
1731  /// Create a new [TypeChecker]  backed by a runtime [type] . 
1832  /// 
1933  /// This implementation uses `dart:mirrors`  (runtime reflection). 
@@ -71,14 +85,13 @@ abstract class TypeChecker {
7185  /// Returns annotating constants on [element]  assignable to this type. 
7286Iterable <DartObject > annotationsOf (Element  element) =>  element.metadata
7387      .map (_checkedConstantValue)
74-       .where ((a) =>  isAssignableFromType (a.type));
88+       .where ((a) =>  a ? .type  !=   null   &&   isAssignableFromType (a.type));
7589
7690  /// Returns annotating constants on [element]  of exactly this type. 
7791Iterable <DartObject > annotationsOfExact (Element  element) =>  element.metadata
7892      .map (_checkedConstantValue)
79-       .where ((a) =>  a? .type !=  null  &&  isAssignableFromType (a.type));
93+       .where ((a) =>  a? .type !=  null  &&  isExactlyType (a.type));
8094
81-   /// Returns `true`  if the type of [element]  can be assigned to this type. 
8295  /// Returns `true`  if the type of [element]  can be assigned to this type. 
8396bool  isAssignableFrom (Element  element) => 
8497      isExactly (element) ||  _getAllSupertypes (element).any (isExactlyType);
@@ -210,3 +223,12 @@ class _UriTypeChecker extends TypeChecker {
210223  @override 
211224  String  toString () =>  '${uri }' ;
212225}
226+ 
227+ class  _AnyChecker  extends  TypeChecker  {
228+   final  Iterable <TypeChecker > _checkers;
229+ 
230+   const  _AnyChecker (this ._checkers) :  super ._();
231+ 
232+   @override 
233+   bool  isExactly (Element  element) =>  _checkers.any ((c) =>  c.isExactly (element));
234+ }
0 commit comments