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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart

Issue 2899343004: Support reflectClass on parameterized classes (Closed)
Patch Set: Cleanup Created 3 years, 7 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 | « pkg/dev_compiler/test/browser/language_tests.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
index cb46e8892fe93206a8c4039082df70af341ce65c..cdfe24bd071d97d84e16c80928dad28c1d5a440b 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
@@ -311,12 +311,22 @@ class JsClosureMirror extends JsInstanceMirror implements ClosureMirror {
}
}
+// For generic classes, mirrors uses the same representation, [ClassMirror],
+// for the instantiated and uninstantiated type. Somewhat awkwardly, most APIs
+// (e.g., [newInstance]) treat the uninstantiated type as if instantiated
+// with all dynamic. The representation below is correspondingly a bit wonky.
+// For an uninstantiated generic class, [_cls] is the instantiated type (with
+// dynamic) and [_raw] is null. For an instantiated generic class, [_cls] is
+// the instantiated type (with the corresponding type parameters), and [_raw]
+// is the generic factory.
class JsClassMirror extends JsMirror implements ClassMirror {
final Type _cls;
final Symbol simpleName;
- // Generic class factory
+ // Generic class factory for instantiated types.
final dynamic _raw;
+ ClassMirror _originalDeclaration;
+
// TODO(vsm): Do this properly
ClassMirror _mixin = null;
List<TypeMirror> _typeArguments;
@@ -414,11 +424,11 @@ class JsClassMirror extends JsMirror implements ClassMirror {
return _declarations;
}
- JsClassMirror._(Type cls)
+ JsClassMirror._(Type cls, {bool instantiated: true})
: _cls = cls,
- _raw = _getGenericClass(_unwrap(cls)),
+ _raw = instantiated ? _getGenericClass(_unwrap(cls)) : null,
simpleName = new Symbol(JS('String', '#.name', _unwrap(cls))) {
- var typeArgs = _getGenericArgs(_unwrap(cls));
+ var typeArgs = _getGenericArgs(_unwrap(_cls));
if (typeArgs == null) {
_typeArguments = const [];
} else {
@@ -485,13 +495,15 @@ class JsClassMirror extends JsMirror implements ClassMirror {
List<TypeMirror> get typeArguments => _typeArguments;
TypeMirror get originalDeclaration {
- // TODO(vsm): Handle generic case. How should we represent an original
- // declaration for a generic class?
if (_raw == null) {
return this;
}
- throw new UnimplementedError(
- "ClassMirror.originalDeclaration unimplemented");
+ if (_originalDeclaration != null) {
+ return _originalDeclaration;
+ }
+ _originalDeclaration =
+ new JsClassMirror._(_wrap(JS('', '#()', _raw)), instantiated: false);
+ return _originalDeclaration;
}
ClassMirror get superclass {
« no previous file with comments | « pkg/dev_compiler/test/browser/language_tests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698