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

Issue 1473073009: Added `dynamicReflected..Type`, corrected type expressions. (Closed)

Created:
5 years ago by eernst
Modified:
5 years ago
Reviewers:
sigurdm
CC:
eernst+reviews_google.com, reviews_dartlang.org, floitsch
Base URL:
https://github.com/dart-lang/reflectable.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Added `dynamicReflected..Type`, corrected type expressions. Added methods `dynamicReflectedType` and `hasDynamicReflectedType` to class mirrors and type annotation related mirrors (variable, parameter, and method mirrors), returning the fully dynamic instantiation of the given [Type] object (e.g., `List` rather than `List<String>`). Added a new public class `TypeValue` to 'mirrors.dart', such that we can use expressions like `const TypeValue<List<int>>().type`; this is in fact convenient in test code as well, and presumably in client code. Corrected the code that produces type expressions for various things (esp. values returned by `dynamicReflectedType`) such that it includes type arguments and uses `TypeValue` when needed. It is not easy to cover generic types in both pre- and post-transform code, and the features around reflected types have brought up new issues: In pre-transform code we cannot obtain `List` from a given `List<T>` for some `T`, so `dynamicReflectedType` cannot be implemented in all cases; but since `hasDynamicReflectedType` returns false in these cases, users can still write reliable code. Similarly, `reflectedType` cannot be implemented in cases like `List<E>` used as a type annotation in the class `List`: We do not have the required primitives to look up `E` in a given list, so we cannot produce a class mirror and then a variable/parameter mirror that holds the [Type] value for `E`, so `hasReflectedType` must return false here. This means that client code must in general test with the `has..` methods (which was obvious anyway, even if they didn't always do it) and the `has..` methods may not return the same value in pre- and post-transform code, which is a new kind of incompatibility. However, it is a worse kind of incompatibility if pre-transform code returns `List<String>` and post-transform code returns `List`, and the behavior changes because an `==` test with `List<String>` now fails after transformation. Rewrote the functions named `_typeCode` and similar names extensively to support these things. Added a new test for `{has,}dynamicReflectedCode`. R=sigurdm@google.com Committed: https://github.com/dart-lang/reflectable/commit/10da7e398ce439314dacfb276e2a58ecbabce5b4

Patch Set 1 #

Total comments: 10

Patch Set 2 : Review response. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+464 lines, -41 lines) Patch
M reflectable/lib/mirrors.dart View 1 6 chunks +87 lines, -3 lines 0 comments Download
M reflectable/lib/src/reflectable_mirror_based.dart View 4 chunks +80 lines, -0 lines 0 comments Download
M reflectable/lib/src/reflectable_transformer_based.dart View 20 chunks +75 lines, -10 lines 0 comments Download
M reflectable/lib/src/setup_analyzer.dart View 1 2 chunks +2 lines, -2 lines 0 comments Download
M reflectable/lib/src/transformer_implementation.dart View 1 13 chunks +165 lines, -19 lines 0 comments Download
M reflectable/lib/transformer.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M reflectable/test/mock_tests/check_literal_transform_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M test_reflectable/pubspec.yaml View 1 chunk +1 line, -0 lines 0 comments Download
A test_reflectable/test/dynamic_reflected_type_test.dart View 1 chunk +45 lines, -0 lines 0 comments Download
M test_reflectable/test/new_instance_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M test_reflectable/test/reflected_type_test.dart View 3 chunks +6 lines, -4 lines 0 comments Download

Messages

Total messages: 6 (2 generated)
eernst
Works with bottest. Expected extension before landing: Some `bestEffortReflectedType` method that tries both `reflectedType` and ...
5 years ago (2015-11-26 10:02:01 UTC) #2
sigurdm
LGTM https://codereview.chromium.org/1473073009/diff/1/reflectable/lib/mirrors.dart File reflectable/lib/mirrors.dart (right): https://codereview.chromium.org/1473073009/diff/1/reflectable/lib/mirrors.dart#newcode312 reflectable/lib/mirrors.dart:312: Type get reflectedType; Document conditions for availability. https://codereview.chromium.org/1473073009/diff/1/reflectable/lib/mirrors.dart#newcode345 ...
5 years ago (2015-11-26 10:18:04 UTC) #3
eernst
Review response, in particular: Added several longish comments about the conditions under which `reflected..Type` is ...
5 years ago (2015-11-26 11:24:00 UTC) #4
eernst
5 years ago (2015-11-26 11:25:31 UTC) #6
Message was sent while issue was closed.
Committed patchset #2 (id:20001) manually as
10da7e398ce439314dacfb276e2a58ecbabce5b4 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698