Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Unified Diff: runtime/lib/mirrors_impl.dart

Issue 126823004: Add TypeMirror.isSubtypeOf, TypeMirror.isAssignableTo, ClassMirror.isSubclassOf (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: mark source mirrors as failing Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors_impl.dart
diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart
index 1605991fd907088b6fea91c24e025309a729af44..f527df78f99fbf22317d7b165d9282c6bec723f3 100644
--- a/runtime/lib/mirrors_impl.dart
+++ b/runtime/lib/mirrors_impl.dart
@@ -109,6 +109,12 @@ String _makeSignatureString(TypeMirror returnType,
List _metadata(reflectee)
native 'DeclarationMirror_metadata';
+bool _subtypeTest(Type a, Type b)
+ native 'TypeMirror_subtypeTest';
+
+bool _moreSpecificTest(Type a, Type b)
+ native 'TypeMirror_moreSpecificTest';
+
class _LocalMirrorSystem extends MirrorSystem {
final Map<Uri, LibraryMirror> libraries;
final IsolateMirror isolate;
@@ -851,6 +857,31 @@ class _LocalClassMirror extends _LocalObjectMirror
int get hashCode => simpleName.hashCode;
+ bool isSubtypeOf(TypeMirror other) {
+ if (other == currentMirrorSystem().dynamicType) return true;
+ if (other == currentMirrorSystem().voidType) return false;
+ return _subtypeTest(_reflectedType, other._reflectedType);
+ }
+
+ bool isAssignableTo(TypeMirror other) {
+ if (other == currentMirrorSystem().dynamicType) return true;
+ if (other == currentMirrorSystem().voidType) return false;
+ return _moreSpecificTest(_reflectedType, other._reflectedType)
+ || _moreSpecificTest(other._reflectedType, _reflectedType);
+ }
+
+ bool isSubclassOf(ClassMirror other) {
+ if (other is! ClassMirror) throw new ArgumentError(other);
+ ClassMirror otherDeclaration = other.originalDeclaration;
+ ClassMirror c = this;
+ while (c != null) {
+ c = c.originalDeclaration;
+ if (c == otherDeclaration) return true;
+ c = c.superclass;
+ }
+ return false;
+ }
+
static _library(reflectee)
native "ClassMirror_library";
@@ -1023,7 +1054,8 @@ class _LocalTypeVariableMirror extends _LocalDeclarationMirror
}
bool get hasReflectedType => false;
- Type get reflectedType => throw new UnsupportedError() ;
+ Type get reflectedType => throw new UnsupportedError();
+ Type get _reflectedType => _reflectee;
List<TypeVariableMirror> get typeVariables => emptyList;
List<TypeMirror> get typeArguments => emptyList;
@@ -1040,6 +1072,19 @@ class _LocalTypeVariableMirror extends _LocalDeclarationMirror
}
int get hashCode => simpleName.hashCode;
+ bool isSubtypeOf(TypeMirror other) {
+ if (other == currentMirrorSystem().dynamicType) return true;
+ if (other == currentMirrorSystem().voidType) return false;
+ return _subtypeTest(_reflectedType, other._reflectedType);
+ }
+
+ bool isAssignableTo(TypeMirror other) {
+ if (other == currentMirrorSystem().dynamicType) return true;
+ if (other == currentMirrorSystem().voidType) return false;
+ return _moreSpecificTest(_reflectedType, other._reflectedType)
+ || _moreSpecificTest(other._reflectedType, _reflectedType);
+ }
+
static DeclarationMirror _TypeVariableMirror_owner(reflectee)
native "TypeVariableMirror_owner";
@@ -1127,6 +1172,19 @@ class _LocalTypedefMirror extends _LocalDeclarationMirror
String toString() => "TypedefMirror on '${_n(simpleName)}'";
+ bool isSubtypeOf(TypeMirror other) {
+ if (other == currentMirrorSystem().dynamicType) return true;
+ if (other == currentMirrorSystem().voidType) return false;
+ return _subtypeTest(_reflectedType, other._reflectedType);
+ }
+
+ bool isAssignableTo(TypeMirror other) {
+ if (other == currentMirrorSystem().dynamicType) return true;
+ if (other == currentMirrorSystem().voidType) return false;
+ return _moreSpecificTest(_reflectedType, other._reflectedType)
+ || _moreSpecificTest(other._reflectedType, _reflectedType);
+ }
+
static _nativeReferent(reflectedType)
native "TypedefMirror_referent";
@@ -1531,6 +1589,14 @@ class _SpecialTypeMirror extends _LocalMirror
int get hashCode => simpleName.hashCode;
String toString() => "TypeMirror on '${_n(simpleName)}'";
+
+ bool isSubtypeOf(TypeMirror other) {
+ return simpleName == #dynamic || other is _SpecialTypeMirror;
+ }
+
+ bool isAssignableTo(TypeMirror other) {
+ return simpleName == #dynamic || other is _SpecialTypeMirror;
+ }
}
class _Mirrors {
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698