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

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

Issue 1391543003: Creates `reflectors`, as a meta-meta feature that enables dynamic selection of a "mirror system". (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Review response. Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this 1 // Copyright (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 // TODO(sigurdm) doc: Make NoSuchCapability messages streamlined (the same in 5 // TODO(sigurdm) doc: Make NoSuchCapability messages streamlined (the same in
6 // both `reflectable_mirror_based.dart` and 6 // both `reflectable_mirror_based.dart` and
7 // `reflectable_transformer_based.dart`, and explaining as well as possible 7 // `reflectable_transformer_based.dart`, and explaining as well as possible
8 // which capability is missing.) 8 // which capability is missing.)
9 9
10 /// Implementation of the reflectable interface using dart mirrors. 10 /// Implementation of the reflectable interface using dart mirrors.
11 library reflectable.src.reflectable_implementation; 11 library reflectable.src.reflectable_implementation;
12 12
13 import 'dart:mirrors' as dm; 13 import 'dart:mirrors' as dm;
14 import 'reflectable_base.dart'; 14 import 'reflectable_base.dart';
15 import 'fixed_point.dart'; 15 import 'fixed_point.dart';
16 import '../capability.dart'; 16 import '../capability.dart';
17 import '../mirrors.dart' as rm; 17 import '../mirrors.dart' as rm;
18 import '../reflectable.dart'; 18 import '../reflectable.dart';
19 19
20 bool get isTransformed => false; 20 bool get isTransformed => false;
21 21
22 /// Returns the set of reflectors in the current program.
23 Set<Reflectable> get reflectors {
24 Set<Reflectable> result = new Set<Reflectable>();
25 for (dm.LibraryMirror library in dm.currentMirrorSystem().libraries.values) {
26 for (dm.LibraryDependencyMirror dependency in library.libraryDependencies) {
27 if (dependency.isImport &&
28 dependency.targetLibrary.qualifiedName == reflectableLibrarySymbol) {
29 for (dm.InstanceMirror metadatumMirror in dependency.metadata) {
30 Object metadatum = metadatumMirror.reflectee;
31 if (metadatum is GlobalQuantifyCapability) {
32 result.add(metadatum.reflector);
33 }
34 if (metadatum is GlobalQuantifyMetaCapability) {
35 result.add(metadatum.reflector);
36 }
37 }
38 }
39 }
40 }
41 for (dm.LibraryMirror library in dm.currentMirrorSystem().libraries.values) {
42 for (dm.DeclarationMirror declaration in library.declarations.values) {
43 for (dm.InstanceMirror metadatum in declaration.metadata) {
44 if (metadatum.reflectee is Reflectable) {
45 result.add(metadatum.reflectee);
46 }
47 }
48 }
49 }
50 return result;
51 }
52
22 /// The name of the reflectable library. 53 /// The name of the reflectable library.
23 const Symbol reflectableLibrarySymbol = #reflectable.reflectable; 54 const Symbol reflectableLibrarySymbol = #reflectable.reflectable;
24 55
25 rm.ClassMirror wrapClassMirrorIfSupported( 56 rm.ClassMirror wrapClassMirrorIfSupported(
26 dm.ClassMirror classMirror, ReflectableImpl reflectable) { 57 dm.ClassMirror classMirror, ReflectableImpl reflectable) {
27 if (classMirror is dm.FunctionTypeMirror) { 58 if (classMirror is dm.FunctionTypeMirror) {
28 // TODO(sigurdm) clarify: Exactly what capabilities will allow reflecting on 59 // TODO(sigurdm) clarify: Exactly what capabilities will allow reflecting on
29 // a function is still not clear. 60 // a function is still not clear.
30 return new _FunctionTypeMirrorImpl(classMirror, reflectable); 61 return new _FunctionTypeMirrorImpl(classMirror, reflectable);
31 } else { 62 } else {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 @override 393 @override
363 Map<String, rm.DeclarationMirror> get declarations { 394 Map<String, rm.DeclarationMirror> get declarations {
364 if (!reflectableSupportsDeclarations(_reflectable)) { 395 if (!reflectableSupportsDeclarations(_reflectable)) {
365 throw new NoSuchCapabilityError( 396 throw new NoSuchCapabilityError(
366 "Attempt to get declarations without capability"); 397 "Attempt to get declarations without capability");
367 } 398 }
368 Map<Symbol, dm.DeclarationMirror> decls = _libraryMirror.declarations; 399 Map<Symbol, dm.DeclarationMirror> decls = _libraryMirror.declarations;
369 Iterable<Symbol> relevantKeys = decls.keys.where((k) { 400 Iterable<Symbol> relevantKeys = decls.keys.where((k) {
370 List<dm.InstanceMirror> metadata = decls[k].metadata; 401 List<dm.InstanceMirror> metadata = decls[k].metadata;
371 for (var item in metadata) { 402 for (var item in metadata) {
372 if (item.hasReflectee && item.reflectee is ReflectableImpl) return true; 403 if (item.hasReflectee && item.reflectee == _reflectable) return true;
373 } 404 }
374 return false; 405 return false;
375 }); 406 });
376 return new Map<String, rm.DeclarationMirror>.fromIterable(relevantKeys, 407 return new Map<String, rm.DeclarationMirror>.fromIterable(relevantKeys,
377 key: (k) => dm.MirrorSystem.getName(k), 408 key: (k) => dm.MirrorSystem.getName(k),
378 value: (v) => wrapDeclarationMirror(decls[v], _reflectable)); 409 value: (v) => wrapDeclarationMirror(decls[v], _reflectable));
379 } 410 }
380 411
381 @override 412 @override
382 Object invoke(String memberName, List positionalArguments, 413 Object invoke(String memberName, List positionalArguments,
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 for (dm.ParameterMirror parameter in declaration.parameters) { 1725 for (dm.ParameterMirror parameter in declaration.parameters) {
1695 dm.TypeMirror typeMirror = parameter.type.originalDeclaration; 1726 dm.TypeMirror typeMirror = parameter.type.originalDeclaration;
1696 if (typeMirror is dm.ClassMirror) yield typeMirror; 1727 if (typeMirror is dm.ClassMirror) yield typeMirror;
1697 } 1728 }
1698 dm.TypeMirror typeMirror = declaration.returnType; 1729 dm.TypeMirror typeMirror = declaration.returnType;
1699 if (typeMirror is dm.ClassMirror) yield typeMirror; 1730 if (typeMirror is dm.ClassMirror) yield typeMirror;
1700 } 1731 }
1701 } 1732 }
1702 } 1733 }
1703 } 1734 }
OLDNEW
« no previous file with comments | « reflectable/lib/src/encoding_constants.dart ('k') | reflectable/lib/src/reflectable_transformer_based.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698