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

Side by Side Diff: test/codegen/lib/mirrors/private_symbol_mangling_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 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
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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 library main;
6
7 //@MirrorsUsed(targets: const ['C1', 'C2', '_privateGlobalField', '_privateGloba lMethod'])
8 import 'dart:mirrors';
9 import 'package:expect/expect.dart';
10 import 'private_symbol_mangling_lib.dart';
11
12 var _privateGlobalField = 1;
13
14 _privateGlobalMethod() => 9;
15
16 class C1 {
17 var _privateField = 0;
18 _privateMethod() => 2;
19 }
20
21 getPrivateGlobalFieldValue(LibraryMirror lib) {
22 for (Symbol symbol in lib.declarations.keys) {
23 DeclarationMirror decl = lib.declarations[symbol];
24 if (decl is VariableMirror && decl.isPrivate) {
25 return lib.getField(symbol).reflectee;
26 }
27 }
28 }
29
30 getPrivateFieldValue(InstanceMirror cls) {
31 for (Symbol symbol in cls.type.declarations.keys) {
32 DeclarationMirror decl = cls.type.declarations[symbol];
33 if (decl is VariableMirror && decl.isPrivate) {
34 return cls.getField(symbol).reflectee;
35 }
36 }
37 }
38
39 getPrivateGlobalMethodValue(LibraryMirror lib) {
40 for (Symbol symbol in lib.declarations.keys) {
41 DeclarationMirror decl = lib.declarations[symbol];
42 if (decl is MethodMirror && decl.isRegularMethod && decl.isPrivate) {
43 return lib.invoke(symbol, []).reflectee;
44 }
45 }
46 }
47
48 getPrivateMethodValue(InstanceMirror cls) {
49 for (Symbol symbol in cls.type.declarations.keys) {
50 DeclarationMirror decl = cls.type.declarations[symbol];
51 if (decl is MethodMirror && decl.isRegularMethod && decl.isPrivate) {
52 return cls.invoke(symbol, []).reflectee;
53 }
54 }
55 }
56
57 main() {
58 LibraryMirror libmain = currentMirrorSystem().findLibrary(#main);
59 LibraryMirror libother = currentMirrorSystem().findLibrary(#other);
60 Expect.equals(1, getPrivateGlobalFieldValue(libmain));
61 Expect.equals(3, getPrivateGlobalFieldValue(libother));
62 Expect.equals(9, getPrivateGlobalMethodValue(libmain));
63 Expect.equals(11, getPrivateGlobalMethodValue(libother));
64
65 var c1 = reflect(new C1());
66 var c2 = reflect(new C2());
67 Expect.equals(0, getPrivateFieldValue(c1));
68 Expect.equals(1, getPrivateFieldValue(c2));
69 Expect.equals(2, getPrivateMethodValue(c1));
70 Expect.equals(3, getPrivateMethodValue(c2));
71 }
OLDNEW
« no previous file with comments | « test/codegen/lib/mirrors/private_symbol_mangling_lib.dart ('k') | test/codegen/lib/mirrors/private_symbol_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698