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

Side by Side Diff: reflectable/lib/src/transformer_implementation.dart

Issue 1181153003: Add `.type` to the transformed InstanceMirror. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Clarify comment Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | test_reflectable/test/reflect_type_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // (c) 2015, the Dart Team. All rights reserved. Use of this 1 // (c) 2015, the Dart Team. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in 2 // source code is governed by a BSD-style license that can be found in
3 // the LICENSE file. 3 // the LICENSE file.
4 4
5 library reflectable.src.transformer_implementation; 5 library reflectable.src.transformer_implementation;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:math' show max; 10 import 'dart:math' show max;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 result += constants.abstractAttribute; 112 result += constants.abstractAttribute;
113 } 113 }
114 if (element.isStatic) { 114 if (element.isStatic) {
115 result += constants.staticAttribute; 115 result += constants.staticAttribute;
116 } 116 }
117 return result; 117 return result;
118 } 118 }
119 119
120 /// Returns a String with the textual representation of the declarations-map. 120 /// Returns a String with the textual representation of the declarations-map.
121 String get declarationsString { 121 String get declarationsString {
122 Iterable<String> declarationParts = declarations 122 Iterable<String> declarationParts = declarations.map(
123 .map((ExecutableElement instanceMember) { 123 (ExecutableElement instanceMember) {
124 return '"${instanceMember.name}": ' 124 return '"${instanceMember.name}": '
125 'new MethodMirrorImpl("${instanceMember.name}", ' 125 'new MethodMirrorImpl("${instanceMember.name}", '
126 '${_declarationDescriptor(instanceMember)}, this)'; 126 '${_declarationDescriptor(instanceMember)}, this)';
127 }); 127 });
128 return "{${declarationParts.join(", ")}}"; 128 return "{${declarationParts.join(", ")}}";
129 } 129 }
130 130
131 void computeNames(Namer namer) { 131 void computeNames(Namer namer) {
132 staticClassMirrorName = namer.freshName("Static_${baseName}_ClassMirror"); 132 staticClassMirrorName = namer.freshName("Static_${baseName}_ClassMirror");
133 staticInstanceMirrorName = 133 staticInstanceMirrorName =
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 Iterable<${prefix}ClassMirror> get annotatedClasses { 757 Iterable<${prefix}ClassMirror> get annotatedClasses {
758 return [${annotatedClassesStrings.join(", ")}]; 758 return [${annotatedClassesStrings.join(", ")}];
759 }"""); 759 }""");
760 } 760 }
761 761
762 /// Returns the source code for the reflection free subclass of 762 /// Returns the source code for the reflection free subclass of
763 /// [ClassMirror] which is specialized for a `reflectedType` which 763 /// [ClassMirror] which is specialized for a `reflectedType` which
764 /// is the class modeled by [classElement]. 764 /// is the class modeled by [classElement].
765 String _staticClassMirrorCode(ClassDomain classDomain) { 765 String _staticClassMirrorCode(ClassDomain classDomain) {
766 String declarationsString = classDomain.declarationsString; 766 String declarationsString = classDomain.declarationsString;
767 String simpleName = classDomain.classElement.name;
768 // When/if we have library-mirrors there could be a generic implementation:
769 // String get qualifiedName => "${owner.qualifiedName}.${simpleName}";
770 String qualifiedName =
771 "${classDomain.classElement.library.name}.$simpleName";
767 return """ 772 return """
768 class ${classDomain.staticClassMirrorName} extends ClassMirrorUnimpl { 773 class ${classDomain.staticClassMirrorName} extends ClassMirrorUnimpl {
769 final String simpleName = "${classDomain.classElement.name}"; 774 final String simpleName = "$simpleName";
775 final String qualifiedName = "$qualifiedName";
770 776
771 Map<String, MethodMirror> _declarationsCache; 777 Map<String, MethodMirror> _declarationsCache;
772 778
773 Map<String, MethodMirror> get declarations { 779 Map<String, MethodMirror> get declarations {
774 if (_declarationsCache == null) { 780 if (_declarationsCache == null) {
775 _declarationsCache = new UnmodifiableMapView($declarationsString); 781 _declarationsCache = new UnmodifiableMapView($declarationsString);
776 } 782 }
777 return _declarationsCache; 783 return _declarationsCache;
778 } 784 }
779 } 785 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 /// [InstanceMirror] which is specialized for a `reflectee` which 1120 /// [InstanceMirror] which is specialized for a `reflectee` which
1115 /// is an instance of the class modeled by [classElement]. The 1121 /// is an instance of the class modeled by [classElement]. The
1116 /// generated code will provide support as specified by 1122 /// generated code will provide support as specified by
1117 /// [capabilities]. 1123 /// [capabilities].
1118 String _staticInstanceMirrorCode(ClassDomain classDomain) { 1124 String _staticInstanceMirrorCode(ClassDomain classDomain) {
1119 // The `rest` of the code is the entire body of the static mirror class, 1125 // The `rest` of the code is the entire body of the static mirror class,
1120 // except for the declaration of `reflectee`, and a constructor. 1126 // except for the declaration of `reflectee`, and a constructor.
1121 String rest = ""; 1127 String rest = "";
1122 rest += instanceMethodFilter(classDomain.reflectorDomain.capabilities); 1128 rest += instanceMethodFilter(classDomain.reflectorDomain.capabilities);
1123 rest += _staticInstanceMirrorInvokeCode(classDomain); 1129 rest += _staticInstanceMirrorInvokeCode(classDomain);
1130 rest += " ClassMirror get type => "
1131 "new ${classDomain.staticClassMirrorName}();\n";
1124 // TODO(eernst): add code for other mirror methods than `invoke`. 1132 // TODO(eernst): add code for other mirror methods than `invoke`.
1125 return """ 1133 return """
1126 class ${classDomain.staticInstanceMirrorName} extends InstanceMirrorUnimpl { 1134 class ${classDomain.staticInstanceMirrorName} extends InstanceMirrorUnimpl {
1127 final ${_classElementName(classDomain)} reflectee; 1135 final ${_classElementName(classDomain)} reflectee;
1128 ${classDomain.staticInstanceMirrorName}(this.reflectee); 1136 ${classDomain.staticInstanceMirrorName}(this.reflectee);
1129 $rest} 1137 $rest}
1130 """; 1138 """;
1131 } 1139 }
1132 1140
1133 /// Returns the result of transforming the given [source] code, which is 1141 /// Returns the result of transforming the given [source] code, which is
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 TransformLogger get logger => _aggregateTransform.logger; 1344 TransformLogger get logger => _aggregateTransform.logger;
1337 Future<Asset> getInput(AssetId id) => _aggregateTransform.getInput(id); 1345 Future<Asset> getInput(AssetId id) => _aggregateTransform.getInput(id);
1338 Future<String> readInputAsString(AssetId id, {Encoding encoding}) { 1346 Future<String> readInputAsString(AssetId id, {Encoding encoding}) {
1339 return _aggregateTransform.readInputAsString(id, encoding: encoding); 1347 return _aggregateTransform.readInputAsString(id, encoding: encoding);
1340 } 1348 }
1341 Stream<List<int>> readInput(AssetId id) => _aggregateTransform.readInput(id); 1349 Stream<List<int>> readInput(AssetId id) => _aggregateTransform.readInput(id);
1342 Future<bool> hasInput(AssetId id) => _aggregateTransform.hasInput(id); 1350 Future<bool> hasInput(AssetId id) => _aggregateTransform.hasInput(id);
1343 void addOutput(Asset output) => _aggregateTransform.addOutput(output); 1351 void addOutput(Asset output) => _aggregateTransform.addOutput(output);
1344 void consumePrimary() => _aggregateTransform.consumePrimary(primaryInput.id); 1352 void consumePrimary() => _aggregateTransform.consumePrimary(primaryInput.id);
1345 } 1353 }
OLDNEW
« no previous file with comments | « no previous file | test_reflectable/test/reflect_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698