Skip to content

Commit

Permalink
Merge branch 'master' into checker-any
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey authored Jul 6, 2017
2 parents fe9d9e3 + 0593ca3 commit 6e15942
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* `TypeChecker#annotations...`-methods now throw a `StateError` if one or more
annotations on an element are not resolvable. This is usually a sign of a
mispelling, missing import, or missing dependency.

* Added `TypeChecker.any`, which delegates to multiple other `TypeChecker`
implementations when making a type check.

Expand Down
10 changes: 10 additions & 0 deletions lib/src/type_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ abstract class TypeChecker {
.map(_checkedConstantValue)
.where((a) => a?.type != null && isExactlyType(a.type));

/// Returns annotating constants on [element] assignable to this type.
Iterable<DartObject> annotationsOf(Element element) => element.metadata
.map((a) => a.computeConstantValue())
.where((a) => isAssignableFromType(a.type));

/// Returns annotating constants on [element] of exactly this type.
Iterable<DartObject> annotationsOfExact(Element element) => element.metadata
.map((a) => a.computeConstantValue())
.where((a) => isExactlyType(a.type));

/// Returns `true` if the type of [element] can be assigned to this type.
bool isAssignableFrom(Element element) =>
isExactly(element) || _getAllSupertypes(element).any(isExactlyType);
Expand Down

0 comments on commit 6e15942

Please sign in to comment.