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

Side by Side 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, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // 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.
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // 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.
6 // annotations of MirrorsUsed are preserved.
7 // In the test the class B is not instantiated, but we still want its names
8 // ("foo") to be preserved.
9
10 @MirrorsUsed(metaTargets: "Meta")
11 import 'dart:mirrors';
12 import 'package:expect/expect.dart';
13
14 class Meta {
15 const Meta();
16 }
17
18 class Super {
19 var inheritedField = 1;
20 var overriddenField = 1;
21
22 inheritedMethod(x) => x;
23 overriddenMethod(x) => x;
24 }
25
26 @Meta()
27 class Reflected extends Super {
28 var overriddenField = 2;
29 var subclassedField = 2;
30
31 overriddenMethod(x) => 2 * x;
32 subclassedMethod(x) => 2 * x;
33 }
34
35 class Subclass extends Reflected {
36 var subclassedField = 4;
37 var subclassField = 4;
38
39 subclassedMethod(x) => 4 * x;
40 subclassMethod(x) => 4 * x;
41 }
42
43 tryCall(object, symbol, value, expected) {
44 var mirror = reflect(object);
45 var result = mirror.invoke(symbol, [value]).reflectee;
46 Expect.equals(result, expected);
47 }
48
49 tryField(object, symbol, expected) {
50 var mirror = reflect(object);
51 var result = mirror.getField(symbol).reflectee;
52 Expect.equals(result, expected);
53 }
54
55 main () {
56 var objects = [new Reflected(), new Subclass()];
57
58 // Make sure the subclass methods are alive.
59 objects[1].subclassField = 9;
60 print(objects[1].subclassMethod(9));
61
62 var index = 1;
63 if (new DateTime.now().year == 1984) {
64 index = 0;
65 }
66
67 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
68 tryCall(object, #inheritedMethod, 11, 11);
69 tryCall(object, #overriddenMethod, 11, 22);
70 tryCall(object, #subclassedMethod, 11, 44);
71 tryField(object, #inheritedField, 1);
72 tryField(object, #overriddenField, 2);
73 tryField(object, #subclassedField, 4);
74 Expect.throws(() =>
75 reflect(object).invoke(#subclassMethod, [11]));
76 Expect.throws(() => reflect(object).getField(#subclassField));
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698