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

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: 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
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..b01ff9a3e99dbcd4cdcd21ca26c96df90dda44db
--- /dev/null
+++ b/tests/lib/mirrors/mirrors_used_inheritance_test.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
Johnni Winther 2014/06/27 07:43:02 2013 -> 2014
herhut 2014/06/27 12:34:38 Done.
+// 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 the names of classes that are marked with meta
Johnni Winther 2014/06/27 07:43:02 Update comment.
herhut 2014/06/27 12:34:38 Done.
+// annotations of MirrorsUsed are preserved.
+// In the test the class B is not instantiated, but we still want its names
+// ("foo") to be preserved.
+
+@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;
+ }
+
+ var object = objects[index];
Johnni Winther 2014/06/27 07:43:02 [object] -> [reflected] to show that we access an
herhut 2014/06/27 12:34:38 Actually, it is an instance of Subclass. I have re
+ tryCall(object, #inheritedMethod, 11, 11);
+ tryCall(object, #overriddenMethod, 11, 22);
+ tryCall(object, #subclassedMethod, 11, 44);
+ tryField(object, #inheritedField, 1);
+ tryField(object, #overriddenField, 2);
+ tryField(object, #subclassedField, 4);
+ Expect.throws(() =>
+ reflect(object).invoke(#subclassMethod, [11]));
+ Expect.throws(() => reflect(object).getField(#subclassField));
+}

Powered by Google App Engine
This is Rietveld 408576698