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

Unified Diff: reflectable/lib/src/reflectable_mirror_based.dart

Issue 1473073009: Added `dynamicReflected..Type`, corrected type expressions. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Review response. Created 5 years, 1 month 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 | « reflectable/lib/mirrors.dart ('k') | reflectable/lib/src/reflectable_transformer_based.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: reflectable/lib/src/reflectable_mirror_based.dart
diff --git a/reflectable/lib/src/reflectable_mirror_based.dart b/reflectable/lib/src/reflectable_mirror_based.dart
index 4dd71205bec182bcec79e5d5e14dec63b91d3863..100f821c376ffcbbdc0ccdc6368e63300c1cc4f7 100644
--- a/reflectable/lib/src/reflectable_mirror_based.dart
+++ b/reflectable/lib/src/reflectable_mirror_based.dart
@@ -798,6 +798,24 @@ class ClassMirrorImpl extends _TypeMirrorImpl
: super(classMirror, reflectable) {}
@override
+ bool get hasDynamicReflectedType => _classMirror.typeVariables.isEmpty;
+
+ @override
+ Type get dynamicReflectedType {
+ if (!hasDynamicReflectedType) {
+ /// We cannot hope to implement this based on 'dart:mirrors' for generic
+ /// classes, because there is no support for obtaining one instantiation
+ /// of a generic class based on a different one (we cannot obtain
+ /// `List<dynamic>` from `List<int>` or any such thing); and when
+ /// `isOriginalDeclaration` is true we do not have a `reflectedType` at
+ /// all.
+ throw new UnsupportedError(
+ "Attempt to get dynamicReflectedType on $_classMirror");
+ }
+ return reflectedType;
+ }
+
+ @override
List<rm.TypeVariableMirror> get typeVariables {
if (!reflectableSupportsDeclarations(_reflectable)) {
throw new NoSuchCapabilityError(
@@ -1056,6 +1074,13 @@ class _FunctionTypeMirrorImpl extends ClassMirrorImpl
: super(functionTypeMirror, reflectable);
@override
+ bool get hasDynamicReflectedType => false;
+
+ @override
+ Type get dynamicReflectedType => throw unimplementedError(
+ "Attempt to get dynamicReflectedType on a function type mirror");
+
+ @override
rm.MethodMirror get callMethod {
return new MethodMirrorImpl(_functionTypeMirror.callMethod, _reflectable);
}
@@ -1160,6 +1185,34 @@ class MethodMirrorImpl extends _DeclarationMirrorImpl
}
@override
+ bool get hasDynamicReflectedReturnType {
+ if (impliesReflectedType(_reflectable.capabilities)) {
+ return _methodMirror.returnType.typeVariables.isEmpty &&
+ _methodMirror.returnType.hasReflectedType;
+ }
+ throw new NoSuchCapabilityError("Attempt to get "
+ "hasDynamicReflectedReturnType without `reflectedTypeCapability`");
+ }
+
+ @override
+ Type get dynamicReflectedReturnType {
+ if (impliesReflectedType(_reflectable.capabilities)) {
+ if (_methodMirror.returnType.typeVariables.isEmpty) {
+ return _methodMirror.returnType.reflectedType;
+ } else {
+ // The value returned by `hasDynamicReflectedReturnType` is false, so
+ // even though this is unimplemented and may be implemented if we get
+ // the required runtime support, it is currently an `UnsupportedError`.
+ throw new UnsupportedError("Attempt to obtain the "
+ "dynamicReflectedReturnType of a generic type "
+ "${_methodMirror.returnType}");
+ }
+ }
+ throw new NoSuchCapabilityError("Attempt to get dynamicReflectedReturnType "
+ "without `reflectedTypeCapability`");
+ }
+
+ @override
String get source => _methodMirror.source;
@override
@@ -1281,6 +1334,33 @@ class VariableMirrorImpl extends _DeclarationMirrorImpl
}
@override
+ bool get hasDynamicReflectedType {
+ if (impliesReflectedType(_reflectable.capabilities)) {
+ return _variableMirror.type.typeVariables.isEmpty &&
+ _variableMirror.type.hasReflectedType;
+ }
+ throw new NoSuchCapabilityError("Attempt to get hasDynamicReflectedType "
+ "without `reflectedTypeCapability`");
+ }
+
+ @override
+ Type get dynamicReflectedType {
+ if (impliesReflectedType(_reflectable.capabilities)) {
+ if (_variableMirror.type.typeVariables.isEmpty) {
+ return _variableMirror.type.reflectedType;
+ } else {
+ // The value returned by `hasDynamicReflectedReturnType` is false, so
+ // even though this is unimplemented and may be implemented if we get
+ // the required runtime support, it is currently an `UnsupportedError`.
+ throw new UnsupportedError("Attempt to obtain the dynamicReflectedType "
+ "of a generic type ${_variableMirror.type}");
+ }
+ }
+ throw new NoSuchCapabilityError("Attempt to get dynamicReflectedType "
+ "without `reflectedTypeCapability`");
+ }
+
+ @override
bool get isStatic => _variableMirror.isStatic;
@override
« no previous file with comments | « reflectable/lib/mirrors.dart ('k') | reflectable/lib/src/reflectable_transformer_based.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698