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

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

Issue 1391013008: Adds limited support for private classes. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: reflectable/lib/src/reflectable_transformer_based.dart
diff --git a/reflectable/lib/src/reflectable_transformer_based.dart b/reflectable/lib/src/reflectable_transformer_based.dart
index a7b3ef86eeff45fc55948c8fee52da0115c826ab..d58a584bdcf71fa92ab9e9fe33702e8c51e3434c 100644
--- a/reflectable/lib/src/reflectable_transformer_based.dart
+++ b/reflectable/lib/src/reflectable_transformer_based.dart
@@ -109,7 +109,15 @@ class ReflectorData {
_typeToClassMirrorCache = new Map.fromIterables(types, classMirrors);
}
}
- return _typeToClassMirrorCache[type];
+ ClassMirror result = _typeToClassMirrorCache[type];
+ if (result == null && "$type".startsWith("_")) {
sigurdm 2015/10/15 12:30:58 Abstract startsWith("_") to isPrivateName()
eernst 2015/10/15 13:46:11 This section deleted: We do not support reflecting
+ for (Type typeKey in _typeToClassMirrorCache.keys) {
+ if (typeKey is FakeType && typeKey.correspondsTo(type)) {
+ return _typeToClassMirrorCache[typeKey];
+ }
+ }
+ }
+ return result;
}
}
@@ -499,14 +507,8 @@ class ClassMirrorImpl extends _DataCaching implements ClassMirror {
}
class LibraryMirrorImpl extends _DataCaching implements LibraryMirror {
- LibraryMirrorImpl(
- this.simpleName,
- this.uri,
- this._reflector,
- this._declarationIndices,
- this.getters,
- this.setters,
- this._metadata);
+ LibraryMirrorImpl(this.simpleName, this.uri, this._reflector,
+ this._declarationIndices, this.getters, this.setters, this._metadata);
final ReflectableImpl _reflector;
@@ -551,6 +553,11 @@ class LibraryMirrorImpl extends _DataCaching implements LibraryMirror {
_data.memberMirrors[declarationIndex];
result[declarationMirror.simpleName] = declarationMirror;
}
+ _data.classMirrors.forEach((ClassMirror classMirror) {
+ if (classMirror.owner == this) {
+ result[classMirror.simpleName] = classMirror;
+ }
+ });
_declarations =
new UnmodifiableMapView<String, DeclarationMirror>(result);
}
@@ -612,8 +619,15 @@ class LibraryMirrorImpl extends _DataCaching implements LibraryMirror {
@override
String get qualifiedName => simpleName;
- bool operator ==(other) => _unsupported();
- int get hashCode => _unsupported();
+ bool operator ==(other) {
+ return other is LibraryMirrorImpl &&
+ other.uri == uri &&
+ other._reflector == _reflector &&
+ other._declarationIndices == _declarationIndices;
+ }
+
+ int get hashCode =>
+ uri.hashCode ^ _reflector.hashCode ^ _declarationIndices.hashCode;
// TODO(sigurdm) implement: Need to implement this. Probably only when a given
// capability is enabled.
@@ -1263,4 +1277,13 @@ class FakeType implements Type {
final String description;
String toString() => "Type($description)";
+
+ /// Make a best effort attempt to recognize that this fake type represents
+ /// the given [type]. Only private non-mixin-application types are recognized,
+ bool correspondsTo(Type type) {
sigurdm 2015/10/15 12:30:58 I think this support for reflecting on instances o
eernst 2015/10/15 13:46:11 Deleted, too.
+ if (description.contains(" with ")) return false;
+ String typeName = type.toString();
+ if (!typeName.startsWith("_")) return false;
+ return description.contains(".$type");
+ }
}

Powered by Google App Engine
This is Rietveld 408576698