OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; | 8 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; |
9 import 'package:compiler/src/io/source_file.dart'; | 9 import 'package:compiler/src/io/source_file.dart'; |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 class PublicClass extends _PrivateClass { | 35 class PublicClass extends _PrivateClass { |
36 PublicClass() : super(); | 36 PublicClass() : super(); |
37 PublicClass.publicConstructor() : super.publicConstructor(); | 37 PublicClass.publicConstructor() : super.publicConstructor(); |
38 PublicClass._privateConstructor() : super._privateConstructor(); | 38 PublicClass._privateConstructor() : super._privateConstructor(); |
39 | 39 |
40 _PrivateClass get private => this; | 40 _PrivateClass get private => this; |
41 } | 41 } |
42 '''; | 42 '''; |
43 | 43 |
44 | |
45 analyze(String text, [expectedWarnings]) { | 44 analyze(String text, [expectedWarnings]) { |
46 return () { | 45 return () { |
47 if (expectedWarnings == null) expectedWarnings = []; | 46 if (expectedWarnings == null) expectedWarnings = []; |
48 if (expectedWarnings is !List) expectedWarnings = [expectedWarnings]; | 47 if (expectedWarnings is! List) expectedWarnings = [expectedWarnings]; |
49 | 48 |
50 MockCompiler compiler = new MockCompiler.internal(analyzeOnly: true); | 49 MockCompiler compiler = new MockCompiler.internal(analyzeOnly: true); |
51 compiler.registerSource(Uri.parse(PRIVATE_SOURCE_URI), PRIVATE_SOURCE); | 50 compiler.registerSource(Uri.parse(PRIVATE_SOURCE_URI), PRIVATE_SOURCE); |
52 compiler.diagnosticHandler = | 51 compiler.diagnosticHandler = |
53 (uri, int begin, int end, String message, kind) { | 52 (uri, int begin, int end, String message, kind) { |
54 SourceFile sourceFile = compiler.sourceFiles[uri.toString()]; | 53 SourceFile sourceFile = compiler.sourceFiles[uri.toString()]; |
55 if (sourceFile != null) { | 54 if (sourceFile != null) { |
56 print(sourceFile.getLocationMessage(message, begin, end)); | 55 print(sourceFile.getLocationMessage(message, begin, end)); |
57 } else { | 56 } else { |
58 print(message); | 57 print(message); |
(...skipping 14 matching lines...) Expand all Loading... |
73 compiler.registerSource(uri, source); | 72 compiler.registerSource(uri, source); |
74 return compiler.run(uri).then((_) { | 73 return compiler.run(uri).then((_) { |
75 DiagnosticCollector collector = compiler.diagnosticCollector; | 74 DiagnosticCollector collector = compiler.diagnosticCollector; |
76 compareWarningKinds(text, expectedWarnings, collector.warnings); | 75 compareWarningKinds(text, expectedWarnings, collector.warnings); |
77 }); | 76 }); |
78 }; | 77 }; |
79 } | 78 } |
80 | 79 |
81 void main() { | 80 void main() { |
82 asyncTest(() => Future.forEach([ | 81 asyncTest(() => Future.forEach([ |
83 // Read from private variable. | 82 // Read from private variable. |
84 analyze('var value = _privateVariable;', MessageKind.CANNOT_RESOLVE), | 83 analyze('var value = _privateVariable;', MessageKind.CANNOT_RESOLVE), |
85 // Write to private variable. | 84 // Write to private variable. |
86 analyze('_privateVariable = 0;', MessageKind.CANNOT_RESOLVE), | 85 analyze('_privateVariable = 0;', MessageKind.CANNOT_RESOLVE), |
87 // Access private function. | 86 // Access private function. |
88 analyze('var value = _privateFunction;', MessageKind.CANNOT_RESOLVE), | 87 analyze('var value = _privateFunction;', MessageKind.CANNOT_RESOLVE), |
89 // Call private function. | 88 // Call private function. |
90 analyze('_privateFunction();', MessageKind.CANNOT_RESOLVE), | 89 analyze('_privateFunction();', MessageKind.CANNOT_RESOLVE), |
91 | 90 |
92 // Call unnamed (public) constructor on private class. | 91 // Call unnamed (public) constructor on private class. |
93 analyze('new _PrivateClass();', MessageKind.CANNOT_RESOLVE), | 92 analyze('new _PrivateClass();', MessageKind.CANNOT_RESOLVE), |
94 // Call public constructor on private class. | 93 // Call public constructor on private class. |
95 analyze('new _PrivateClass.publicConstructor();', | 94 analyze('new _PrivateClass.publicConstructor();', |
96 MessageKind.CANNOT_RESOLVE), | 95 MessageKind.CANNOT_RESOLVE), |
97 // Call private constructor on private class. | 96 // Call private constructor on private class. |
98 analyze('new _PrivateClass._privateConstructor();', | 97 analyze('new _PrivateClass._privateConstructor();', |
99 MessageKind.CANNOT_RESOLVE), | 98 MessageKind.CANNOT_RESOLVE), |
100 // Call public getter of private type. | 99 // Call public getter of private type. |
101 analyze('var value = publicClass.private;'), | 100 analyze('var value = publicClass.private;'), |
102 // Read from private field on private class. | 101 // Read from private field on private class. |
103 analyze('var value = publicClass.private._privateField;', | 102 analyze('var value = publicClass.private._privateField;', |
104 MessageKind.PRIVATE_ACCESS), | 103 MessageKind.PRIVATE_ACCESS), |
105 // Write to private field on private class. | 104 // Write to private field on private class. |
106 analyze('publicClass.private._privateField = 0;', | 105 analyze('publicClass.private._privateField = 0;', |
107 MessageKind.PRIVATE_ACCESS), | 106 MessageKind.PRIVATE_ACCESS), |
108 // Call private getter on private class. | 107 // Call private getter on private class. |
109 analyze('var value = publicClass.private._privateGetter;', | 108 analyze('var value = publicClass.private._privateGetter;', |
110 MessageKind.PRIVATE_ACCESS), | 109 MessageKind.PRIVATE_ACCESS), |
111 // Call private setter on private class. | 110 // Call private setter on private class. |
112 analyze('publicClass.private._privateSetter = 0;', | 111 analyze('publicClass.private._privateSetter = 0;', |
113 MessageKind.PRIVATE_ACCESS), | 112 MessageKind.PRIVATE_ACCESS), |
114 // Access private method on private class. | 113 // Access private method on private class. |
115 analyze('var value = publicClass.private._privateMethod;', | 114 analyze('var value = publicClass.private._privateMethod;', |
116 MessageKind.PRIVATE_ACCESS), | 115 MessageKind.PRIVATE_ACCESS), |
117 // Call private method on private class. | 116 // Call private method on private class. |
118 analyze('publicClass.private._privateMethod();', | 117 analyze('publicClass.private._privateMethod();', |
119 MessageKind.PRIVATE_ACCESS), | 118 MessageKind.PRIVATE_ACCESS), |
120 | 119 |
121 // Read from public field on private class. | 120 // Read from public field on private class. |
122 analyze('var value = publicClass.private.publicField;'), | 121 analyze('var value = publicClass.private.publicField;'), |
123 // Write to public field on private class. | 122 // Write to public field on private class. |
124 analyze('publicClass.private.publicField = 0;'), | 123 analyze('publicClass.private.publicField = 0;'), |
125 // Call public getter on private class. | 124 // Call public getter on private class. |
126 analyze('var value = publicClass.private.publicGetter;'), | 125 analyze('var value = publicClass.private.publicGetter;'), |
127 // Call public setter on private class. | 126 // Call public setter on private class. |
128 analyze('publicClass.private.publicSetter = 0;'), | 127 analyze('publicClass.private.publicSetter = 0;'), |
129 // Access public method on private class. | 128 // Access public method on private class. |
130 analyze('var value = publicClass.private.publicMethod;'), | 129 analyze('var value = publicClass.private.publicMethod;'), |
131 // Call public method on private class. | 130 // Call public method on private class. |
132 analyze('publicClass.private.publicMethod();'), | 131 analyze('publicClass.private.publicMethod();'), |
133 | 132 |
134 // Call unnamed (public) constructor on public class. | 133 // Call unnamed (public) constructor on public class. |
135 analyze('publicClass = new PublicClass();'), | 134 analyze('publicClass = new PublicClass();'), |
136 // Call public constructor on public class. | 135 // Call public constructor on public class. |
137 analyze('publicClass = new PublicClass.publicConstructor();'), | 136 analyze('publicClass = new PublicClass.publicConstructor();'), |
138 // Call private constructor on public class. | 137 // Call private constructor on public class. |
139 analyze('publicClass = new PublicClass._privateConstructor();', | 138 analyze('publicClass = new PublicClass._privateConstructor();', |
140 MessageKind.CANNOT_FIND_CONSTRUCTOR), | 139 MessageKind.CANNOT_FIND_CONSTRUCTOR), |
141 // Read from private field on public class. | 140 // Read from private field on public class. |
142 analyze('var value = publicClass._privateField;', | 141 analyze('var value = publicClass._privateField;', |
143 MessageKind.PRIVATE_ACCESS), | 142 MessageKind.PRIVATE_ACCESS), |
144 // Write to private field on public class. | 143 // Write to private field on public class. |
145 analyze('publicClass._privateField = 0;', | 144 analyze('publicClass._privateField = 0;', MessageKind.PRIVATE_ACCESS), |
146 MessageKind.PRIVATE_ACCESS), | 145 // Call private getter on public class. |
147 // Call private getter on public class. | 146 analyze('var value = publicClass._privateGetter;', |
148 analyze('var value = publicClass._privateGetter;', | 147 MessageKind.PRIVATE_ACCESS), |
149 MessageKind.PRIVATE_ACCESS), | 148 // Call private setter on public class. |
150 // Call private setter on public class. | 149 analyze('publicClass._privateSetter = 0;', MessageKind.PRIVATE_ACCESS), |
151 analyze('publicClass._privateSetter = 0;', | 150 // Access private method on public class. |
152 MessageKind.PRIVATE_ACCESS), | 151 analyze('var value = publicClass._privateMethod;', |
153 // Access private method on public class. | 152 MessageKind.PRIVATE_ACCESS), |
154 analyze('var value = publicClass._privateMethod;', | 153 // Call private method on public class. |
155 MessageKind.PRIVATE_ACCESS), | 154 analyze('publicClass._privateMethod();', MessageKind.PRIVATE_ACCESS), |
156 // Call private method on public class. | |
157 analyze('publicClass._privateMethod();', | |
158 MessageKind.PRIVATE_ACCESS), | |
159 | 155 |
160 // Read from public field on public class. | 156 // Read from public field on public class. |
161 analyze('var value = publicClass.publicField;'), | 157 analyze('var value = publicClass.publicField;'), |
162 // Write to public field on public class. | 158 // Write to public field on public class. |
163 analyze('publicClass.publicField = 0;'), | 159 analyze('publicClass.publicField = 0;'), |
164 // Call public getter on public class. | 160 // Call public getter on public class. |
165 analyze('var value = publicClass.publicGetter;'), | 161 analyze('var value = publicClass.publicGetter;'), |
166 // Call public setter on public class. | 162 // Call public setter on public class. |
167 analyze('publicClass.publicSetter = 0;'), | 163 analyze('publicClass.publicSetter = 0;'), |
168 // Access public method on public class. | 164 // Access public method on public class. |
169 analyze('var value = publicClass.publicMethod;'), | 165 analyze('var value = publicClass.publicMethod;'), |
170 // Call public method on public class. | 166 // Call public method on public class. |
171 analyze('publicClass.publicMethod();'), | 167 analyze('publicClass.publicMethod();'), |
172 ], (f) => f())); | 168 ], (f) => f())); |
173 } | 169 } |
174 | |
OLD | NEW |