OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library analyzer.test.generated.element_resolver_test; | 5 library analyzer.test.generated.element_resolver_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 main() { | 32 main() { |
33 defineReflectiveSuite(() { | 33 defineReflectiveSuite(() { |
34 defineReflectiveTests(ElementResolverCodeTest); | 34 defineReflectiveTests(ElementResolverCodeTest); |
35 defineReflectiveTests(ElementResolverTest); | 35 defineReflectiveTests(ElementResolverTest); |
36 }); | 36 }); |
37 } | 37 } |
38 | 38 |
39 @reflectiveTest | 39 @reflectiveTest |
40 class ElementResolverCodeTest extends ResolverTestCase { | 40 class ElementResolverCodeTest extends ResolverTestCase { |
41 test_annotation_class_namedConstructor() async { | 41 test_annotation_class_namedConstructor() async { |
42 addNamedSource( | 42 addNamedSource('/a.dart', r''' |
43 '/a.dart', | |
44 r''' | |
45 class A { | 43 class A { |
46 const A.named(); | 44 const A.named(); |
47 } | 45 } |
48 '''); | 46 '''); |
49 await _validateAnnotation('', '@A.named()', (SimpleIdentifier name1, | 47 await _validateAnnotation('', '@A.named()', (SimpleIdentifier name1, |
50 SimpleIdentifier name2, | 48 SimpleIdentifier name2, |
51 SimpleIdentifier name3, | 49 SimpleIdentifier name3, |
52 Element annotationElement) { | 50 Element annotationElement) { |
53 expect(name1, isNotNull); | 51 expect(name1, isNotNull); |
54 expect(name1.staticElement, new isInstanceOf<ClassElement>()); | 52 expect(name1.staticElement, new isInstanceOf<ClassElement>()); |
55 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'A'); | 53 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'A'); |
56 expect(name2, isNotNull); | 54 expect(name2, isNotNull); |
57 expect(name2.staticElement, new isInstanceOf<ConstructorElement>()); | 55 expect(name2.staticElement, new isInstanceOf<ConstructorElement>()); |
58 expect( | 56 expect( |
59 resolutionMap.staticElementForIdentifier(name2).displayName, 'named'); | 57 resolutionMap.staticElementForIdentifier(name2).displayName, 'named'); |
60 expect(name3, isNull); | 58 expect(name3, isNull); |
61 if (annotationElement is ConstructorElement) { | 59 if (annotationElement is ConstructorElement) { |
62 expect(annotationElement, same(name2.staticElement)); | 60 expect(annotationElement, same(name2.staticElement)); |
63 expect(annotationElement.enclosingElement, name1.staticElement); | 61 expect(annotationElement.enclosingElement, name1.staticElement); |
64 expect(annotationElement.displayName, 'named'); | 62 expect(annotationElement.displayName, 'named'); |
65 expect(annotationElement.parameters, isEmpty); | 63 expect(annotationElement.parameters, isEmpty); |
66 } else { | 64 } else { |
67 fail('Expected "annotationElement" is ConstructorElement, ' | 65 fail('Expected "annotationElement" is ConstructorElement, ' |
68 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 66 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
69 } | 67 } |
70 }); | 68 }); |
71 } | 69 } |
72 | 70 |
73 test_annotation_class_prefixed_namedConstructor() async { | 71 test_annotation_class_prefixed_namedConstructor() async { |
74 addNamedSource( | 72 addNamedSource('/a.dart', r''' |
75 '/a.dart', | |
76 r''' | |
77 class A { | 73 class A { |
78 const A.named(); | 74 const A.named(); |
79 } | 75 } |
80 '''); | 76 '''); |
81 await _validateAnnotation('as p', '@p.A.named()', (SimpleIdentifier name1, | 77 await _validateAnnotation('as p', '@p.A.named()', (SimpleIdentifier name1, |
82 SimpleIdentifier name2, | 78 SimpleIdentifier name2, |
83 SimpleIdentifier name3, | 79 SimpleIdentifier name3, |
84 Element annotationElement) { | 80 Element annotationElement) { |
85 expect(name1, isNotNull); | 81 expect(name1, isNotNull); |
86 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); | 82 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); |
(...skipping 11 matching lines...) Expand all Loading... |
98 expect(annotationElement.displayName, 'named'); | 94 expect(annotationElement.displayName, 'named'); |
99 expect(annotationElement.parameters, isEmpty); | 95 expect(annotationElement.parameters, isEmpty); |
100 } else { | 96 } else { |
101 fail('Expected "annotationElement" is ConstructorElement, ' | 97 fail('Expected "annotationElement" is ConstructorElement, ' |
102 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 98 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
103 } | 99 } |
104 }); | 100 }); |
105 } | 101 } |
106 | 102 |
107 test_annotation_class_prefixed_staticConstField() async { | 103 test_annotation_class_prefixed_staticConstField() async { |
108 addNamedSource( | 104 addNamedSource('/a.dart', r''' |
109 '/a.dart', | |
110 r''' | |
111 class A { | 105 class A { |
112 static const V = 0; | 106 static const V = 0; |
113 } | 107 } |
114 '''); | 108 '''); |
115 await _validateAnnotation('as p', '@p.A.V', (SimpleIdentifier name1, | 109 await _validateAnnotation('as p', '@p.A.V', (SimpleIdentifier name1, |
116 SimpleIdentifier name2, | 110 SimpleIdentifier name2, |
117 SimpleIdentifier name3, | 111 SimpleIdentifier name3, |
118 Element annotationElement) { | 112 Element annotationElement) { |
119 expect(name1, isNotNull); | 113 expect(name1, isNotNull); |
120 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); | 114 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); |
121 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'p'); | 115 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'p'); |
122 expect(name2, isNotNull); | 116 expect(name2, isNotNull); |
123 expect(name2.staticElement, new isInstanceOf<ClassElement>()); | 117 expect(name2.staticElement, new isInstanceOf<ClassElement>()); |
124 expect(resolutionMap.staticElementForIdentifier(name2).displayName, 'A'); | 118 expect(resolutionMap.staticElementForIdentifier(name2).displayName, 'A'); |
125 expect(name3, isNotNull); | 119 expect(name3, isNotNull); |
126 expect(name3.staticElement, new isInstanceOf<PropertyAccessorElement>()); | 120 expect(name3.staticElement, new isInstanceOf<PropertyAccessorElement>()); |
127 expect(resolutionMap.staticElementForIdentifier(name3).displayName, 'V'); | 121 expect(resolutionMap.staticElementForIdentifier(name3).displayName, 'V'); |
128 if (annotationElement is PropertyAccessorElement) { | 122 if (annotationElement is PropertyAccessorElement) { |
129 expect(annotationElement, same(name3.staticElement)); | 123 expect(annotationElement, same(name3.staticElement)); |
130 expect(annotationElement.enclosingElement, name2.staticElement); | 124 expect(annotationElement.enclosingElement, name2.staticElement); |
131 expect(annotationElement.displayName, 'V'); | 125 expect(annotationElement.displayName, 'V'); |
132 } else { | 126 } else { |
133 fail('Expected "annotationElement" is PropertyAccessorElement, ' | 127 fail('Expected "annotationElement" is PropertyAccessorElement, ' |
134 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 128 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
135 } | 129 } |
136 }); | 130 }); |
137 } | 131 } |
138 | 132 |
139 test_annotation_class_prefixed_unnamedConstructor() async { | 133 test_annotation_class_prefixed_unnamedConstructor() async { |
140 addNamedSource( | 134 addNamedSource('/a.dart', r''' |
141 '/a.dart', | |
142 r''' | |
143 class A { | 135 class A { |
144 const A(); | 136 const A(); |
145 } | 137 } |
146 '''); | 138 '''); |
147 await _validateAnnotation('as p', '@p.A', (SimpleIdentifier name1, | 139 await _validateAnnotation('as p', '@p.A', (SimpleIdentifier name1, |
148 SimpleIdentifier name2, | 140 SimpleIdentifier name2, |
149 SimpleIdentifier name3, | 141 SimpleIdentifier name3, |
150 Element annotationElement) { | 142 Element annotationElement) { |
151 expect(name1, isNotNull); | 143 expect(name1, isNotNull); |
152 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); | 144 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); |
153 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'p'); | 145 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'p'); |
154 expect(name2, isNotNull); | 146 expect(name2, isNotNull); |
155 expect(name2.staticElement, new isInstanceOf<ClassElement>()); | 147 expect(name2.staticElement, new isInstanceOf<ClassElement>()); |
156 expect(resolutionMap.staticElementForIdentifier(name2).displayName, 'A'); | 148 expect(resolutionMap.staticElementForIdentifier(name2).displayName, 'A'); |
157 expect(name3, isNull); | 149 expect(name3, isNull); |
158 if (annotationElement is ConstructorElement) { | 150 if (annotationElement is ConstructorElement) { |
159 expect(annotationElement.enclosingElement, name2.staticElement); | 151 expect(annotationElement.enclosingElement, name2.staticElement); |
160 expect(annotationElement.displayName, ''); | 152 expect(annotationElement.displayName, ''); |
161 expect(annotationElement.parameters, isEmpty); | 153 expect(annotationElement.parameters, isEmpty); |
162 } else { | 154 } else { |
163 fail('Expected "annotationElement" is ConstructorElement, ' | 155 fail('Expected "annotationElement" is ConstructorElement, ' |
164 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 156 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
165 } | 157 } |
166 }); | 158 }); |
167 } | 159 } |
168 | 160 |
169 test_annotation_class_staticConstField() async { | 161 test_annotation_class_staticConstField() async { |
170 addNamedSource( | 162 addNamedSource('/a.dart', r''' |
171 '/a.dart', | |
172 r''' | |
173 class A { | 163 class A { |
174 static const V = 0; | 164 static const V = 0; |
175 } | 165 } |
176 '''); | 166 '''); |
177 await _validateAnnotation('', '@A.V', (SimpleIdentifier name1, | 167 await _validateAnnotation('', '@A.V', (SimpleIdentifier name1, |
178 SimpleIdentifier name2, | 168 SimpleIdentifier name2, |
179 SimpleIdentifier name3, | 169 SimpleIdentifier name3, |
180 Element annotationElement) { | 170 Element annotationElement) { |
181 expect(name1, isNotNull); | 171 expect(name1, isNotNull); |
182 expect(name1.staticElement, new isInstanceOf<ClassElement>()); | 172 expect(name1.staticElement, new isInstanceOf<ClassElement>()); |
183 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'A'); | 173 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'A'); |
184 expect(name2, isNotNull); | 174 expect(name2, isNotNull); |
185 expect(name2.staticElement, new isInstanceOf<PropertyAccessorElement>()); | 175 expect(name2.staticElement, new isInstanceOf<PropertyAccessorElement>()); |
186 expect(resolutionMap.staticElementForIdentifier(name2).displayName, 'V'); | 176 expect(resolutionMap.staticElementForIdentifier(name2).displayName, 'V'); |
187 expect(name3, isNull); | 177 expect(name3, isNull); |
188 if (annotationElement is PropertyAccessorElement) { | 178 if (annotationElement is PropertyAccessorElement) { |
189 expect(annotationElement, same(name2.staticElement)); | 179 expect(annotationElement, same(name2.staticElement)); |
190 expect(annotationElement.enclosingElement, name1.staticElement); | 180 expect(annotationElement.enclosingElement, name1.staticElement); |
191 expect(annotationElement.displayName, 'V'); | 181 expect(annotationElement.displayName, 'V'); |
192 } else { | 182 } else { |
193 fail('Expected "annotationElement" is PropertyAccessorElement, ' | 183 fail('Expected "annotationElement" is PropertyAccessorElement, ' |
194 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 184 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
195 } | 185 } |
196 }); | 186 }); |
197 } | 187 } |
198 | 188 |
199 test_annotation_class_unnamedConstructor() async { | 189 test_annotation_class_unnamedConstructor() async { |
200 addNamedSource( | 190 addNamedSource('/a.dart', r''' |
201 '/a.dart', | |
202 r''' | |
203 class A { | 191 class A { |
204 const A(); | 192 const A(); |
205 } | 193 } |
206 '''); | 194 '''); |
207 await _validateAnnotation('', '@A', (SimpleIdentifier name1, | 195 await _validateAnnotation('', '@A', (SimpleIdentifier name1, |
208 SimpleIdentifier name2, | 196 SimpleIdentifier name2, |
209 SimpleIdentifier name3, | 197 SimpleIdentifier name3, |
210 Element annotationElement) { | 198 Element annotationElement) { |
211 expect(name1, isNotNull); | 199 expect(name1, isNotNull); |
212 expect(name1.staticElement, new isInstanceOf<ClassElement>()); | 200 expect(name1.staticElement, new isInstanceOf<ClassElement>()); |
213 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'A'); | 201 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'A'); |
214 expect(name2, isNull); | 202 expect(name2, isNull); |
215 expect(name3, isNull); | 203 expect(name3, isNull); |
216 if (annotationElement is ConstructorElement) { | 204 if (annotationElement is ConstructorElement) { |
217 expect(annotationElement.enclosingElement, name1.staticElement); | 205 expect(annotationElement.enclosingElement, name1.staticElement); |
218 expect(annotationElement.displayName, ''); | 206 expect(annotationElement.displayName, ''); |
219 expect(annotationElement.parameters, isEmpty); | 207 expect(annotationElement.parameters, isEmpty); |
220 } else { | 208 } else { |
221 fail('Expected "annotationElement" is ConstructorElement, ' | 209 fail('Expected "annotationElement" is ConstructorElement, ' |
222 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 210 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
223 } | 211 } |
224 }); | 212 }); |
225 } | 213 } |
226 | 214 |
227 test_annotation_topLevelVariable() async { | 215 test_annotation_topLevelVariable() async { |
228 addNamedSource( | 216 addNamedSource('/a.dart', r''' |
229 '/a.dart', | |
230 r''' | |
231 const V = 0; | 217 const V = 0; |
232 '''); | 218 '''); |
233 await _validateAnnotation('', '@V', (SimpleIdentifier name1, | 219 await _validateAnnotation('', '@V', (SimpleIdentifier name1, |
234 SimpleIdentifier name2, | 220 SimpleIdentifier name2, |
235 SimpleIdentifier name3, | 221 SimpleIdentifier name3, |
236 Element annotationElement) { | 222 Element annotationElement) { |
237 expect(name1, isNotNull); | 223 expect(name1, isNotNull); |
238 expect(name1.staticElement, new isInstanceOf<PropertyAccessorElement>()); | 224 expect(name1.staticElement, new isInstanceOf<PropertyAccessorElement>()); |
239 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'V'); | 225 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'V'); |
240 expect(name2, isNull); | 226 expect(name2, isNull); |
241 expect(name3, isNull); | 227 expect(name3, isNull); |
242 if (annotationElement is PropertyAccessorElement) { | 228 if (annotationElement is PropertyAccessorElement) { |
243 expect(annotationElement, same(name1.staticElement)); | 229 expect(annotationElement, same(name1.staticElement)); |
244 expect(annotationElement.enclosingElement, | 230 expect(annotationElement.enclosingElement, |
245 new isInstanceOf<CompilationUnitElement>()); | 231 new isInstanceOf<CompilationUnitElement>()); |
246 expect(annotationElement.displayName, 'V'); | 232 expect(annotationElement.displayName, 'V'); |
247 } else { | 233 } else { |
248 fail('Expected "annotationElement" is PropertyAccessorElement, ' | 234 fail('Expected "annotationElement" is PropertyAccessorElement, ' |
249 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; | 235 'but (${annotationElement?.runtimeType}) $annotationElement found.')
; |
250 } | 236 } |
251 }); | 237 }); |
252 } | 238 } |
253 | 239 |
254 test_annotation_topLevelVariable_prefixed() async { | 240 test_annotation_topLevelVariable_prefixed() async { |
255 addNamedSource( | 241 addNamedSource('/a.dart', r''' |
256 '/a.dart', | |
257 r''' | |
258 const V = 0; | 242 const V = 0; |
259 '''); | 243 '''); |
260 await _validateAnnotation('as p', '@p.V', (SimpleIdentifier name1, | 244 await _validateAnnotation('as p', '@p.V', (SimpleIdentifier name1, |
261 SimpleIdentifier name2, | 245 SimpleIdentifier name2, |
262 SimpleIdentifier name3, | 246 SimpleIdentifier name3, |
263 Element annotationElement) { | 247 Element annotationElement) { |
264 expect(name1, isNotNull); | 248 expect(name1, isNotNull); |
265 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); | 249 expect(name1.staticElement, new isInstanceOf<PrefixElement>()); |
266 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'p'); | 250 expect(resolutionMap.staticElementForIdentifier(name1).displayName, 'p'); |
267 expect(name2, isNotNull); | 251 expect(name2, isNotNull); |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 innerScope = new LabelScope( | 1280 innerScope = new LabelScope( |
1297 outerScope, labelElement.name, labelTarget, labelElement); | 1281 outerScope, labelElement.name, labelTarget, labelElement); |
1298 } | 1282 } |
1299 _visitor.labelScope = innerScope; | 1283 _visitor.labelScope = innerScope; |
1300 statement.accept(_resolver); | 1284 statement.accept(_resolver); |
1301 } finally { | 1285 } finally { |
1302 _visitor.labelScope = outerScope; | 1286 _visitor.labelScope = outerScope; |
1303 } | 1287 } |
1304 } | 1288 } |
1305 } | 1289 } |
OLD | NEW |