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

Unified Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart

Issue 126823004: Add TypeMirror.isSubtypeOf, TypeMirror.isAssignableTo, ClassMirror.isSubclassOf (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: +source mirrors 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
Index: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart
diff --git a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart
index 8a5a41e33ceb4d163611228ce46590b3b8069f09..3652f00397dfb09474694e907ebc976321cd9e55 100644
--- a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart
+++ b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart
@@ -54,6 +54,14 @@ abstract class Dart2JsTypeMirror
bool get isDynamic => false;
+ bool isSubtypeOf(TypeMirror other) {
+ return mirrorSystem.compiler.types.isSubtype(this._type, other._type);
+ }
+
+ bool isAssignableTo(TypeMirror other) {
+ return mirrorSystem.compiler.types.isAssignable(this._type, other._type);
+ }
+
String toString() => _type.toString();
}
@@ -226,6 +234,18 @@ class Dart2JsClassDeclarationMirror
InterfaceType type)
: super(system, type);
+ 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;
+ }
+
String toString() => 'Mirror on class ${_type.name}';
}

Powered by Google App Engine
This is Rietveld 408576698