| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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.all_the_rest_test; | 5 library analyzer.test.generated.all_the_rest_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/file_system/physical_file_system.dart'; | 10 import 'package:analyzer/file_system/physical_file_system.dart'; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 DirectoryBasedSourceContainer container = | 259 DirectoryBasedSourceContainer container = |
| 260 new DirectoryBasedSourceContainer.con1(dir); | 260 new DirectoryBasedSourceContainer.con1(dir); |
| 261 expect(container.contains(source1), isTrue); | 261 expect(container.contains(source1), isTrue); |
| 262 expect(container.contains(source2), isTrue); | 262 expect(container.contains(source2), isTrue); |
| 263 expect(container.contains(source3), isFalse); | 263 expect(container.contains(source3), isFalse); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 @reflectiveTest | 267 @reflectiveTest |
| 268 class ElementBuilderTest extends ParserTestCase { | 268 class ElementBuilderTest extends ParserTestCase { |
| 269 /** |
| 270 * Parse the given [code], pass it through [ElementBuilder], and return the |
| 271 * resulting [ElementHolder]. |
| 272 */ |
| 273 ElementHolder buildElementsForText(String code) { |
| 274 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); |
| 275 ElementHolder holder = new ElementHolder(); |
| 276 ElementBuilder builder = new ElementBuilder(holder); |
| 277 unit.accept(builder); |
| 278 return holder; |
| 279 } |
| 280 |
| 281 /** |
| 282 * Verify that the given [element] has exactly one annotation, and that its |
| 283 * [ElementAnnotationImpl] is unresolved and points back to [element]. |
| 284 */ |
| 285 void checkMetadata(Element element) { |
| 286 expect(element.metadata, hasLength(1)); |
| 287 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>()); |
| 288 ElementAnnotationImpl elementAnnotation = element.metadata[0]; |
| 289 expect(elementAnnotation.element, isNull); // Not yet resolved |
| 290 expect(elementAnnotation.annotatedElement, element); |
| 291 } |
| 292 |
| 269 void fail_visitMethodDeclaration_setter_duplicate() { | 293 void fail_visitMethodDeclaration_setter_duplicate() { |
| 270 // https://github.com/dart-lang/sdk/issues/25601 | 294 // https://github.com/dart-lang/sdk/issues/25601 |
| 271 String code = r''' | 295 String code = r''' |
| 272 class C { | 296 class C { |
| 273 set zzz(x) {} | 297 set zzz(x) {} |
| 274 set zzz(y) {} | 298 set zzz(y) {} |
| 275 } | 299 } |
| 276 '''; | 300 '''; |
| 277 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); | 301 ClassElement classElement = buildElementsForText(code).types[0]; |
| 278 ElementHolder holder = new ElementHolder(); | |
| 279 ElementBuilder builder = new ElementBuilder(holder); | |
| 280 unit.accept(builder); | |
| 281 ClassElement classElement = holder.types[0]; | |
| 282 for (PropertyAccessorElement accessor in classElement.accessors) { | 302 for (PropertyAccessorElement accessor in classElement.accessors) { |
| 283 expect(accessor.variable.setter, same(accessor)); | 303 expect(accessor.variable.setter, same(accessor)); |
| 284 } | 304 } |
| 285 } | 305 } |
| 286 | 306 |
| 307 void test_metadata_variableDeclaration() { |
| 308 List<TopLevelVariableElement> topLevelVariables = |
| 309 buildElementsForText('@a int x, y;').topLevelVariables; |
| 310 checkMetadata(topLevelVariables[0]); |
| 311 checkMetadata(topLevelVariables[1]); |
| 312 } |
| 313 |
| 314 void test_metadata_visitClassDeclaration() { |
| 315 ClassElement classElement = buildElementsForText('@a class C {}').types[0]; |
| 316 checkMetadata(classElement); |
| 317 } |
| 318 |
| 319 void test_metadata_visitClassTypeAlias() { |
| 320 ClassElement classElement = |
| 321 buildElementsForText('@a class C = D with E;').types[0]; |
| 322 checkMetadata(classElement); |
| 323 } |
| 324 |
| 325 void test_metadata_visitConstructorDeclaration() { |
| 326 ConstructorElement constructorElement = |
| 327 buildElementsForText('class C { @a C(); }').types[0].constructors[0]; |
| 328 checkMetadata(constructorElement); |
| 329 } |
| 330 |
| 331 void test_metadata_visitDeclaredIdentifier() { |
| 332 LocalVariableElement localVariableElement = |
| 333 buildElementsForText('f() { for (@a var x in y) {} }') |
| 334 .functions[0] |
| 335 .localVariables[0]; |
| 336 checkMetadata(localVariableElement); |
| 337 } |
| 338 |
| 339 void test_metadata_visitEnumDeclaration() { |
| 340 ClassElement classElement = |
| 341 buildElementsForText('@a enum E { v }').enums[0]; |
| 342 checkMetadata(classElement); |
| 343 } |
| 344 |
| 345 void test_metadata_visitFieldFormalParameter() { |
| 346 ParameterElement parameterElement = |
| 347 buildElementsForText('class C { var x; C(@a this.x); }') |
| 348 .types[0] |
| 349 .constructors[0] |
| 350 .parameters[0]; |
| 351 checkMetadata(parameterElement); |
| 352 } |
| 353 |
| 354 void test_metadata_visitFunctionDeclaration_function() { |
| 355 FunctionElement functionElement = |
| 356 buildElementsForText('@a f() {}').functions[0]; |
| 357 checkMetadata(functionElement); |
| 358 } |
| 359 |
| 360 void test_metadata_visitFunctionDeclaration_getter() { |
| 361 PropertyAccessorElement propertyAccessorElement = |
| 362 buildElementsForText('@a get f => null;').accessors[0]; |
| 363 checkMetadata(propertyAccessorElement); |
| 364 } |
| 365 |
| 366 void test_metadata_visitFunctionDeclaration_setter() { |
| 367 PropertyAccessorElement propertyAccessorElement = |
| 368 buildElementsForText('@a set f(value) {}').accessors[0]; |
| 369 checkMetadata(propertyAccessorElement); |
| 370 } |
| 371 |
| 372 void test_metadata_visitFunctionTypeAlias() { |
| 373 FunctionTypeAliasElement functionTypeAliasElement = |
| 374 buildElementsForText('@a typedef F();').typeAliases[0]; |
| 375 checkMetadata(functionTypeAliasElement); |
| 376 } |
| 377 |
| 378 void test_metadata_visitFunctionTypedFormalParameter() { |
| 379 ParameterElement parameterElement = |
| 380 buildElementsForText('f(@a g()) {}').functions[0].parameters[0]; |
| 381 checkMetadata(parameterElement); |
| 382 } |
| 383 |
| 384 void test_metadata_visitMethodDeclaration_getter() { |
| 385 PropertyAccessorElement propertyAccessorElement = |
| 386 buildElementsForText('class C { @a get m => null; }') |
| 387 .types[0] |
| 388 .accessors[0]; |
| 389 checkMetadata(propertyAccessorElement); |
| 390 } |
| 391 |
| 392 void test_metadata_visitMethodDeclaration_method() { |
| 393 MethodElement methodElement = |
| 394 buildElementsForText('class C { @a m() {} }').types[0].methods[0]; |
| 395 checkMetadata(methodElement); |
| 396 } |
| 397 |
| 398 void test_metadata_visitMethodDeclaration_setter() { |
| 399 PropertyAccessorElement propertyAccessorElement = |
| 400 buildElementsForText('class C { @a set f(value) {} }') |
| 401 .types[0] |
| 402 .accessors[0]; |
| 403 checkMetadata(propertyAccessorElement); |
| 404 } |
| 405 |
| 406 void test_metadata_visitSimpleFormalParameter() { |
| 407 ParameterElement parameterElement = |
| 408 buildElementsForText('f(@a x) {}').functions[0].parameters[0]; |
| 409 checkMetadata(parameterElement); |
| 410 } |
| 411 |
| 412 void test_metadata_visitTypeParameter() { |
| 413 TypeParameterElement typeParameterElement = |
| 414 buildElementsForText('class C<@a T> {}').types[0].typeParameters[0]; |
| 415 checkMetadata(typeParameterElement); |
| 416 } |
| 417 |
| 287 void test_visitCatchClause() { | 418 void test_visitCatchClause() { |
| 288 // } catch (e, s) { | 419 // } catch (e, s) { |
| 289 ElementHolder holder = new ElementHolder(); | 420 ElementHolder holder = new ElementHolder(); |
| 290 ElementBuilder builder = new ElementBuilder(holder); | 421 ElementBuilder builder = new ElementBuilder(holder); |
| 291 String exceptionParameterName = "e"; | 422 String exceptionParameterName = "e"; |
| 292 String stackParameterName = "s"; | 423 String stackParameterName = "s"; |
| 293 CatchClause clause = | 424 CatchClause clause = |
| 294 AstFactory.catchClause2(exceptionParameterName, stackParameterName); | 425 AstFactory.catchClause2(exceptionParameterName, stackParameterName); |
| 295 clause.accept(builder); | 426 clause.accept(builder); |
| 296 | 427 |
| (...skipping 3519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3816 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 3947 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
| 3817 expect(UriKind.fromEncoding(0x58), same(null)); | 3948 expect(UriKind.fromEncoding(0x58), same(null)); |
| 3818 } | 3949 } |
| 3819 | 3950 |
| 3820 void test_getEncoding() { | 3951 void test_getEncoding() { |
| 3821 expect(UriKind.DART_URI.encoding, 0x64); | 3952 expect(UriKind.DART_URI.encoding, 0x64); |
| 3822 expect(UriKind.FILE_URI.encoding, 0x66); | 3953 expect(UriKind.FILE_URI.encoding, 0x66); |
| 3823 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 3954 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
| 3824 } | 3955 } |
| 3825 } | 3956 } |
| OLD | NEW |