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 engine.all_the_rest_test; | 5 library engine.all_the_rest_test; |
6 | 6 |
7 import 'package:analyzer/file_system/physical_file_system.dart'; | 7 import 'package:analyzer/file_system/physical_file_system.dart'; |
8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 4956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4967 new DirectoryBasedSourceContainer.con1(dir); | 4967 new DirectoryBasedSourceContainer.con1(dir); |
4968 expect(container.contains(source1), isTrue); | 4968 expect(container.contains(source1), isTrue); |
4969 expect(container.contains(source2), isTrue); | 4969 expect(container.contains(source2), isTrue); |
4970 expect(container.contains(source3), isFalse); | 4970 expect(container.contains(source3), isFalse); |
4971 } | 4971 } |
4972 } | 4972 } |
4973 | 4973 |
4974 @reflectiveTest | 4974 @reflectiveTest |
4975 class ElementBuilderTest extends EngineTestCase { | 4975 class ElementBuilderTest extends EngineTestCase { |
4976 void test_visitCatchClause() { | 4976 void test_visitCatchClause() { |
| 4977 // } catch (e, s) { |
4977 ElementHolder holder = new ElementHolder(); | 4978 ElementHolder holder = new ElementHolder(); |
4978 ElementBuilder builder = new ElementBuilder(holder); | 4979 ElementBuilder builder = new ElementBuilder(holder); |
4979 String exceptionParameterName = "e"; | 4980 String exceptionParameterName = "e"; |
4980 String stackParameterName = "s"; | 4981 String stackParameterName = "s"; |
4981 CatchClause clause = | 4982 CatchClause clause = |
4982 AstFactory.catchClause2(exceptionParameterName, stackParameterName); | 4983 AstFactory.catchClause2(exceptionParameterName, stackParameterName); |
4983 clause.accept(builder); | 4984 clause.accept(builder); |
| 4985 |
4984 List<LocalVariableElement> variables = holder.localVariables; | 4986 List<LocalVariableElement> variables = holder.localVariables; |
4985 expect(variables, hasLength(2)); | 4987 expect(variables, hasLength(2)); |
4986 VariableElement exceptionVariable = variables[0]; | 4988 VariableElement exceptionVariable = variables[0]; |
4987 expect(exceptionVariable, isNotNull); | 4989 expect(exceptionVariable, isNotNull); |
4988 expect(exceptionVariable.name, exceptionParameterName); | 4990 expect(exceptionVariable.name, exceptionParameterName); |
| 4991 expect(exceptionVariable.hasImplicitType, isTrue); |
4989 expect(exceptionVariable.isSynthetic, isFalse); | 4992 expect(exceptionVariable.isSynthetic, isFalse); |
4990 expect(exceptionVariable.isConst, isFalse); | 4993 expect(exceptionVariable.isConst, isFalse); |
4991 expect(exceptionVariable.isFinal, isFalse); | 4994 expect(exceptionVariable.isFinal, isFalse); |
4992 expect(exceptionVariable.initializer, isNull); | 4995 expect(exceptionVariable.initializer, isNull); |
4993 VariableElement stackVariable = variables[1]; | 4996 VariableElement stackVariable = variables[1]; |
4994 expect(stackVariable, isNotNull); | 4997 expect(stackVariable, isNotNull); |
4995 expect(stackVariable.name, stackParameterName); | 4998 expect(stackVariable.name, stackParameterName); |
4996 expect(stackVariable.isSynthetic, isFalse); | 4999 expect(stackVariable.isSynthetic, isFalse); |
4997 expect(stackVariable.isConst, isFalse); | 5000 expect(stackVariable.isConst, isFalse); |
4998 expect(stackVariable.isFinal, isFalse); | 5001 expect(stackVariable.isFinal, isFalse); |
4999 expect(stackVariable.initializer, isNull); | 5002 expect(stackVariable.initializer, isNull); |
5000 } | 5003 } |
5001 | 5004 |
| 5005 void test_visitCatchClause_withType() { |
| 5006 // } on E catch (e) { |
| 5007 ElementHolder holder = new ElementHolder(); |
| 5008 ElementBuilder builder = new ElementBuilder(holder); |
| 5009 String exceptionParameterName = "e"; |
| 5010 CatchClause clause = AstFactory.catchClause4( |
| 5011 AstFactory.typeName4('E'), exceptionParameterName); |
| 5012 clause.accept(builder); |
| 5013 |
| 5014 List<LocalVariableElement> variables = holder.localVariables; |
| 5015 expect(variables, hasLength(1)); |
| 5016 VariableElement exceptionVariable = variables[0]; |
| 5017 expect(exceptionVariable, isNotNull); |
| 5018 expect(exceptionVariable.name, exceptionParameterName); |
| 5019 expect(exceptionVariable.hasImplicitType, isFalse); |
| 5020 } |
| 5021 |
5002 void test_visitClassDeclaration_abstract() { | 5022 void test_visitClassDeclaration_abstract() { |
5003 ElementHolder holder = new ElementHolder(); | 5023 ElementHolder holder = new ElementHolder(); |
5004 ElementBuilder builder = new ElementBuilder(holder); | 5024 ElementBuilder builder = new ElementBuilder(holder); |
5005 String className = "C"; | 5025 String className = "C"; |
5006 ClassDeclaration classDeclaration = AstFactory.classDeclaration( | 5026 ClassDeclaration classDeclaration = AstFactory.classDeclaration( |
5007 Keyword.ABSTRACT, className, null, null, null, null); | 5027 Keyword.ABSTRACT, className, null, null, null, null); |
5008 classDeclaration.accept(builder); | 5028 classDeclaration.accept(builder); |
5009 List<ClassElement> types = holder.types; | 5029 List<ClassElement> types = holder.types; |
5010 expect(types, hasLength(1)); | 5030 expect(types, hasLength(1)); |
5011 ClassElement type = types[0]; | 5031 ClassElement type = types[0]; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5333 expect(constructor.isExternal, isFalse); | 5353 expect(constructor.isExternal, isFalse); |
5334 expect(constructor.isFactory, isFalse); | 5354 expect(constructor.isFactory, isFalse); |
5335 expect(constructor.name, ""); | 5355 expect(constructor.name, ""); |
5336 expect(constructor.functions, hasLength(0)); | 5356 expect(constructor.functions, hasLength(0)); |
5337 expect(constructor.labels, hasLength(0)); | 5357 expect(constructor.labels, hasLength(0)); |
5338 expect(constructor.localVariables, hasLength(0)); | 5358 expect(constructor.localVariables, hasLength(0)); |
5339 expect(constructor.parameters, hasLength(0)); | 5359 expect(constructor.parameters, hasLength(0)); |
5340 expect(constructorDeclaration.element, same(constructor)); | 5360 expect(constructorDeclaration.element, same(constructor)); |
5341 } | 5361 } |
5342 | 5362 |
| 5363 void test_visitDeclaredIdentifier_noType() { |
| 5364 // var i |
| 5365 ElementHolder holder = new ElementHolder(); |
| 5366 ElementBuilder builder = new ElementBuilder(holder); |
| 5367 var variableName = 'i'; |
| 5368 DeclaredIdentifier identifier = |
| 5369 AstFactory.declaredIdentifier3(variableName); |
| 5370 AstFactory.forEachStatement( |
| 5371 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); |
| 5372 identifier.accept(builder); |
| 5373 |
| 5374 List<LocalVariableElement> variables = holder.localVariables; |
| 5375 expect(variables, hasLength(1)); |
| 5376 LocalVariableElement variable = variables[0]; |
| 5377 expect(variable, isNotNull); |
| 5378 expect(variable.hasImplicitType, isTrue); |
| 5379 expect(variable.isConst, isFalse); |
| 5380 expect(variable.isDeprecated, isFalse); |
| 5381 expect(variable.isFinal, isFalse); |
| 5382 expect(variable.isOverride, isFalse); |
| 5383 expect(variable.isPrivate, isFalse); |
| 5384 expect(variable.isPublic, isTrue); |
| 5385 expect(variable.isSynthetic, isFalse); |
| 5386 expect(variable.name, variableName); |
| 5387 } |
| 5388 |
| 5389 void test_visitDeclaredIdentifier_type() { |
| 5390 // E i |
| 5391 ElementHolder holder = new ElementHolder(); |
| 5392 ElementBuilder builder = new ElementBuilder(holder); |
| 5393 var variableName = 'i'; |
| 5394 DeclaredIdentifier identifier = |
| 5395 AstFactory.declaredIdentifier4(AstFactory.typeName4('E'), variableName); |
| 5396 AstFactory.forEachStatement( |
| 5397 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); |
| 5398 identifier.accept(builder); |
| 5399 |
| 5400 List<LocalVariableElement> variables = holder.localVariables; |
| 5401 expect(variables, hasLength(1)); |
| 5402 LocalVariableElement variable = variables[0]; |
| 5403 expect(variable, isNotNull); |
| 5404 expect(variable.hasImplicitType, isFalse); |
| 5405 expect(variable.isConst, isFalse); |
| 5406 expect(variable.isDeprecated, isFalse); |
| 5407 expect(variable.isFinal, isFalse); |
| 5408 expect(variable.isOverride, isFalse); |
| 5409 expect(variable.isPrivate, isFalse); |
| 5410 expect(variable.isPublic, isTrue); |
| 5411 expect(variable.isSynthetic, isFalse); |
| 5412 expect(variable.name, variableName); |
| 5413 } |
| 5414 |
| 5415 void test_visitDefaultFormalParameter_noType() { |
| 5416 // p = 0 |
| 5417 ElementHolder holder = new ElementHolder(); |
| 5418 ElementBuilder builder = new ElementBuilder(holder); |
| 5419 String parameterName = 'p'; |
| 5420 DefaultFormalParameter formalParameter = AstFactory |
| 5421 .positionalFormalParameter( |
| 5422 AstFactory.simpleFormalParameter3(parameterName), |
| 5423 AstFactory.integer(0)); |
| 5424 formalParameter.accept(builder); |
| 5425 |
| 5426 List<ParameterElement> parameters = holder.parameters; |
| 5427 expect(parameters, hasLength(1)); |
| 5428 ParameterElement parameter = parameters[0]; |
| 5429 expect(parameter.hasImplicitType, isTrue); |
| 5430 expect(parameter.isConst, isFalse); |
| 5431 expect(parameter.isDeprecated, isFalse); |
| 5432 expect(parameter.isFinal, isFalse); |
| 5433 expect(parameter.isInitializingFormal, isFalse); |
| 5434 expect(parameter.isOverride, isFalse); |
| 5435 expect(parameter.isPrivate, isFalse); |
| 5436 expect(parameter.isPublic, isTrue); |
| 5437 expect(parameter.isSynthetic, isFalse); |
| 5438 expect(parameter.name, parameterName); |
| 5439 } |
| 5440 |
| 5441 void test_visitDefaultFormalParameter_type() { |
| 5442 // E p = 0 |
| 5443 ElementHolder holder = new ElementHolder(); |
| 5444 ElementBuilder builder = new ElementBuilder(holder); |
| 5445 String parameterName = 'p'; |
| 5446 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( |
| 5447 AstFactory.simpleFormalParameter4( |
| 5448 AstFactory.typeName4('E'), parameterName), |
| 5449 AstFactory.integer(0)); |
| 5450 formalParameter.accept(builder); |
| 5451 |
| 5452 List<ParameterElement> parameters = holder.parameters; |
| 5453 expect(parameters, hasLength(1)); |
| 5454 ParameterElement parameter = parameters[0]; |
| 5455 expect(parameter.hasImplicitType, isFalse); |
| 5456 expect(parameter.isConst, isFalse); |
| 5457 expect(parameter.isDeprecated, isFalse); |
| 5458 expect(parameter.isFinal, isFalse); |
| 5459 expect(parameter.isInitializingFormal, isFalse); |
| 5460 expect(parameter.isOverride, isFalse); |
| 5461 expect(parameter.isPrivate, isFalse); |
| 5462 expect(parameter.isPublic, isTrue); |
| 5463 expect(parameter.isSynthetic, isFalse); |
| 5464 expect(parameter.name, parameterName); |
| 5465 } |
| 5466 |
5343 void test_visitEnumDeclaration() { | 5467 void test_visitEnumDeclaration() { |
5344 ElementHolder holder = new ElementHolder(); | 5468 ElementHolder holder = new ElementHolder(); |
5345 ElementBuilder builder = new ElementBuilder(holder); | 5469 ElementBuilder builder = new ElementBuilder(holder); |
5346 String enumName = "E"; | 5470 String enumName = "E"; |
5347 EnumDeclaration enumDeclaration = | 5471 EnumDeclaration enumDeclaration = |
5348 AstFactory.enumDeclaration2(enumName, ["ONE"]); | 5472 AstFactory.enumDeclaration2(enumName, ["ONE"]); |
5349 enumDeclaration.accept(builder); | 5473 enumDeclaration.accept(builder); |
5350 List<ClassElement> enums = holder.enums; | 5474 List<ClassElement> enums = holder.enums; |
5351 expect(enums, hasLength(1)); | 5475 expect(enums, hasLength(1)); |
5352 ClassElement enumElement = enums[0]; | 5476 ClassElement enumElement = enums[0]; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5437 AstFactory.simpleFormalParameter3(secondParameterName) | 5561 AstFactory.simpleFormalParameter3(secondParameterName) |
5438 ]); | 5562 ]); |
5439 parameterList.accept(builder); | 5563 parameterList.accept(builder); |
5440 List<ParameterElement> parameters = holder.parameters; | 5564 List<ParameterElement> parameters = holder.parameters; |
5441 expect(parameters, hasLength(2)); | 5565 expect(parameters, hasLength(2)); |
5442 expect(parameters[0].name, firstParameterName); | 5566 expect(parameters[0].name, firstParameterName); |
5443 expect(parameters[1].name, secondParameterName); | 5567 expect(parameters[1].name, secondParameterName); |
5444 } | 5568 } |
5445 | 5569 |
5446 void test_visitFunctionDeclaration_external() { | 5570 void test_visitFunctionDeclaration_external() { |
| 5571 // external f(); |
5447 ElementHolder holder = new ElementHolder(); | 5572 ElementHolder holder = new ElementHolder(); |
5448 ElementBuilder builder = new ElementBuilder(holder); | 5573 ElementBuilder builder = new ElementBuilder(holder); |
5449 String functionName = "f"; | 5574 String functionName = "f"; |
5450 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 5575 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
5451 null, | 5576 null, |
5452 null, | 5577 null, |
5453 functionName, | 5578 functionName, |
5454 AstFactory.functionExpression2( | 5579 AstFactory.functionExpression2( |
5455 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 5580 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody())); |
5456 declaration.externalKeyword = | 5581 declaration.externalKeyword = |
5457 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 5582 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
5458 declaration.accept(builder); | 5583 declaration.accept(builder); |
| 5584 |
5459 List<FunctionElement> functions = holder.functions; | 5585 List<FunctionElement> functions = holder.functions; |
5460 expect(functions, hasLength(1)); | 5586 expect(functions, hasLength(1)); |
5461 FunctionElement function = functions[0]; | 5587 FunctionElement function = functions[0]; |
5462 expect(function, isNotNull); | 5588 expect(function, isNotNull); |
5463 expect(function.name, functionName); | 5589 expect(function.name, functionName); |
5464 expect(declaration.element, same(function)); | 5590 expect(declaration.element, same(function)); |
5465 expect(declaration.functionExpression.element, same(function)); | 5591 expect(declaration.functionExpression.element, same(function)); |
| 5592 expect(function.hasImplicitReturnType, isTrue); |
5466 expect(function.isExternal, isTrue); | 5593 expect(function.isExternal, isTrue); |
5467 expect(function.isSynthetic, isFalse); | 5594 expect(function.isSynthetic, isFalse); |
5468 expect(function.typeParameters, hasLength(0)); | 5595 expect(function.typeParameters, hasLength(0)); |
5469 } | 5596 } |
5470 | 5597 |
5471 void test_visitFunctionDeclaration_getter() { | 5598 void test_visitFunctionDeclaration_getter() { |
| 5599 // get f() {} |
5472 ElementHolder holder = new ElementHolder(); | 5600 ElementHolder holder = new ElementHolder(); |
5473 ElementBuilder builder = new ElementBuilder(holder); | 5601 ElementBuilder builder = new ElementBuilder(holder); |
5474 String functionName = "f"; | 5602 String functionName = "f"; |
5475 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 5603 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
5476 null, | 5604 null, |
5477 Keyword.GET, | 5605 Keyword.GET, |
5478 functionName, | 5606 functionName, |
5479 AstFactory.functionExpression2( | 5607 AstFactory.functionExpression2( |
5480 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 5608 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
5481 declaration.accept(builder); | 5609 declaration.accept(builder); |
| 5610 |
5482 List<PropertyAccessorElement> accessors = holder.accessors; | 5611 List<PropertyAccessorElement> accessors = holder.accessors; |
5483 expect(accessors, hasLength(1)); | 5612 expect(accessors, hasLength(1)); |
5484 PropertyAccessorElement accessor = accessors[0]; | 5613 PropertyAccessorElement accessor = accessors[0]; |
5485 expect(accessor, isNotNull); | 5614 expect(accessor, isNotNull); |
5486 expect(accessor.name, functionName); | 5615 expect(accessor.name, functionName); |
5487 expect(declaration.element, same(accessor)); | 5616 expect(declaration.element, same(accessor)); |
5488 expect(declaration.functionExpression.element, same(accessor)); | 5617 expect(declaration.functionExpression.element, same(accessor)); |
| 5618 expect(accessor.hasImplicitReturnType, isTrue); |
5489 expect(accessor.isGetter, isTrue); | 5619 expect(accessor.isGetter, isTrue); |
5490 expect(accessor.isExternal, isFalse); | 5620 expect(accessor.isExternal, isFalse); |
5491 expect(accessor.isSetter, isFalse); | 5621 expect(accessor.isSetter, isFalse); |
5492 expect(accessor.isSynthetic, isFalse); | 5622 expect(accessor.isSynthetic, isFalse); |
5493 expect(accessor.typeParameters, hasLength(0)); | 5623 expect(accessor.typeParameters, hasLength(0)); |
5494 PropertyInducingElement variable = accessor.variable; | 5624 PropertyInducingElement variable = accessor.variable; |
5495 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, | 5625 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, |
5496 TopLevelVariableElement, variable); | 5626 TopLevelVariableElement, variable); |
5497 expect(variable.isSynthetic, isTrue); | 5627 expect(variable.isSynthetic, isTrue); |
5498 } | 5628 } |
5499 | 5629 |
5500 void test_visitFunctionDeclaration_plain() { | 5630 void test_visitFunctionDeclaration_plain() { |
| 5631 // T f() {} |
5501 ElementHolder holder = new ElementHolder(); | 5632 ElementHolder holder = new ElementHolder(); |
5502 ElementBuilder builder = new ElementBuilder(holder); | 5633 ElementBuilder builder = new ElementBuilder(holder); |
5503 String functionName = "f"; | 5634 String functionName = "f"; |
5504 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 5635 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
5505 null, | 5636 AstFactory.typeName4('T'), |
5506 null, | 5637 null, |
5507 functionName, | 5638 functionName, |
5508 AstFactory.functionExpression2( | 5639 AstFactory.functionExpression2( |
5509 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 5640 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
5510 declaration.accept(builder); | 5641 declaration.accept(builder); |
| 5642 |
5511 List<FunctionElement> functions = holder.functions; | 5643 List<FunctionElement> functions = holder.functions; |
5512 expect(functions, hasLength(1)); | 5644 expect(functions, hasLength(1)); |
5513 FunctionElement function = functions[0]; | 5645 FunctionElement function = functions[0]; |
5514 expect(function, isNotNull); | 5646 expect(function, isNotNull); |
| 5647 expect(function.hasImplicitReturnType, isFalse); |
5515 expect(function.name, functionName); | 5648 expect(function.name, functionName); |
5516 expect(declaration.element, same(function)); | 5649 expect(declaration.element, same(function)); |
5517 expect(declaration.functionExpression.element, same(function)); | 5650 expect(declaration.functionExpression.element, same(function)); |
5518 expect(function.isExternal, isFalse); | 5651 expect(function.isExternal, isFalse); |
5519 expect(function.isSynthetic, isFalse); | 5652 expect(function.isSynthetic, isFalse); |
5520 expect(function.typeParameters, hasLength(0)); | 5653 expect(function.typeParameters, hasLength(0)); |
5521 } | 5654 } |
5522 | 5655 |
5523 void test_visitFunctionDeclaration_setter() { | 5656 void test_visitFunctionDeclaration_setter() { |
| 5657 // set f() {} |
5524 ElementHolder holder = new ElementHolder(); | 5658 ElementHolder holder = new ElementHolder(); |
5525 ElementBuilder builder = new ElementBuilder(holder); | 5659 ElementBuilder builder = new ElementBuilder(holder); |
5526 String functionName = "f"; | 5660 String functionName = "f"; |
5527 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 5661 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
5528 null, | 5662 null, |
5529 Keyword.SET, | 5663 Keyword.SET, |
5530 functionName, | 5664 functionName, |
5531 AstFactory.functionExpression2( | 5665 AstFactory.functionExpression2( |
5532 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 5666 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
5533 declaration.accept(builder); | 5667 declaration.accept(builder); |
| 5668 |
5534 List<PropertyAccessorElement> accessors = holder.accessors; | 5669 List<PropertyAccessorElement> accessors = holder.accessors; |
5535 expect(accessors, hasLength(1)); | 5670 expect(accessors, hasLength(1)); |
5536 PropertyAccessorElement accessor = accessors[0]; | 5671 PropertyAccessorElement accessor = accessors[0]; |
5537 expect(accessor, isNotNull); | 5672 expect(accessor, isNotNull); |
| 5673 expect(accessor.hasImplicitReturnType, isFalse); |
5538 expect(accessor.name, "$functionName="); | 5674 expect(accessor.name, "$functionName="); |
5539 expect(declaration.element, same(accessor)); | 5675 expect(declaration.element, same(accessor)); |
5540 expect(declaration.functionExpression.element, same(accessor)); | 5676 expect(declaration.functionExpression.element, same(accessor)); |
5541 expect(accessor.isGetter, isFalse); | 5677 expect(accessor.isGetter, isFalse); |
5542 expect(accessor.isExternal, isFalse); | 5678 expect(accessor.isExternal, isFalse); |
5543 expect(accessor.isSetter, isTrue); | 5679 expect(accessor.isSetter, isTrue); |
5544 expect(accessor.isSynthetic, isFalse); | 5680 expect(accessor.isSynthetic, isFalse); |
5545 expect(accessor.typeParameters, hasLength(0)); | 5681 expect(accessor.typeParameters, hasLength(0)); |
5546 PropertyInducingElement variable = accessor.variable; | 5682 PropertyInducingElement variable = accessor.variable; |
5547 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, | 5683 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, |
5548 TopLevelVariableElement, variable); | 5684 TopLevelVariableElement, variable); |
5549 expect(variable.isSynthetic, isTrue); | 5685 expect(variable.isSynthetic, isTrue); |
5550 } | 5686 } |
5551 | 5687 |
5552 void test_visitFunctionDeclaration_typeParameters() { | 5688 void test_visitFunctionDeclaration_typeParameters() { |
| 5689 // f<E>() {} |
5553 ElementHolder holder = new ElementHolder(); | 5690 ElementHolder holder = new ElementHolder(); |
5554 ElementBuilder builder = new ElementBuilder(holder); | 5691 ElementBuilder builder = new ElementBuilder(holder); |
5555 String functionName = 'f'; | 5692 String functionName = 'f'; |
5556 String typeParameterName = 'E'; | 5693 String typeParameterName = 'E'; |
5557 FunctionExpression expression = AstFactory.functionExpression3( | 5694 FunctionExpression expression = AstFactory.functionExpression3( |
5558 AstFactory.typeParameterList([typeParameterName]), | 5695 AstFactory.typeParameterList([typeParameterName]), |
5559 AstFactory.formalParameterList(), | 5696 AstFactory.formalParameterList(), |
5560 AstFactory.blockFunctionBody2()); | 5697 AstFactory.blockFunctionBody2()); |
5561 FunctionDeclaration declaration = | 5698 FunctionDeclaration declaration = |
5562 AstFactory.functionDeclaration(null, null, functionName, expression); | 5699 AstFactory.functionDeclaration(null, null, functionName, expression); |
5563 declaration.accept(builder); | 5700 declaration.accept(builder); |
| 5701 |
5564 List<FunctionElement> functions = holder.functions; | 5702 List<FunctionElement> functions = holder.functions; |
5565 expect(functions, hasLength(1)); | 5703 expect(functions, hasLength(1)); |
5566 FunctionElement function = functions[0]; | 5704 FunctionElement function = functions[0]; |
5567 expect(function, isNotNull); | 5705 expect(function, isNotNull); |
| 5706 expect(function.hasImplicitReturnType, isTrue); |
5568 expect(function.name, functionName); | 5707 expect(function.name, functionName); |
5569 expect(function.isExternal, isFalse); | 5708 expect(function.isExternal, isFalse); |
5570 expect(function.isSynthetic, isFalse); | 5709 expect(function.isSynthetic, isFalse); |
5571 expect(declaration.element, same(function)); | 5710 expect(declaration.element, same(function)); |
5572 expect(expression.element, same(function)); | 5711 expect(expression.element, same(function)); |
5573 List<TypeParameterElement> typeParameters = function.typeParameters; | 5712 List<TypeParameterElement> typeParameters = function.typeParameters; |
5574 expect(typeParameters, hasLength(1)); | 5713 expect(typeParameters, hasLength(1)); |
5575 TypeParameterElement typeParameter = typeParameters[0]; | 5714 TypeParameterElement typeParameter = typeParameters[0]; |
5576 expect(typeParameter, isNotNull); | 5715 expect(typeParameter, isNotNull); |
5577 expect(typeParameter.name, typeParameterName); | 5716 expect(typeParameter.name, typeParameterName); |
5578 } | 5717 } |
5579 | 5718 |
5580 void test_visitFunctionExpression() { | 5719 void test_visitFunctionExpression() { |
5581 ElementHolder holder = new ElementHolder(); | 5720 ElementHolder holder = new ElementHolder(); |
5582 ElementBuilder builder = new ElementBuilder(holder); | 5721 ElementBuilder builder = new ElementBuilder(holder); |
5583 FunctionExpression expression = AstFactory.functionExpression2( | 5722 FunctionExpression expression = AstFactory.functionExpression2( |
5584 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()); | 5723 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()); |
5585 expression.accept(builder); | 5724 expression.accept(builder); |
5586 List<FunctionElement> functions = holder.functions; | 5725 List<FunctionElement> functions = holder.functions; |
5587 expect(functions, hasLength(1)); | 5726 expect(functions, hasLength(1)); |
5588 FunctionElement function = functions[0]; | 5727 FunctionElement function = functions[0]; |
5589 expect(function, isNotNull); | 5728 expect(function, isNotNull); |
5590 expect(expression.element, same(function)); | 5729 expect(expression.element, same(function)); |
| 5730 expect(function.hasImplicitReturnType, isTrue); |
5591 expect(function.isSynthetic, isFalse); | 5731 expect(function.isSynthetic, isFalse); |
5592 expect(function.typeParameters, hasLength(0)); | 5732 expect(function.typeParameters, hasLength(0)); |
5593 } | 5733 } |
5594 | 5734 |
5595 void test_visitFunctionTypeAlias() { | 5735 void test_visitFunctionTypeAlias() { |
5596 ElementHolder holder = new ElementHolder(); | 5736 ElementHolder holder = new ElementHolder(); |
5597 ElementBuilder builder = new ElementBuilder(holder); | 5737 ElementBuilder builder = new ElementBuilder(holder); |
5598 String aliasName = "F"; | 5738 String aliasName = "F"; |
5599 String parameterName = "E"; | 5739 String parameterName = "E"; |
5600 FunctionTypeAlias aliasNode = AstFactory.typeAlias( | 5740 FunctionTypeAlias aliasNode = AstFactory.typeAlias( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5670 statement.accept(builder); | 5810 statement.accept(builder); |
5671 List<LabelElement> labels = holder.labels; | 5811 List<LabelElement> labels = holder.labels; |
5672 expect(labels, hasLength(1)); | 5812 expect(labels, hasLength(1)); |
5673 LabelElement label = labels[0]; | 5813 LabelElement label = labels[0]; |
5674 expect(label, isNotNull); | 5814 expect(label, isNotNull); |
5675 expect(label.name, labelName); | 5815 expect(label.name, labelName); |
5676 expect(label.isSynthetic, isFalse); | 5816 expect(label.isSynthetic, isFalse); |
5677 } | 5817 } |
5678 | 5818 |
5679 void test_visitMethodDeclaration_abstract() { | 5819 void test_visitMethodDeclaration_abstract() { |
| 5820 // m(); |
5680 ElementHolder holder = new ElementHolder(); | 5821 ElementHolder holder = new ElementHolder(); |
5681 ElementBuilder builder = new ElementBuilder(holder); | 5822 ElementBuilder builder = new ElementBuilder(holder); |
5682 String methodName = "m"; | 5823 String methodName = "m"; |
5683 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 5824 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5684 null, | 5825 null, |
5685 null, | 5826 null, |
5686 null, | 5827 null, |
5687 null, | 5828 null, |
5688 AstFactory.identifier3(methodName), | 5829 AstFactory.identifier3(methodName), |
5689 AstFactory.formalParameterList(), | 5830 AstFactory.formalParameterList(), |
5690 AstFactory.emptyFunctionBody()); | 5831 AstFactory.emptyFunctionBody()); |
5691 methodDeclaration.accept(builder); | 5832 methodDeclaration.accept(builder); |
| 5833 |
5692 List<MethodElement> methods = holder.methods; | 5834 List<MethodElement> methods = holder.methods; |
5693 expect(methods, hasLength(1)); | 5835 expect(methods, hasLength(1)); |
5694 MethodElement method = methods[0]; | 5836 MethodElement method = methods[0]; |
5695 expect(method, isNotNull); | 5837 expect(method, isNotNull); |
| 5838 expect(method.hasImplicitReturnType, isTrue); |
5696 expect(method.name, methodName); | 5839 expect(method.name, methodName); |
5697 expect(method.functions, hasLength(0)); | 5840 expect(method.functions, hasLength(0)); |
5698 expect(method.labels, hasLength(0)); | 5841 expect(method.labels, hasLength(0)); |
5699 expect(method.localVariables, hasLength(0)); | 5842 expect(method.localVariables, hasLength(0)); |
5700 expect(method.parameters, hasLength(0)); | 5843 expect(method.parameters, hasLength(0)); |
5701 expect(method.typeParameters, hasLength(0)); | 5844 expect(method.typeParameters, hasLength(0)); |
5702 expect(method.isAbstract, isTrue); | 5845 expect(method.isAbstract, isTrue); |
5703 expect(method.isExternal, isFalse); | 5846 expect(method.isExternal, isFalse); |
5704 expect(method.isStatic, isFalse); | 5847 expect(method.isStatic, isFalse); |
5705 expect(method.isSynthetic, isFalse); | 5848 expect(method.isSynthetic, isFalse); |
5706 } | 5849 } |
5707 | 5850 |
5708 void test_visitMethodDeclaration_external() { | 5851 void test_visitMethodDeclaration_external() { |
| 5852 // external m(); |
5709 ElementHolder holder = new ElementHolder(); | 5853 ElementHolder holder = new ElementHolder(); |
5710 ElementBuilder builder = new ElementBuilder(holder); | 5854 ElementBuilder builder = new ElementBuilder(holder); |
5711 String methodName = "m"; | 5855 String methodName = "m"; |
5712 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 5856 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5713 null, | 5857 null, |
5714 null, | 5858 null, |
5715 null, | 5859 null, |
5716 null, | 5860 null, |
5717 AstFactory.identifier3(methodName), | 5861 AstFactory.identifier3(methodName), |
5718 AstFactory.formalParameterList(), | 5862 AstFactory.formalParameterList(), |
5719 AstFactory.emptyFunctionBody()); | 5863 AstFactory.emptyFunctionBody()); |
5720 methodDeclaration.externalKeyword = | 5864 methodDeclaration.externalKeyword = |
5721 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 5865 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
5722 methodDeclaration.accept(builder); | 5866 methodDeclaration.accept(builder); |
| 5867 |
5723 List<MethodElement> methods = holder.methods; | 5868 List<MethodElement> methods = holder.methods; |
5724 expect(methods, hasLength(1)); | 5869 expect(methods, hasLength(1)); |
5725 MethodElement method = methods[0]; | 5870 MethodElement method = methods[0]; |
5726 expect(method, isNotNull); | 5871 expect(method, isNotNull); |
| 5872 expect(method.hasImplicitReturnType, isTrue); |
5727 expect(method.name, methodName); | 5873 expect(method.name, methodName); |
5728 expect(method.functions, hasLength(0)); | 5874 expect(method.functions, hasLength(0)); |
5729 expect(method.labels, hasLength(0)); | 5875 expect(method.labels, hasLength(0)); |
5730 expect(method.localVariables, hasLength(0)); | 5876 expect(method.localVariables, hasLength(0)); |
5731 expect(method.parameters, hasLength(0)); | 5877 expect(method.parameters, hasLength(0)); |
5732 expect(method.typeParameters, hasLength(0)); | 5878 expect(method.typeParameters, hasLength(0)); |
5733 expect(method.isAbstract, isFalse); | 5879 expect(method.isAbstract, isFalse); |
5734 expect(method.isExternal, isTrue); | 5880 expect(method.isExternal, isTrue); |
5735 expect(method.isStatic, isFalse); | 5881 expect(method.isStatic, isFalse); |
5736 expect(method.isSynthetic, isFalse); | 5882 expect(method.isSynthetic, isFalse); |
5737 } | 5883 } |
5738 | 5884 |
5739 void test_visitMethodDeclaration_getter() { | 5885 void test_visitMethodDeclaration_getter() { |
| 5886 // get m() {} |
5740 ElementHolder holder = new ElementHolder(); | 5887 ElementHolder holder = new ElementHolder(); |
5741 ElementBuilder builder = new ElementBuilder(holder); | 5888 ElementBuilder builder = new ElementBuilder(holder); |
5742 String methodName = "m"; | 5889 String methodName = "m"; |
5743 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 5890 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5744 null, | 5891 null, |
5745 null, | 5892 null, |
5746 Keyword.GET, | 5893 Keyword.GET, |
5747 null, | 5894 null, |
5748 AstFactory.identifier3(methodName), | 5895 AstFactory.identifier3(methodName), |
5749 AstFactory.formalParameterList(), | 5896 AstFactory.formalParameterList(), |
5750 AstFactory.blockFunctionBody2()); | 5897 AstFactory.blockFunctionBody2()); |
5751 methodDeclaration.accept(builder); | 5898 methodDeclaration.accept(builder); |
| 5899 |
5752 List<FieldElement> fields = holder.fields; | 5900 List<FieldElement> fields = holder.fields; |
5753 expect(fields, hasLength(1)); | 5901 expect(fields, hasLength(1)); |
5754 FieldElement field = fields[0]; | 5902 FieldElement field = fields[0]; |
5755 expect(field, isNotNull); | 5903 expect(field, isNotNull); |
5756 expect(field.name, methodName); | 5904 expect(field.name, methodName); |
5757 expect(field.isSynthetic, isTrue); | 5905 expect(field.isSynthetic, isTrue); |
5758 expect(field.setter, isNull); | 5906 expect(field.setter, isNull); |
5759 PropertyAccessorElement getter = field.getter; | 5907 PropertyAccessorElement getter = field.getter; |
5760 expect(getter, isNotNull); | 5908 expect(getter, isNotNull); |
| 5909 expect(getter.hasImplicitReturnType, isTrue); |
5761 expect(getter.isAbstract, isFalse); | 5910 expect(getter.isAbstract, isFalse); |
5762 expect(getter.isExternal, isFalse); | 5911 expect(getter.isExternal, isFalse); |
5763 expect(getter.isGetter, isTrue); | 5912 expect(getter.isGetter, isTrue); |
5764 expect(getter.isSynthetic, isFalse); | 5913 expect(getter.isSynthetic, isFalse); |
5765 expect(getter.name, methodName); | 5914 expect(getter.name, methodName); |
5766 expect(getter.variable, field); | 5915 expect(getter.variable, field); |
5767 expect(getter.functions, hasLength(0)); | 5916 expect(getter.functions, hasLength(0)); |
5768 expect(getter.labels, hasLength(0)); | 5917 expect(getter.labels, hasLength(0)); |
5769 expect(getter.localVariables, hasLength(0)); | 5918 expect(getter.localVariables, hasLength(0)); |
5770 expect(getter.parameters, hasLength(0)); | 5919 expect(getter.parameters, hasLength(0)); |
5771 } | 5920 } |
5772 | 5921 |
5773 void test_visitMethodDeclaration_getter_abstract() { | 5922 void test_visitMethodDeclaration_getter_abstract() { |
| 5923 // get m(); |
5774 ElementHolder holder = new ElementHolder(); | 5924 ElementHolder holder = new ElementHolder(); |
5775 ElementBuilder builder = new ElementBuilder(holder); | 5925 ElementBuilder builder = new ElementBuilder(holder); |
5776 String methodName = "m"; | 5926 String methodName = "m"; |
5777 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 5927 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5778 null, | 5928 null, |
5779 null, | 5929 null, |
5780 Keyword.GET, | 5930 Keyword.GET, |
5781 null, | 5931 null, |
5782 AstFactory.identifier3(methodName), | 5932 AstFactory.identifier3(methodName), |
5783 AstFactory.formalParameterList(), | 5933 AstFactory.formalParameterList(), |
5784 AstFactory.emptyFunctionBody()); | 5934 AstFactory.emptyFunctionBody()); |
5785 methodDeclaration.accept(builder); | 5935 methodDeclaration.accept(builder); |
| 5936 |
5786 List<FieldElement> fields = holder.fields; | 5937 List<FieldElement> fields = holder.fields; |
5787 expect(fields, hasLength(1)); | 5938 expect(fields, hasLength(1)); |
5788 FieldElement field = fields[0]; | 5939 FieldElement field = fields[0]; |
5789 expect(field, isNotNull); | 5940 expect(field, isNotNull); |
5790 expect(field.name, methodName); | 5941 expect(field.name, methodName); |
5791 expect(field.isSynthetic, isTrue); | 5942 expect(field.isSynthetic, isTrue); |
5792 expect(field.setter, isNull); | 5943 expect(field.setter, isNull); |
5793 PropertyAccessorElement getter = field.getter; | 5944 PropertyAccessorElement getter = field.getter; |
5794 expect(getter, isNotNull); | 5945 expect(getter, isNotNull); |
| 5946 expect(getter.hasImplicitReturnType, isTrue); |
5795 expect(getter.isAbstract, isTrue); | 5947 expect(getter.isAbstract, isTrue); |
5796 expect(getter.isExternal, isFalse); | 5948 expect(getter.isExternal, isFalse); |
5797 expect(getter.isGetter, isTrue); | 5949 expect(getter.isGetter, isTrue); |
5798 expect(getter.isSynthetic, isFalse); | 5950 expect(getter.isSynthetic, isFalse); |
5799 expect(getter.name, methodName); | 5951 expect(getter.name, methodName); |
5800 expect(getter.variable, field); | 5952 expect(getter.variable, field); |
5801 expect(getter.functions, hasLength(0)); | 5953 expect(getter.functions, hasLength(0)); |
5802 expect(getter.labels, hasLength(0)); | 5954 expect(getter.labels, hasLength(0)); |
5803 expect(getter.localVariables, hasLength(0)); | 5955 expect(getter.localVariables, hasLength(0)); |
5804 expect(getter.parameters, hasLength(0)); | 5956 expect(getter.parameters, hasLength(0)); |
5805 } | 5957 } |
5806 | 5958 |
5807 void test_visitMethodDeclaration_getter_external() { | 5959 void test_visitMethodDeclaration_getter_external() { |
| 5960 // external get m(); |
5808 ElementHolder holder = new ElementHolder(); | 5961 ElementHolder holder = new ElementHolder(); |
5809 ElementBuilder builder = new ElementBuilder(holder); | 5962 ElementBuilder builder = new ElementBuilder(holder); |
5810 String methodName = "m"; | 5963 String methodName = "m"; |
5811 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( | 5964 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( |
5812 null, | 5965 null, |
5813 null, | 5966 null, |
5814 Keyword.GET, | 5967 Keyword.GET, |
5815 null, | 5968 null, |
5816 AstFactory.identifier3(methodName), | 5969 AstFactory.identifier3(methodName), |
5817 AstFactory.formalParameterList()); | 5970 AstFactory.formalParameterList()); |
5818 methodDeclaration.externalKeyword = | 5971 methodDeclaration.externalKeyword = |
5819 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 5972 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
5820 methodDeclaration.accept(builder); | 5973 methodDeclaration.accept(builder); |
| 5974 |
5821 List<FieldElement> fields = holder.fields; | 5975 List<FieldElement> fields = holder.fields; |
5822 expect(fields, hasLength(1)); | 5976 expect(fields, hasLength(1)); |
5823 FieldElement field = fields[0]; | 5977 FieldElement field = fields[0]; |
5824 expect(field, isNotNull); | 5978 expect(field, isNotNull); |
5825 expect(field.name, methodName); | 5979 expect(field.name, methodName); |
5826 expect(field.isSynthetic, isTrue); | 5980 expect(field.isSynthetic, isTrue); |
5827 expect(field.setter, isNull); | 5981 expect(field.setter, isNull); |
5828 PropertyAccessorElement getter = field.getter; | 5982 PropertyAccessorElement getter = field.getter; |
5829 expect(getter, isNotNull); | 5983 expect(getter, isNotNull); |
| 5984 expect(getter.hasImplicitReturnType, isTrue); |
5830 expect(getter.isAbstract, isFalse); | 5985 expect(getter.isAbstract, isFalse); |
5831 expect(getter.isExternal, isTrue); | 5986 expect(getter.isExternal, isTrue); |
5832 expect(getter.isGetter, isTrue); | 5987 expect(getter.isGetter, isTrue); |
5833 expect(getter.isSynthetic, isFalse); | 5988 expect(getter.isSynthetic, isFalse); |
5834 expect(getter.name, methodName); | 5989 expect(getter.name, methodName); |
5835 expect(getter.variable, field); | 5990 expect(getter.variable, field); |
5836 expect(getter.functions, hasLength(0)); | 5991 expect(getter.functions, hasLength(0)); |
5837 expect(getter.labels, hasLength(0)); | 5992 expect(getter.labels, hasLength(0)); |
5838 expect(getter.localVariables, hasLength(0)); | 5993 expect(getter.localVariables, hasLength(0)); |
5839 expect(getter.parameters, hasLength(0)); | 5994 expect(getter.parameters, hasLength(0)); |
5840 } | 5995 } |
5841 | 5996 |
5842 void test_visitMethodDeclaration_minimal() { | 5997 void test_visitMethodDeclaration_minimal() { |
| 5998 // T m() {} |
5843 ElementHolder holder = new ElementHolder(); | 5999 ElementHolder holder = new ElementHolder(); |
5844 ElementBuilder builder = new ElementBuilder(holder); | 6000 ElementBuilder builder = new ElementBuilder(holder); |
5845 String methodName = "m"; | 6001 String methodName = "m"; |
5846 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6002 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5847 null, | 6003 null, |
5848 null, | 6004 AstFactory.typeName4('T'), |
5849 null, | 6005 null, |
5850 null, | 6006 null, |
5851 AstFactory.identifier3(methodName), | 6007 AstFactory.identifier3(methodName), |
5852 AstFactory.formalParameterList(), | 6008 AstFactory.formalParameterList(), |
5853 AstFactory.blockFunctionBody2()); | 6009 AstFactory.blockFunctionBody2()); |
5854 methodDeclaration.accept(builder); | 6010 methodDeclaration.accept(builder); |
5855 List<MethodElement> methods = holder.methods; | 6011 List<MethodElement> methods = holder.methods; |
5856 expect(methods, hasLength(1)); | 6012 expect(methods, hasLength(1)); |
5857 MethodElement method = methods[0]; | 6013 MethodElement method = methods[0]; |
5858 expect(method, isNotNull); | 6014 expect(method, isNotNull); |
| 6015 expect(method.hasImplicitReturnType, isFalse); |
5859 expect(method.name, methodName); | 6016 expect(method.name, methodName); |
5860 expect(method.functions, hasLength(0)); | 6017 expect(method.functions, hasLength(0)); |
5861 expect(method.labels, hasLength(0)); | 6018 expect(method.labels, hasLength(0)); |
5862 expect(method.localVariables, hasLength(0)); | 6019 expect(method.localVariables, hasLength(0)); |
5863 expect(method.parameters, hasLength(0)); | 6020 expect(method.parameters, hasLength(0)); |
5864 expect(method.typeParameters, hasLength(0)); | 6021 expect(method.typeParameters, hasLength(0)); |
5865 expect(method.isAbstract, isFalse); | 6022 expect(method.isAbstract, isFalse); |
5866 expect(method.isExternal, isFalse); | 6023 expect(method.isExternal, isFalse); |
5867 expect(method.isStatic, isFalse); | 6024 expect(method.isStatic, isFalse); |
5868 expect(method.isSynthetic, isFalse); | 6025 expect(method.isSynthetic, isFalse); |
5869 } | 6026 } |
5870 | 6027 |
5871 void test_visitMethodDeclaration_operator() { | 6028 void test_visitMethodDeclaration_operator() { |
| 6029 // operator +(addend) {} |
5872 ElementHolder holder = new ElementHolder(); | 6030 ElementHolder holder = new ElementHolder(); |
5873 ElementBuilder builder = new ElementBuilder(holder); | 6031 ElementBuilder builder = new ElementBuilder(holder); |
5874 String methodName = "+"; | 6032 String methodName = "+"; |
5875 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6033 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5876 null, | 6034 null, |
5877 null, | 6035 null, |
5878 null, | 6036 null, |
5879 Keyword.OPERATOR, | 6037 Keyword.OPERATOR, |
5880 AstFactory.identifier3(methodName), | 6038 AstFactory.identifier3(methodName), |
5881 AstFactory | 6039 AstFactory |
5882 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]), | 6040 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]), |
5883 AstFactory.blockFunctionBody2()); | 6041 AstFactory.blockFunctionBody2()); |
5884 methodDeclaration.accept(builder); | 6042 methodDeclaration.accept(builder); |
| 6043 |
5885 List<MethodElement> methods = holder.methods; | 6044 List<MethodElement> methods = holder.methods; |
5886 expect(methods, hasLength(1)); | 6045 expect(methods, hasLength(1)); |
5887 MethodElement method = methods[0]; | 6046 MethodElement method = methods[0]; |
5888 expect(method, isNotNull); | 6047 expect(method, isNotNull); |
| 6048 expect(method.hasImplicitReturnType, isTrue); |
5889 expect(method.name, methodName); | 6049 expect(method.name, methodName); |
5890 expect(method.functions, hasLength(0)); | 6050 expect(method.functions, hasLength(0)); |
5891 expect(method.labels, hasLength(0)); | 6051 expect(method.labels, hasLength(0)); |
5892 expect(method.localVariables, hasLength(0)); | 6052 expect(method.localVariables, hasLength(0)); |
5893 expect(method.parameters, hasLength(1)); | 6053 expect(method.parameters, hasLength(1)); |
5894 expect(method.typeParameters, hasLength(0)); | 6054 expect(method.typeParameters, hasLength(0)); |
5895 expect(method.isAbstract, isFalse); | 6055 expect(method.isAbstract, isFalse); |
5896 expect(method.isExternal, isFalse); | 6056 expect(method.isExternal, isFalse); |
5897 expect(method.isStatic, isFalse); | 6057 expect(method.isStatic, isFalse); |
5898 expect(method.isSynthetic, isFalse); | 6058 expect(method.isSynthetic, isFalse); |
5899 } | 6059 } |
5900 | 6060 |
5901 void test_visitMethodDeclaration_setter() { | 6061 void test_visitMethodDeclaration_setter() { |
| 6062 // set m() {} |
5902 ElementHolder holder = new ElementHolder(); | 6063 ElementHolder holder = new ElementHolder(); |
5903 ElementBuilder builder = new ElementBuilder(holder); | 6064 ElementBuilder builder = new ElementBuilder(holder); |
5904 String methodName = "m"; | 6065 String methodName = "m"; |
5905 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6066 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5906 null, | 6067 null, |
5907 null, | 6068 null, |
5908 Keyword.SET, | 6069 Keyword.SET, |
5909 null, | 6070 null, |
5910 AstFactory.identifier3(methodName), | 6071 AstFactory.identifier3(methodName), |
5911 AstFactory.formalParameterList(), | 6072 AstFactory.formalParameterList(), |
5912 AstFactory.blockFunctionBody2()); | 6073 AstFactory.blockFunctionBody2()); |
5913 methodDeclaration.accept(builder); | 6074 methodDeclaration.accept(builder); |
| 6075 |
5914 List<FieldElement> fields = holder.fields; | 6076 List<FieldElement> fields = holder.fields; |
5915 expect(fields, hasLength(1)); | 6077 expect(fields, hasLength(1)); |
5916 FieldElement field = fields[0]; | 6078 FieldElement field = fields[0]; |
5917 expect(field, isNotNull); | 6079 expect(field, isNotNull); |
5918 expect(field.name, methodName); | 6080 expect(field.name, methodName); |
5919 expect(field.isSynthetic, isTrue); | 6081 expect(field.isSynthetic, isTrue); |
5920 expect(field.getter, isNull); | 6082 expect(field.getter, isNull); |
5921 PropertyAccessorElement setter = field.setter; | 6083 PropertyAccessorElement setter = field.setter; |
5922 expect(setter, isNotNull); | 6084 expect(setter, isNotNull); |
| 6085 expect(setter.hasImplicitReturnType, isFalse); |
5923 expect(setter.isAbstract, isFalse); | 6086 expect(setter.isAbstract, isFalse); |
5924 expect(setter.isExternal, isFalse); | 6087 expect(setter.isExternal, isFalse); |
5925 expect(setter.isSetter, isTrue); | 6088 expect(setter.isSetter, isTrue); |
5926 expect(setter.isSynthetic, isFalse); | 6089 expect(setter.isSynthetic, isFalse); |
5927 expect(setter.name, "$methodName="); | 6090 expect(setter.name, "$methodName="); |
5928 expect(setter.displayName, methodName); | 6091 expect(setter.displayName, methodName); |
5929 expect(setter.variable, field); | 6092 expect(setter.variable, field); |
5930 expect(setter.functions, hasLength(0)); | 6093 expect(setter.functions, hasLength(0)); |
5931 expect(setter.labels, hasLength(0)); | 6094 expect(setter.labels, hasLength(0)); |
5932 expect(setter.localVariables, hasLength(0)); | 6095 expect(setter.localVariables, hasLength(0)); |
5933 expect(setter.parameters, hasLength(0)); | 6096 expect(setter.parameters, hasLength(0)); |
5934 } | 6097 } |
5935 | 6098 |
5936 void test_visitMethodDeclaration_setter_abstract() { | 6099 void test_visitMethodDeclaration_setter_abstract() { |
| 6100 // set m(); |
5937 ElementHolder holder = new ElementHolder(); | 6101 ElementHolder holder = new ElementHolder(); |
5938 ElementBuilder builder = new ElementBuilder(holder); | 6102 ElementBuilder builder = new ElementBuilder(holder); |
5939 String methodName = "m"; | 6103 String methodName = "m"; |
5940 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6104 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
5941 null, | 6105 null, |
5942 null, | 6106 null, |
5943 Keyword.SET, | 6107 Keyword.SET, |
5944 null, | 6108 null, |
5945 AstFactory.identifier3(methodName), | 6109 AstFactory.identifier3(methodName), |
5946 AstFactory.formalParameterList(), | 6110 AstFactory.formalParameterList(), |
5947 AstFactory.emptyFunctionBody()); | 6111 AstFactory.emptyFunctionBody()); |
5948 methodDeclaration.accept(builder); | 6112 methodDeclaration.accept(builder); |
| 6113 |
5949 List<FieldElement> fields = holder.fields; | 6114 List<FieldElement> fields = holder.fields; |
5950 expect(fields, hasLength(1)); | 6115 expect(fields, hasLength(1)); |
5951 FieldElement field = fields[0]; | 6116 FieldElement field = fields[0]; |
5952 expect(field, isNotNull); | 6117 expect(field, isNotNull); |
5953 expect(field.name, methodName); | 6118 expect(field.name, methodName); |
5954 expect(field.isSynthetic, isTrue); | 6119 expect(field.isSynthetic, isTrue); |
5955 expect(field.getter, isNull); | 6120 expect(field.getter, isNull); |
5956 PropertyAccessorElement setter = field.setter; | 6121 PropertyAccessorElement setter = field.setter; |
5957 expect(setter, isNotNull); | 6122 expect(setter, isNotNull); |
| 6123 expect(setter.hasImplicitReturnType, isFalse); |
5958 expect(setter.isAbstract, isTrue); | 6124 expect(setter.isAbstract, isTrue); |
5959 expect(setter.isExternal, isFalse); | 6125 expect(setter.isExternal, isFalse); |
5960 expect(setter.isSetter, isTrue); | 6126 expect(setter.isSetter, isTrue); |
5961 expect(setter.isSynthetic, isFalse); | 6127 expect(setter.isSynthetic, isFalse); |
5962 expect(setter.name, "$methodName="); | 6128 expect(setter.name, "$methodName="); |
5963 expect(setter.displayName, methodName); | 6129 expect(setter.displayName, methodName); |
5964 expect(setter.variable, field); | 6130 expect(setter.variable, field); |
5965 expect(setter.functions, hasLength(0)); | 6131 expect(setter.functions, hasLength(0)); |
5966 expect(setter.labels, hasLength(0)); | 6132 expect(setter.labels, hasLength(0)); |
5967 expect(setter.localVariables, hasLength(0)); | 6133 expect(setter.localVariables, hasLength(0)); |
5968 expect(setter.parameters, hasLength(0)); | 6134 expect(setter.parameters, hasLength(0)); |
5969 } | 6135 } |
5970 | 6136 |
5971 void test_visitMethodDeclaration_setter_external() { | 6137 void test_visitMethodDeclaration_setter_external() { |
| 6138 // external m(); |
5972 ElementHolder holder = new ElementHolder(); | 6139 ElementHolder holder = new ElementHolder(); |
5973 ElementBuilder builder = new ElementBuilder(holder); | 6140 ElementBuilder builder = new ElementBuilder(holder); |
5974 String methodName = "m"; | 6141 String methodName = "m"; |
5975 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( | 6142 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( |
5976 null, | 6143 null, |
5977 null, | 6144 null, |
5978 Keyword.SET, | 6145 Keyword.SET, |
5979 null, | 6146 null, |
5980 AstFactory.identifier3(methodName), | 6147 AstFactory.identifier3(methodName), |
5981 AstFactory.formalParameterList()); | 6148 AstFactory.formalParameterList()); |
5982 methodDeclaration.externalKeyword = | 6149 methodDeclaration.externalKeyword = |
5983 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 6150 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
5984 methodDeclaration.accept(builder); | 6151 methodDeclaration.accept(builder); |
| 6152 |
5985 List<FieldElement> fields = holder.fields; | 6153 List<FieldElement> fields = holder.fields; |
5986 expect(fields, hasLength(1)); | 6154 expect(fields, hasLength(1)); |
5987 FieldElement field = fields[0]; | 6155 FieldElement field = fields[0]; |
5988 expect(field, isNotNull); | 6156 expect(field, isNotNull); |
5989 expect(field.name, methodName); | 6157 expect(field.name, methodName); |
5990 expect(field.isSynthetic, isTrue); | 6158 expect(field.isSynthetic, isTrue); |
5991 expect(field.getter, isNull); | 6159 expect(field.getter, isNull); |
5992 PropertyAccessorElement setter = field.setter; | 6160 PropertyAccessorElement setter = field.setter; |
5993 expect(setter, isNotNull); | 6161 expect(setter, isNotNull); |
| 6162 expect(setter.hasImplicitReturnType, isFalse); |
5994 expect(setter.isAbstract, isFalse); | 6163 expect(setter.isAbstract, isFalse); |
5995 expect(setter.isExternal, isTrue); | 6164 expect(setter.isExternal, isTrue); |
5996 expect(setter.isSetter, isTrue); | 6165 expect(setter.isSetter, isTrue); |
5997 expect(setter.isSynthetic, isFalse); | 6166 expect(setter.isSynthetic, isFalse); |
5998 expect(setter.name, "$methodName="); | 6167 expect(setter.name, "$methodName="); |
5999 expect(setter.displayName, methodName); | 6168 expect(setter.displayName, methodName); |
6000 expect(setter.variable, field); | 6169 expect(setter.variable, field); |
6001 expect(setter.functions, hasLength(0)); | 6170 expect(setter.functions, hasLength(0)); |
6002 expect(setter.labels, hasLength(0)); | 6171 expect(setter.labels, hasLength(0)); |
6003 expect(setter.localVariables, hasLength(0)); | 6172 expect(setter.localVariables, hasLength(0)); |
6004 expect(setter.parameters, hasLength(0)); | 6173 expect(setter.parameters, hasLength(0)); |
6005 } | 6174 } |
6006 | 6175 |
6007 void test_visitMethodDeclaration_static() { | 6176 void test_visitMethodDeclaration_static() { |
| 6177 // static m() {} |
6008 ElementHolder holder = new ElementHolder(); | 6178 ElementHolder holder = new ElementHolder(); |
6009 ElementBuilder builder = new ElementBuilder(holder); | 6179 ElementBuilder builder = new ElementBuilder(holder); |
6010 String methodName = "m"; | 6180 String methodName = "m"; |
6011 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6181 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
6012 Keyword.STATIC, | 6182 Keyword.STATIC, |
6013 null, | 6183 null, |
6014 null, | 6184 null, |
6015 null, | 6185 null, |
6016 AstFactory.identifier3(methodName), | 6186 AstFactory.identifier3(methodName), |
6017 AstFactory.formalParameterList(), | 6187 AstFactory.formalParameterList(), |
6018 AstFactory.blockFunctionBody2()); | 6188 AstFactory.blockFunctionBody2()); |
6019 methodDeclaration.accept(builder); | 6189 methodDeclaration.accept(builder); |
6020 List<MethodElement> methods = holder.methods; | 6190 List<MethodElement> methods = holder.methods; |
6021 expect(methods, hasLength(1)); | 6191 expect(methods, hasLength(1)); |
6022 MethodElement method = methods[0]; | 6192 MethodElement method = methods[0]; |
6023 expect(method, isNotNull); | 6193 expect(method, isNotNull); |
| 6194 expect(method.hasImplicitReturnType, isTrue); |
6024 expect(method.name, methodName); | 6195 expect(method.name, methodName); |
6025 expect(method.functions, hasLength(0)); | 6196 expect(method.functions, hasLength(0)); |
6026 expect(method.labels, hasLength(0)); | 6197 expect(method.labels, hasLength(0)); |
6027 expect(method.localVariables, hasLength(0)); | 6198 expect(method.localVariables, hasLength(0)); |
6028 expect(method.parameters, hasLength(0)); | 6199 expect(method.parameters, hasLength(0)); |
6029 expect(method.typeParameters, hasLength(0)); | 6200 expect(method.typeParameters, hasLength(0)); |
6030 expect(method.isAbstract, isFalse); | 6201 expect(method.isAbstract, isFalse); |
6031 expect(method.isExternal, isFalse); | 6202 expect(method.isExternal, isFalse); |
6032 expect(method.isStatic, isTrue); | 6203 expect(method.isStatic, isTrue); |
6033 expect(method.isSynthetic, isFalse); | 6204 expect(method.isSynthetic, isFalse); |
6034 } | 6205 } |
6035 | 6206 |
6036 void test_visitMethodDeclaration_typeParameters() { | 6207 void test_visitMethodDeclaration_typeParameters() { |
| 6208 // m<E>() {} |
6037 ElementHolder holder = new ElementHolder(); | 6209 ElementHolder holder = new ElementHolder(); |
6038 ElementBuilder builder = new ElementBuilder(holder); | 6210 ElementBuilder builder = new ElementBuilder(holder); |
6039 String methodName = "m"; | 6211 String methodName = "m"; |
6040 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6212 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
6041 null, | 6213 null, |
6042 null, | 6214 null, |
6043 null, | 6215 null, |
6044 null, | 6216 null, |
6045 AstFactory.identifier3(methodName), | 6217 AstFactory.identifier3(methodName), |
6046 AstFactory.formalParameterList(), | 6218 AstFactory.formalParameterList(), |
6047 AstFactory.blockFunctionBody2()); | 6219 AstFactory.blockFunctionBody2()); |
6048 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']); | 6220 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']); |
6049 methodDeclaration.accept(builder); | 6221 methodDeclaration.accept(builder); |
| 6222 |
6050 List<MethodElement> methods = holder.methods; | 6223 List<MethodElement> methods = holder.methods; |
6051 expect(methods, hasLength(1)); | 6224 expect(methods, hasLength(1)); |
6052 MethodElement method = methods[0]; | 6225 MethodElement method = methods[0]; |
6053 expect(method, isNotNull); | 6226 expect(method, isNotNull); |
| 6227 expect(method.hasImplicitReturnType, isTrue); |
6054 expect(method.name, methodName); | 6228 expect(method.name, methodName); |
6055 expect(method.functions, hasLength(0)); | 6229 expect(method.functions, hasLength(0)); |
6056 expect(method.labels, hasLength(0)); | 6230 expect(method.labels, hasLength(0)); |
6057 expect(method.localVariables, hasLength(0)); | 6231 expect(method.localVariables, hasLength(0)); |
6058 expect(method.parameters, hasLength(0)); | 6232 expect(method.parameters, hasLength(0)); |
6059 expect(method.typeParameters, hasLength(1)); | 6233 expect(method.typeParameters, hasLength(1)); |
6060 expect(method.isAbstract, isFalse); | 6234 expect(method.isAbstract, isFalse); |
6061 expect(method.isExternal, isFalse); | 6235 expect(method.isExternal, isFalse); |
6062 expect(method.isStatic, isFalse); | 6236 expect(method.isStatic, isFalse); |
6063 expect(method.isSynthetic, isFalse); | 6237 expect(method.isSynthetic, isFalse); |
6064 } | 6238 } |
6065 | 6239 |
6066 void test_visitMethodDeclaration_withMembers() { | 6240 void test_visitMethodDeclaration_withMembers() { |
| 6241 // m(p) { var v; try { l: return; } catch (e) {} } |
6067 ElementHolder holder = new ElementHolder(); | 6242 ElementHolder holder = new ElementHolder(); |
6068 ElementBuilder builder = new ElementBuilder(holder); | 6243 ElementBuilder builder = new ElementBuilder(holder); |
6069 String methodName = "m"; | 6244 String methodName = "m"; |
6070 String parameterName = "p"; | 6245 String parameterName = "p"; |
6071 String localVariableName = "v"; | 6246 String localVariableName = "v"; |
6072 String labelName = "l"; | 6247 String labelName = "l"; |
6073 String exceptionParameterName = "e"; | 6248 String exceptionParameterName = "e"; |
6074 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 6249 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
6075 null, | 6250 null, |
6076 null, | 6251 null, |
6077 null, | 6252 null, |
6078 null, | 6253 null, |
6079 AstFactory.identifier3(methodName), | 6254 AstFactory.identifier3(methodName), |
6080 AstFactory.formalParameterList( | 6255 AstFactory.formalParameterList( |
6081 [AstFactory.simpleFormalParameter3(parameterName)]), | 6256 [AstFactory.simpleFormalParameter3(parameterName)]), |
6082 AstFactory.blockFunctionBody2([ | 6257 AstFactory.blockFunctionBody2([ |
6083 AstFactory.variableDeclarationStatement2( | 6258 AstFactory.variableDeclarationStatement2( |
6084 Keyword.VAR, [AstFactory.variableDeclaration(localVariableName)]), | 6259 Keyword.VAR, [AstFactory.variableDeclaration(localVariableName)]), |
6085 AstFactory.tryStatement2( | 6260 AstFactory.tryStatement2( |
6086 AstFactory.block([ | 6261 AstFactory.block([ |
6087 AstFactory.labeledStatement([AstFactory.label2(labelName)], | 6262 AstFactory.labeledStatement([AstFactory.label2(labelName)], |
6088 AstFactory.returnStatement()) | 6263 AstFactory.returnStatement()) |
6089 ]), | 6264 ]), |
6090 [AstFactory.catchClause(exceptionParameterName)]) | 6265 [AstFactory.catchClause(exceptionParameterName)]) |
6091 ])); | 6266 ])); |
6092 methodDeclaration.accept(builder); | 6267 methodDeclaration.accept(builder); |
| 6268 |
6093 List<MethodElement> methods = holder.methods; | 6269 List<MethodElement> methods = holder.methods; |
6094 expect(methods, hasLength(1)); | 6270 expect(methods, hasLength(1)); |
6095 MethodElement method = methods[0]; | 6271 MethodElement method = methods[0]; |
6096 expect(method, isNotNull); | 6272 expect(method, isNotNull); |
| 6273 expect(method.hasImplicitReturnType, isTrue); |
6097 expect(method.name, methodName); | 6274 expect(method.name, methodName); |
6098 expect(method.typeParameters, hasLength(0)); | 6275 expect(method.typeParameters, hasLength(0)); |
6099 expect(method.isAbstract, isFalse); | 6276 expect(method.isAbstract, isFalse); |
6100 expect(method.isExternal, isFalse); | 6277 expect(method.isExternal, isFalse); |
6101 expect(method.isStatic, isFalse); | 6278 expect(method.isStatic, isFalse); |
6102 expect(method.isSynthetic, isFalse); | 6279 expect(method.isSynthetic, isFalse); |
6103 List<VariableElement> parameters = method.parameters; | 6280 List<VariableElement> parameters = method.parameters; |
6104 expect(parameters, hasLength(1)); | 6281 expect(parameters, hasLength(1)); |
6105 VariableElement parameter = parameters[0]; | 6282 VariableElement parameter = parameters[0]; |
6106 expect(parameter, isNotNull); | 6283 expect(parameter, isNotNull); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6146 SourceRange visibleRange = parameter.visibleRange; | 6323 SourceRange visibleRange = parameter.visibleRange; |
6147 expect(100, visibleRange.offset); | 6324 expect(100, visibleRange.offset); |
6148 expect(110, visibleRange.end); | 6325 expect(110, visibleRange.end); |
6149 } | 6326 } |
6150 expect(parameter.defaultValueCode, "42"); | 6327 expect(parameter.defaultValueCode, "42"); |
6151 FunctionElement initializer = parameter.initializer; | 6328 FunctionElement initializer = parameter.initializer; |
6152 expect(initializer, isNotNull); | 6329 expect(initializer, isNotNull); |
6153 expect(initializer.isSynthetic, isTrue); | 6330 expect(initializer.isSynthetic, isTrue); |
6154 } | 6331 } |
6155 | 6332 |
6156 void test_visitSimpleFormalParameter() { | 6333 void test_visitSimpleFormalParameter_noType() { |
| 6334 // p |
6157 ElementHolder holder = new ElementHolder(); | 6335 ElementHolder holder = new ElementHolder(); |
6158 ElementBuilder builder = new ElementBuilder(holder); | 6336 ElementBuilder builder = new ElementBuilder(holder); |
6159 String parameterName = "p"; | 6337 String parameterName = "p"; |
6160 SimpleFormalParameter formalParameter = | 6338 SimpleFormalParameter formalParameter = |
6161 AstFactory.simpleFormalParameter3(parameterName); | 6339 AstFactory.simpleFormalParameter3(parameterName); |
6162 _useParameterInMethod(formalParameter, 100, 110); | 6340 _useParameterInMethod(formalParameter, 100, 110); |
6163 formalParameter.accept(builder); | 6341 formalParameter.accept(builder); |
6164 List<ParameterElement> parameters = holder.parameters; | 6342 List<ParameterElement> parameters = holder.parameters; |
6165 expect(parameters, hasLength(1)); | 6343 expect(parameters, hasLength(1)); |
6166 ParameterElement parameter = parameters[0]; | 6344 ParameterElement parameter = parameters[0]; |
6167 expect(parameter, isNotNull); | 6345 expect(parameter, isNotNull); |
6168 expect(parameter.name, parameterName); | 6346 expect(parameter.hasImplicitType, isTrue); |
6169 expect(parameter.initializer, isNull); | 6347 expect(parameter.initializer, isNull); |
6170 expect(parameter.isConst, isFalse); | 6348 expect(parameter.isConst, isFalse); |
6171 expect(parameter.isFinal, isFalse); | 6349 expect(parameter.isFinal, isFalse); |
6172 expect(parameter.isSynthetic, isFalse); | 6350 expect(parameter.isSynthetic, isFalse); |
| 6351 expect(parameter.name, parameterName); |
6173 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 6352 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
6174 { | 6353 { |
6175 SourceRange visibleRange = parameter.visibleRange; | 6354 SourceRange visibleRange = parameter.visibleRange; |
| 6355 expect(100, visibleRange.offset); |
| 6356 expect(110, visibleRange.end); |
| 6357 } |
| 6358 } |
| 6359 |
| 6360 void test_visitSimpleFormalParameter_type() { |
| 6361 // T p |
| 6362 ElementHolder holder = new ElementHolder(); |
| 6363 ElementBuilder builder = new ElementBuilder(holder); |
| 6364 String parameterName = "p"; |
| 6365 SimpleFormalParameter formalParameter = AstFactory.simpleFormalParameter4( |
| 6366 AstFactory.typeName4('T'), parameterName); |
| 6367 _useParameterInMethod(formalParameter, 100, 110); |
| 6368 formalParameter.accept(builder); |
| 6369 List<ParameterElement> parameters = holder.parameters; |
| 6370 expect(parameters, hasLength(1)); |
| 6371 ParameterElement parameter = parameters[0]; |
| 6372 expect(parameter, isNotNull); |
| 6373 expect(parameter.hasImplicitType, isFalse); |
| 6374 expect(parameter.initializer, isNull); |
| 6375 expect(parameter.isConst, isFalse); |
| 6376 expect(parameter.isFinal, isFalse); |
| 6377 expect(parameter.isSynthetic, isFalse); |
| 6378 expect(parameter.name, parameterName); |
| 6379 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 6380 { |
| 6381 SourceRange visibleRange = parameter.visibleRange; |
6176 expect(100, visibleRange.offset); | 6382 expect(100, visibleRange.offset); |
6177 expect(110, visibleRange.end); | 6383 expect(110, visibleRange.end); |
6178 } | 6384 } |
6179 } | 6385 } |
6180 | 6386 |
6181 void test_visitTypeAlias_minimal() { | 6387 void test_visitTypeAlias_minimal() { |
6182 ElementHolder holder = new ElementHolder(); | 6388 ElementHolder holder = new ElementHolder(); |
6183 ElementBuilder builder = new ElementBuilder(holder); | 6389 ElementBuilder builder = new ElementBuilder(holder); |
6184 String aliasName = "F"; | 6390 String aliasName = "F"; |
6185 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null); | 6391 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6281 AstFactory.variableDeclarationStatement2(null, [variable]); | 6487 AstFactory.variableDeclarationStatement2(null, [variable]); |
6282 ConstructorDeclaration constructor = AstFactory.constructorDeclaration2( | 6488 ConstructorDeclaration constructor = AstFactory.constructorDeclaration2( |
6283 null, | 6489 null, |
6284 null, | 6490 null, |
6285 AstFactory.identifier3("C"), | 6491 AstFactory.identifier3("C"), |
6286 "C", | 6492 "C", |
6287 AstFactory.formalParameterList(), | 6493 AstFactory.formalParameterList(), |
6288 null, | 6494 null, |
6289 AstFactory.blockFunctionBody2([statement])); | 6495 AstFactory.blockFunctionBody2([statement])); |
6290 constructor.accept(builder); | 6496 constructor.accept(builder); |
| 6497 |
6291 List<ConstructorElement> constructors = holder.constructors; | 6498 List<ConstructorElement> constructors = holder.constructors; |
6292 expect(constructors, hasLength(1)); | 6499 expect(constructors, hasLength(1)); |
6293 List<LocalVariableElement> variableElements = | 6500 List<LocalVariableElement> variableElements = |
6294 constructors[0].localVariables; | 6501 constructors[0].localVariables; |
6295 expect(variableElements, hasLength(1)); | 6502 expect(variableElements, hasLength(1)); |
6296 LocalVariableElement variableElement = variableElements[0]; | 6503 LocalVariableElement variableElement = variableElements[0]; |
| 6504 expect(variableElement.hasImplicitType, isTrue); |
6297 expect(variableElement.name, variableName); | 6505 expect(variableElement.name, variableName); |
6298 } | 6506 } |
6299 | 6507 |
6300 void test_visitVariableDeclaration_inMethod() { | 6508 void test_visitVariableDeclaration_inMethod() { |
6301 ElementHolder holder = new ElementHolder(); | 6509 ElementHolder holder = new ElementHolder(); |
6302 ElementBuilder builder = new ElementBuilder(holder); | 6510 ElementBuilder builder = new ElementBuilder(holder); |
6303 // | 6511 // |
6304 // m() {var v;} | 6512 // m() {T v;} |
6305 // | 6513 // |
6306 String variableName = "v"; | 6514 String variableName = "v"; |
6307 VariableDeclaration variable = | 6515 VariableDeclaration variable = |
6308 AstFactory.variableDeclaration2(variableName, null); | 6516 AstFactory.variableDeclaration2(variableName, null); |
6309 Statement statement = | 6517 Statement statement = AstFactory.variableDeclarationStatement( |
6310 AstFactory.variableDeclarationStatement2(null, [variable]); | 6518 null, AstFactory.typeName4('T'), [variable]); |
6311 MethodDeclaration constructor = AstFactory.methodDeclaration2( | 6519 MethodDeclaration method = AstFactory.methodDeclaration2( |
6312 null, | 6520 null, |
6313 null, | 6521 null, |
6314 null, | 6522 null, |
6315 null, | 6523 null, |
6316 AstFactory.identifier3("m"), | 6524 AstFactory.identifier3("m"), |
6317 AstFactory.formalParameterList(), | 6525 AstFactory.formalParameterList(), |
6318 AstFactory.blockFunctionBody2([statement])); | 6526 AstFactory.blockFunctionBody2([statement])); |
6319 constructor.accept(builder); | 6527 method.accept(builder); |
| 6528 |
6320 List<MethodElement> methods = holder.methods; | 6529 List<MethodElement> methods = holder.methods; |
6321 expect(methods, hasLength(1)); | 6530 expect(methods, hasLength(1)); |
6322 List<LocalVariableElement> variableElements = methods[0].localVariables; | 6531 List<LocalVariableElement> variableElements = methods[0].localVariables; |
6323 expect(variableElements, hasLength(1)); | 6532 expect(variableElements, hasLength(1)); |
6324 LocalVariableElement variableElement = variableElements[0]; | 6533 LocalVariableElement variableElement = variableElements[0]; |
| 6534 expect(variableElement.hasImplicitType, isFalse); |
6325 expect(variableElement.name, variableName); | 6535 expect(variableElement.name, variableName); |
6326 } | 6536 } |
6327 | 6537 |
6328 void test_visitVariableDeclaration_localNestedInField() { | 6538 void test_visitVariableDeclaration_localNestedInFunction() { |
6329 ElementHolder holder = new ElementHolder(); | 6539 ElementHolder holder = new ElementHolder(); |
6330 ElementBuilder builder = new ElementBuilder(holder); | 6540 ElementBuilder builder = new ElementBuilder(holder); |
6331 // | 6541 // |
6332 // var f = () {var v;} | 6542 // var f = () {var v;}; |
6333 // | 6543 // |
6334 String variableName = "v"; | 6544 String variableName = "v"; |
6335 VariableDeclaration variable = | 6545 VariableDeclaration variable = |
6336 AstFactory.variableDeclaration2(variableName, null); | 6546 AstFactory.variableDeclaration2(variableName, null); |
6337 Statement statement = | 6547 Statement statement = |
6338 AstFactory.variableDeclarationStatement2(null, [variable]); | 6548 AstFactory.variableDeclarationStatement2(null, [variable]); |
6339 Expression initializer = AstFactory.functionExpression2( | 6549 Expression initializer = AstFactory.functionExpression2( |
6340 AstFactory.formalParameterList(), | 6550 AstFactory.formalParameterList(), |
6341 AstFactory.blockFunctionBody2([statement])); | 6551 AstFactory.blockFunctionBody2([statement])); |
6342 String fieldName = "f"; | 6552 String fieldName = "f"; |
6343 VariableDeclaration field = | 6553 VariableDeclaration field = |
6344 AstFactory.variableDeclaration2(fieldName, initializer); | 6554 AstFactory.variableDeclaration2(fieldName, initializer); |
6345 FieldDeclaration fieldDeclaration = | 6555 FieldDeclaration fieldDeclaration = |
6346 AstFactory.fieldDeclaration2(false, null, [field]); | 6556 AstFactory.fieldDeclaration2(false, null, [field]); |
6347 fieldDeclaration.accept(builder); | 6557 fieldDeclaration.accept(builder); |
| 6558 |
6348 List<FieldElement> variables = holder.fields; | 6559 List<FieldElement> variables = holder.fields; |
6349 expect(variables, hasLength(1)); | 6560 expect(variables, hasLength(1)); |
6350 FieldElement fieldElement = variables[0]; | 6561 FieldElement fieldElement = variables[0]; |
6351 expect(fieldElement, isNotNull); | 6562 expect(fieldElement, isNotNull); |
6352 FunctionElement initializerElement = fieldElement.initializer; | 6563 FunctionElement initializerElement = fieldElement.initializer; |
6353 expect(initializerElement, isNotNull); | 6564 expect(initializerElement, isNotNull); |
6354 List<FunctionElement> functionElements = initializerElement.functions; | 6565 List<FunctionElement> functionElements = initializerElement.functions; |
6355 expect(functionElements, hasLength(1)); | 6566 expect(functionElements, hasLength(1)); |
6356 List<LocalVariableElement> variableElements = | 6567 List<LocalVariableElement> variableElements = |
6357 functionElements[0].localVariables; | 6568 functionElements[0].localVariables; |
6358 expect(variableElements, hasLength(1)); | 6569 expect(variableElements, hasLength(1)); |
6359 LocalVariableElement variableElement = variableElements[0]; | 6570 LocalVariableElement variableElement = variableElements[0]; |
6360 expect(variableElement.name, variableName); | 6571 expect(variableElement.hasImplicitType, isTrue); |
6361 expect(variableElement.isConst, isFalse); | 6572 expect(variableElement.isConst, isFalse); |
6362 expect(variableElement.isFinal, isFalse); | 6573 expect(variableElement.isFinal, isFalse); |
6363 expect(variableElement.isSynthetic, isFalse); | 6574 expect(variableElement.isSynthetic, isFalse); |
| 6575 expect(variableElement.name, variableName); |
6364 } | 6576 } |
6365 | 6577 |
6366 void test_visitVariableDeclaration_noInitializer() { | 6578 void test_visitVariableDeclaration_noInitializer() { |
| 6579 // var v; |
6367 ElementHolder holder = new ElementHolder(); | 6580 ElementHolder holder = new ElementHolder(); |
6368 ElementBuilder builder = new ElementBuilder(holder); | 6581 ElementBuilder builder = new ElementBuilder(holder); |
6369 String variableName = "v"; | 6582 String variableName = "v"; |
6370 VariableDeclaration variableDeclaration = | 6583 VariableDeclaration variableDeclaration = |
6371 AstFactory.variableDeclaration2(variableName, null); | 6584 AstFactory.variableDeclaration2(variableName, null); |
6372 AstFactory.variableDeclarationList2(null, [variableDeclaration]); | 6585 AstFactory.variableDeclarationList2(null, [variableDeclaration]); |
6373 variableDeclaration.accept(builder); | 6586 variableDeclaration.accept(builder); |
| 6587 |
6374 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 6588 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
6375 expect(variables, hasLength(1)); | 6589 expect(variables, hasLength(1)); |
6376 TopLevelVariableElement variable = variables[0]; | 6590 TopLevelVariableElement variable = variables[0]; |
6377 expect(variable, isNotNull); | 6591 expect(variable, isNotNull); |
| 6592 expect(variable.hasImplicitType, isTrue); |
6378 expect(variable.initializer, isNull); | 6593 expect(variable.initializer, isNull); |
6379 expect(variable.name, variableName); | 6594 expect(variable.name, variableName); |
6380 expect(variable.isConst, isFalse); | 6595 expect(variable.isConst, isFalse); |
6381 expect(variable.isFinal, isFalse); | 6596 expect(variable.isFinal, isFalse); |
6382 expect(variable.isSynthetic, isFalse); | 6597 expect(variable.isSynthetic, isFalse); |
6383 expect(variable.getter, isNotNull); | 6598 expect(variable.getter, isNotNull); |
6384 expect(variable.setter, isNotNull); | 6599 expect(variable.setter, isNotNull); |
6385 } | 6600 } |
6386 | 6601 |
6387 void test_visitVariableDeclaration_top_const_hasInitializer() { | 6602 void test_visitVariableDeclaration_top_const_hasInitializer() { |
| 6603 // const v = 42; |
6388 ElementHolder holder = new ElementHolder(); | 6604 ElementHolder holder = new ElementHolder(); |
6389 ElementBuilder builder = new ElementBuilder(holder); | 6605 ElementBuilder builder = new ElementBuilder(holder); |
6390 String variableName = "v"; | 6606 String variableName = "v"; |
6391 VariableDeclaration variableDeclaration = | 6607 VariableDeclaration variableDeclaration = |
6392 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42)); | 6608 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42)); |
6393 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]); | 6609 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]); |
6394 variableDeclaration.accept(builder); | 6610 variableDeclaration.accept(builder); |
| 6611 |
6395 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 6612 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
6396 expect(variables, hasLength(1)); | 6613 expect(variables, hasLength(1)); |
6397 TopLevelVariableElement variable = variables[0]; | 6614 TopLevelVariableElement variable = variables[0]; |
6398 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>()); | 6615 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>()); |
6399 expect(variable.initializer, isNotNull); | 6616 expect(variable.initializer, isNotNull); |
6400 expect(variable.name, variableName); | 6617 expect(variable.name, variableName); |
| 6618 expect(variable.hasImplicitType, isTrue); |
6401 expect(variable.isConst, isTrue); | 6619 expect(variable.isConst, isTrue); |
6402 expect(variable.isFinal, isFalse); | 6620 expect(variable.isFinal, isFalse); |
6403 expect(variable.isSynthetic, isFalse); | 6621 expect(variable.isSynthetic, isFalse); |
6404 expect(variable.getter, isNotNull); | 6622 expect(variable.getter, isNotNull); |
6405 expect(variable.setter, isNull); | 6623 expect(variable.setter, isNull); |
6406 } | 6624 } |
6407 | 6625 |
6408 void test_visitVariableDeclaration_top_final() { | 6626 void test_visitVariableDeclaration_top_final() { |
| 6627 // final v; |
6409 ElementHolder holder = new ElementHolder(); | 6628 ElementHolder holder = new ElementHolder(); |
6410 ElementBuilder builder = new ElementBuilder(holder); | 6629 ElementBuilder builder = new ElementBuilder(holder); |
6411 String variableName = "v"; | 6630 String variableName = "v"; |
6412 VariableDeclaration variableDeclaration = | 6631 VariableDeclaration variableDeclaration = |
6413 AstFactory.variableDeclaration2(variableName, null); | 6632 AstFactory.variableDeclaration2(variableName, null); |
6414 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); | 6633 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); |
6415 variableDeclaration.accept(builder); | 6634 variableDeclaration.accept(builder); |
6416 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 6635 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
6417 expect(variables, hasLength(1)); | 6636 expect(variables, hasLength(1)); |
6418 TopLevelVariableElement variable = variables[0]; | 6637 TopLevelVariableElement variable = variables[0]; |
6419 expect(variable, isNotNull); | 6638 expect(variable, isNotNull); |
| 6639 expect(variable.hasImplicitType, isTrue); |
6420 expect(variable.initializer, isNull); | 6640 expect(variable.initializer, isNull); |
6421 expect(variable.name, variableName); | 6641 expect(variable.name, variableName); |
6422 expect(variable.isConst, isFalse); | 6642 expect(variable.isConst, isFalse); |
6423 expect(variable.isFinal, isTrue); | 6643 expect(variable.isFinal, isTrue); |
6424 expect(variable.isSynthetic, isFalse); | 6644 expect(variable.isSynthetic, isFalse); |
6425 expect(variable.getter, isNotNull); | 6645 expect(variable.getter, isNotNull); |
6426 expect(variable.setter, isNull); | 6646 expect(variable.setter, isNull); |
6427 } | 6647 } |
6428 | 6648 |
6429 void _useParameterInMethod( | 6649 void _useParameterInMethod( |
(...skipping 2556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8986 if (_expectedExternalScriptName == null) { | 9206 if (_expectedExternalScriptName == null) { |
8987 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 9207 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
8988 } else { | 9208 } else { |
8989 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 9209 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
8990 String actualExternalScriptName = scriptSource.shortName; | 9210 String actualExternalScriptName = scriptSource.shortName; |
8991 expect(actualExternalScriptName, _expectedExternalScriptName, | 9211 expect(actualExternalScriptName, _expectedExternalScriptName, |
8992 reason: "script $scriptIndex"); | 9212 reason: "script $scriptIndex"); |
8993 } | 9213 } |
8994 } | 9214 } |
8995 } | 9215 } |
OLD | NEW |