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

Unified Diff: tests/lib/mirrors/mirrors_used_inheritance_test.dart

Issue 340783011: Take inheritance into account when computing the elements accessible by mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebased + fixes Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/mirrors_used_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/mirrors_used_inheritance_test.dart
diff --git a/tests/lib/mirrors/mirrors_used_inheritance_test.dart b/tests/lib/mirrors/mirrors_used_inheritance_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3f9f971b5bf8e35ea380e05133b187fcc3e2a6d6
--- /dev/null
+++ b/tests/lib/mirrors/mirrors_used_inheritance_test.dart
@@ -0,0 +1,78 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test to make sure that all members of reflectable classes are reflectable,
+// including ones inherited from super classes and the overriding members
+// of subclasses.
+
+@MirrorsUsed(metaTargets: "Meta")
+import 'dart:mirrors';
+import 'package:expect/expect.dart';
+
+class Meta {
+ const Meta();
+}
+
+class Super {
+ var inheritedField = 1;
+ var overriddenField = 1;
+
+ inheritedMethod(x) => x;
+ overriddenMethod(x) => x;
+}
+
+@Meta()
+class Reflected extends Super {
+ var overriddenField = 2;
+ var subclassedField = 2;
+
+ overriddenMethod(x) => 2 * x;
+ subclassedMethod(x) => 2 * x;
+}
+
+class Subclass extends Reflected {
+ var subclassedField = 4;
+ var subclassField = 4;
+
+ subclassedMethod(x) => 4 * x;
+ subclassMethod(x) => 4 * x;
+}
+
+tryCall(object, symbol, value, expected) {
+ var mirror = reflect(object);
+ var result = mirror.invoke(symbol, [value]).reflectee;
+ Expect.equals(result, expected);
+}
+
+tryField(object, symbol, expected) {
+ var mirror = reflect(object);
+ var result = mirror.getField(symbol).reflectee;
+ Expect.equals(result, expected);
+}
+
+main () {
+ var objects = [new Reflected(), new Subclass()];
+
+ // Make sure the subclass methods are alive.
+ objects[1].subclassField = 9;
+ print(objects[1].subclassMethod(9));
+
+ var index = 1;
+ if (new DateTime.now().year == 1984) {
+ index = 0;
+ }
+
+ // Reflect an instance of [Subclass], which should only expose the interface
+ // of [Reflected].
+ var subclass = objects[index];
+ tryCall(subclass, #inheritedMethod, 11, 11);
+ tryCall(subclass, #overriddenMethod, 11, 22);
+ tryCall(subclass, #subclassedMethod, 11, 44);
+ tryField(subclass, #inheritedField, 1);
+ tryField(subclass, #overriddenField, 2);
+ tryField(subclass, #subclassedField, 4);
+ Expect.throws(() =>
+ reflect(subclass).invoke(#subclassMethod, [11]));
+ Expect.throws(() => reflect(subclass).getField(#subclassField));
+}
« no previous file with comments | « tests/compiler/dart2js/mirrors_used_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698