| 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/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; |
| 7 import 'package:analyzer/file_system/physical_file_system.dart'; | 9 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 11 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 12 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 14 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/java_core.dart'; | 15 import 'package:analyzer/src/generated/java_core.dart'; |
| 14 import 'package:analyzer/src/generated/java_engine_io.dart'; | 16 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 15 import 'package:analyzer/src/generated/java_io.dart'; | 17 import 'package:analyzer/src/generated/java_io.dart'; |
| 16 import 'package:analyzer/src/generated/resolver.dart'; | 18 import 'package:analyzer/src/generated/resolver.dart'; |
| 17 import 'package:analyzer/src/generated/scanner.dart'; | 19 import 'package:analyzer/src/generated/scanner.dart'; |
| 18 import 'package:analyzer/src/generated/sdk.dart'; | 20 import 'package:analyzer/src/generated/sdk.dart'; |
| 19 import 'package:analyzer/src/generated/sdk_io.dart'; | 21 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 _setupVariableDeclaration("v", false, true); | 568 _setupVariableDeclaration("v", false, true); |
| 567 expect(_findConstants(), isEmpty); | 569 expect(_findConstants(), isEmpty); |
| 568 } | 570 } |
| 569 | 571 |
| 570 void test_visitVariableDeclaration_static_const_inClass() { | 572 void test_visitVariableDeclaration_static_const_inClass() { |
| 571 VariableDeclaration field = | 573 VariableDeclaration field = |
| 572 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); | 574 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); |
| 573 expect(_findConstants(), contains(field.element)); | 575 expect(_findConstants(), contains(field.element)); |
| 574 } | 576 } |
| 575 | 577 |
| 576 void test_visitVariableDeclaration_static_const_inClassWithConstConstructor()
{ | 578 void |
| 579 test_visitVariableDeclaration_static_const_inClassWithConstConstructor() { |
| 577 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, | 580 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, |
| 578 isStatic: true, hasConstConstructor: true); | 581 isStatic: true, hasConstConstructor: true); |
| 579 expect(_findConstants(), contains(field.element)); | 582 expect(_findConstants(), contains(field.element)); |
| 580 } | 583 } |
| 581 | 584 |
| 582 void test_visitVariableDeclaration_static_final_inClassWithConstConstructor()
{ | 585 void |
| 586 test_visitVariableDeclaration_static_final_inClassWithConstConstructor() { |
| 583 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 587 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
| 584 isStatic: true, hasConstConstructor: true); | 588 isStatic: true, hasConstConstructor: true); |
| 585 expect(_findConstants(), isNot(contains(field.element))); | 589 expect(_findConstants(), isNot(contains(field.element))); |
| 586 } | 590 } |
| 587 | 591 |
| 588 void test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstru
ctor() { | 592 void |
| 593 test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstruc
tor() { |
| 589 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | 594 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, |
| 590 isInitialized: false, hasConstConstructor: true); | 595 isInitialized: false, hasConstConstructor: true); |
| 591 expect(_findConstants(), isNot(contains(field.element))); | 596 expect(_findConstants(), isNot(contains(field.element))); |
| 592 } | 597 } |
| 593 | 598 |
| 594 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { | 599 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { |
| 595 _setupFieldDeclaration('C', 'f', Keyword.CONST, | 600 _setupFieldDeclaration('C', 'f', Keyword.CONST, |
| 596 isStatic: true, isInitialized: false); | 601 isStatic: true, isInitialized: false); |
| 597 expect(_findConstants(), isEmpty); | 602 expect(_findConstants(), isEmpty); |
| 598 } | 603 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 612 Set<ConstantEvaluationTarget> _findConstants() { | 617 Set<ConstantEvaluationTarget> _findConstants() { |
| 613 ConstantFinder finder = new ConstantFinder(_context, _source, _source); | 618 ConstantFinder finder = new ConstantFinder(_context, _source, _source); |
| 614 _node.accept(finder); | 619 _node.accept(finder); |
| 615 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; | 620 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; |
| 616 expect(constants, isNotNull); | 621 expect(constants, isNotNull); |
| 617 return constants; | 622 return constants; |
| 618 } | 623 } |
| 619 | 624 |
| 620 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { | 625 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { |
| 621 Keyword constKeyword = isConst ? Keyword.CONST : null; | 626 Keyword constKeyword = isConst ? Keyword.CONST : null; |
| 622 ConstructorDeclaration constructorDeclaration = AstFactory | 627 ConstructorDeclaration constructorDeclaration = |
| 623 .constructorDeclaration2( | 628 AstFactory.constructorDeclaration2( |
| 624 constKeyword, | 629 constKeyword, |
| 625 null, | 630 null, |
| 626 null, | 631 null, |
| 627 name, | 632 name, |
| 628 AstFactory.formalParameterList(), | 633 AstFactory.formalParameterList(), |
| 629 null, | 634 null, |
| 630 AstFactory.blockFunctionBody2()); | 635 AstFactory.blockFunctionBody2()); |
| 631 ClassElement classElement = ElementFactory.classElement2(name); | 636 ClassElement classElement = ElementFactory.classElement2(name); |
| 632 ConstructorElement element = | 637 ConstructorElement element = |
| 633 ElementFactory.constructorElement(classElement, name, isConst); | 638 ElementFactory.constructorElement(classElement, name, isConst); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 654 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2( | 659 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2( |
| 655 isStatic, keyword, <VariableDeclaration>[variableDeclaration]); | 660 isStatic, keyword, <VariableDeclaration>[variableDeclaration]); |
| 656 ClassDeclaration classDeclaration = | 661 ClassDeclaration classDeclaration = |
| 657 AstFactory.classDeclaration(null, className, null, null, null, null); | 662 AstFactory.classDeclaration(null, className, null, null, null, null); |
| 658 classDeclaration.members.add(fieldDeclaration); | 663 classDeclaration.members.add(fieldDeclaration); |
| 659 _node = classDeclaration; | 664 _node = classDeclaration; |
| 660 ClassElementImpl classElement = ElementFactory.classElement2(className); | 665 ClassElementImpl classElement = ElementFactory.classElement2(className); |
| 661 classElement.fields = <FieldElement>[fieldElement]; | 666 classElement.fields = <FieldElement>[fieldElement]; |
| 662 classDeclaration.name.staticElement = classElement; | 667 classDeclaration.name.staticElement = classElement; |
| 663 if (hasConstConstructor) { | 668 if (hasConstConstructor) { |
| 664 ConstructorDeclaration constructorDeclaration = AstFactory | 669 ConstructorDeclaration constructorDeclaration = |
| 665 .constructorDeclaration2( | 670 AstFactory.constructorDeclaration2( |
| 666 Keyword.CONST, | 671 Keyword.CONST, |
| 667 null, | 672 null, |
| 668 AstFactory.identifier3(className), | 673 AstFactory.identifier3(className), |
| 669 null, | 674 null, |
| 670 AstFactory.formalParameterList(), | 675 AstFactory.formalParameterList(), |
| 671 null, | 676 null, |
| 672 AstFactory.blockFunctionBody2()); | 677 AstFactory.blockFunctionBody2()); |
| 673 classDeclaration.members.add(constructorDeclaration); | 678 classDeclaration.members.add(constructorDeclaration); |
| 674 ConstructorElement constructorElement = | 679 ConstructorElement constructorElement = |
| 675 ElementFactory.constructorElement(classElement, '', true); | 680 ElementFactory.constructorElement(classElement, '', true); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 const A(int i, int j) : k = 2 * i + j; | 1325 const A(int i, int j) : k = 2 * i + j; |
| 1321 final int k; | 1326 final int k; |
| 1322 }'''); | 1327 }'''); |
| 1323 EvaluationResultImpl result = | 1328 EvaluationResultImpl result = |
| 1324 _evaluateTopLevelVariable(compilationUnit, "foo"); | 1329 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1325 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1330 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1326 expect(fields, hasLength(1)); | 1331 expect(fields, hasLength(1)); |
| 1327 _assertIntField(fields, "k", 13); | 1332 _assertIntField(fields, "k", 13); |
| 1328 } | 1333 } |
| 1329 | 1334 |
| 1330 void test_instanceCreationExpression_computedField_namedOptionalWithDefault()
{ | 1335 void |
| 1336 test_instanceCreationExpression_computedField_namedOptionalWithDefault() { |
| 1331 _checkInstanceCreationOptionalParams(false, true, true); | 1337 _checkInstanceCreationOptionalParams(false, true, true); |
| 1332 } | 1338 } |
| 1333 | 1339 |
| 1334 void test_instanceCreationExpression_computedField_namedOptionalWithoutDefault
() { | 1340 void |
| 1341 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault(
) { |
| 1335 _checkInstanceCreationOptionalParams(false, true, false); | 1342 _checkInstanceCreationOptionalParams(false, true, false); |
| 1336 } | 1343 } |
| 1337 | 1344 |
| 1338 void test_instanceCreationExpression_computedField_unnamedOptionalWithDefault(
) { | 1345 void |
| 1346 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault()
{ |
| 1339 _checkInstanceCreationOptionalParams(false, false, true); | 1347 _checkInstanceCreationOptionalParams(false, false, true); |
| 1340 } | 1348 } |
| 1341 | 1349 |
| 1342 void test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefau
lt() { | 1350 void |
| 1351 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefaul
t() { |
| 1343 _checkInstanceCreationOptionalParams(false, false, false); | 1352 _checkInstanceCreationOptionalParams(false, false, false); |
| 1344 } | 1353 } |
| 1345 | 1354 |
| 1346 void test_instanceCreationExpression_computedField_usesConstConstructor() { | 1355 void test_instanceCreationExpression_computedField_usesConstConstructor() { |
| 1347 CompilationUnit compilationUnit = resolveSource(r''' | 1356 CompilationUnit compilationUnit = resolveSource(r''' |
| 1348 const foo = const A(3); | 1357 const foo = const A(3); |
| 1349 class A { | 1358 class A { |
| 1350 const A(int i) : b = const B(4); | 1359 const A(int i) : b = const B(4); |
| 1351 final int b; | 1360 final int b; |
| 1352 } | 1361 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 int x; | 1434 int x; |
| 1426 const A(this.x) | 1435 const A(this.x) |
| 1427 }'''); | 1436 }'''); |
| 1428 EvaluationResultImpl result = | 1437 EvaluationResultImpl result = |
| 1429 _evaluateTopLevelVariable(compilationUnit, "foo"); | 1438 _evaluateTopLevelVariable(compilationUnit, "foo"); |
| 1430 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | 1439 Map<String, DartObjectImpl> fields = _assertType(result, "A"); |
| 1431 expect(fields, hasLength(1)); | 1440 expect(fields, hasLength(1)); |
| 1432 _assertIntField(fields, "x", 42); | 1441 _assertIntField(fields, "x", 42); |
| 1433 } | 1442 } |
| 1434 | 1443 |
| 1435 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDef
ault() { | 1444 void |
| 1445 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefa
ult() { |
| 1436 _checkInstanceCreationOptionalParams(true, true, true); | 1446 _checkInstanceCreationOptionalParams(true, true, true); |
| 1437 } | 1447 } |
| 1438 | 1448 |
| 1439 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithout
Default() { | 1449 void |
| 1450 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutD
efault() { |
| 1440 _checkInstanceCreationOptionalParams(true, true, false); | 1451 _checkInstanceCreationOptionalParams(true, true, false); |
| 1441 } | 1452 } |
| 1442 | 1453 |
| 1443 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithD
efault() { | 1454 void |
| 1455 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDe
fault() { |
| 1444 _checkInstanceCreationOptionalParams(true, false, true); | 1456 _checkInstanceCreationOptionalParams(true, false, true); |
| 1445 } | 1457 } |
| 1446 | 1458 |
| 1447 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWitho
utDefault() { | 1459 void |
| 1460 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithou
tDefault() { |
| 1448 _checkInstanceCreationOptionalParams(true, false, false); | 1461 _checkInstanceCreationOptionalParams(true, false, false); |
| 1449 } | 1462 } |
| 1450 | 1463 |
| 1451 void test_instanceCreationExpression_implicitSuper() { | 1464 void test_instanceCreationExpression_implicitSuper() { |
| 1452 CompilationUnit compilationUnit = resolveSource(r''' | 1465 CompilationUnit compilationUnit = resolveSource(r''' |
| 1453 const foo = const B(4); | 1466 const foo = const B(4); |
| 1454 class A { | 1467 class A { |
| 1455 const A() : x = 3; | 1468 const A() : x = 3; |
| 1456 final int x; | 1469 final int x; |
| 1457 } | 1470 } |
| (...skipping 3386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4844 expect(types, hasLength(1)); | 4857 expect(types, hasLength(1)); |
| 4845 ClassElement type = types[0]; | 4858 ClassElement type = types[0]; |
| 4846 expect(type.typeParameters, hasLength(1)); | 4859 expect(type.typeParameters, hasLength(1)); |
| 4847 expect(type.typeParameters[0].name, equals('T')); | 4860 expect(type.typeParameters[0].name, equals('T')); |
| 4848 } | 4861 } |
| 4849 | 4862 |
| 4850 void test_visitConstructorDeclaration_external() { | 4863 void test_visitConstructorDeclaration_external() { |
| 4851 ElementHolder holder = new ElementHolder(); | 4864 ElementHolder holder = new ElementHolder(); |
| 4852 ElementBuilder builder = new ElementBuilder(holder); | 4865 ElementBuilder builder = new ElementBuilder(holder); |
| 4853 String className = "A"; | 4866 String className = "A"; |
| 4854 ConstructorDeclaration constructorDeclaration = AstFactory | 4867 ConstructorDeclaration constructorDeclaration = |
| 4855 .constructorDeclaration2( | 4868 AstFactory.constructorDeclaration2( |
| 4856 null, | 4869 null, |
| 4857 null, | 4870 null, |
| 4858 AstFactory.identifier3(className), | 4871 AstFactory.identifier3(className), |
| 4859 null, | 4872 null, |
| 4860 AstFactory.formalParameterList(), | 4873 AstFactory.formalParameterList(), |
| 4861 null, | 4874 null, |
| 4862 AstFactory.blockFunctionBody2()); | 4875 AstFactory.blockFunctionBody2()); |
| 4863 constructorDeclaration.externalKeyword = | 4876 constructorDeclaration.externalKeyword = |
| 4864 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 4877 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| 4865 constructorDeclaration.accept(builder); | 4878 constructorDeclaration.accept(builder); |
| 4866 List<ConstructorElement> constructors = holder.constructors; | 4879 List<ConstructorElement> constructors = holder.constructors; |
| 4867 expect(constructors, hasLength(1)); | 4880 expect(constructors, hasLength(1)); |
| 4868 ConstructorElement constructor = constructors[0]; | 4881 ConstructorElement constructor = constructors[0]; |
| 4869 expect(constructor, isNotNull); | 4882 expect(constructor, isNotNull); |
| 4870 expect(constructor.isExternal, isTrue); | 4883 expect(constructor.isExternal, isTrue); |
| 4871 expect(constructor.isFactory, isFalse); | 4884 expect(constructor.isFactory, isFalse); |
| 4872 expect(constructor.name, ""); | 4885 expect(constructor.name, ""); |
| 4873 expect(constructor.functions, hasLength(0)); | 4886 expect(constructor.functions, hasLength(0)); |
| 4874 expect(constructor.labels, hasLength(0)); | 4887 expect(constructor.labels, hasLength(0)); |
| 4875 expect(constructor.localVariables, hasLength(0)); | 4888 expect(constructor.localVariables, hasLength(0)); |
| 4876 expect(constructor.parameters, hasLength(0)); | 4889 expect(constructor.parameters, hasLength(0)); |
| 4877 } | 4890 } |
| 4878 | 4891 |
| 4879 void test_visitConstructorDeclaration_factory() { | 4892 void test_visitConstructorDeclaration_factory() { |
| 4880 ElementHolder holder = new ElementHolder(); | 4893 ElementHolder holder = new ElementHolder(); |
| 4881 ElementBuilder builder = new ElementBuilder(holder); | 4894 ElementBuilder builder = new ElementBuilder(holder); |
| 4882 String className = "A"; | 4895 String className = "A"; |
| 4883 ConstructorDeclaration constructorDeclaration = AstFactory | 4896 ConstructorDeclaration constructorDeclaration = |
| 4884 .constructorDeclaration2( | 4897 AstFactory.constructorDeclaration2( |
| 4885 null, | 4898 null, |
| 4886 Keyword.FACTORY, | 4899 Keyword.FACTORY, |
| 4887 AstFactory.identifier3(className), | 4900 AstFactory.identifier3(className), |
| 4888 null, | 4901 null, |
| 4889 AstFactory.formalParameterList(), | 4902 AstFactory.formalParameterList(), |
| 4890 null, | 4903 null, |
| 4891 AstFactory.blockFunctionBody2()); | 4904 AstFactory.blockFunctionBody2()); |
| 4892 constructorDeclaration.accept(builder); | 4905 constructorDeclaration.accept(builder); |
| 4893 List<ConstructorElement> constructors = holder.constructors; | 4906 List<ConstructorElement> constructors = holder.constructors; |
| 4894 expect(constructors, hasLength(1)); | 4907 expect(constructors, hasLength(1)); |
| 4895 ConstructorElement constructor = constructors[0]; | 4908 ConstructorElement constructor = constructors[0]; |
| 4896 expect(constructor, isNotNull); | 4909 expect(constructor, isNotNull); |
| 4897 expect(constructor.isExternal, isFalse); | 4910 expect(constructor.isExternal, isFalse); |
| 4898 expect(constructor.isFactory, isTrue); | 4911 expect(constructor.isFactory, isTrue); |
| 4899 expect(constructor.name, ""); | 4912 expect(constructor.name, ""); |
| 4900 expect(constructor.functions, hasLength(0)); | 4913 expect(constructor.functions, hasLength(0)); |
| 4901 expect(constructor.labels, hasLength(0)); | 4914 expect(constructor.labels, hasLength(0)); |
| 4902 expect(constructor.localVariables, hasLength(0)); | 4915 expect(constructor.localVariables, hasLength(0)); |
| 4903 expect(constructor.parameters, hasLength(0)); | 4916 expect(constructor.parameters, hasLength(0)); |
| 4904 } | 4917 } |
| 4905 | 4918 |
| 4906 void test_visitConstructorDeclaration_minimal() { | 4919 void test_visitConstructorDeclaration_minimal() { |
| 4907 ElementHolder holder = new ElementHolder(); | 4920 ElementHolder holder = new ElementHolder(); |
| 4908 ElementBuilder builder = new ElementBuilder(holder); | 4921 ElementBuilder builder = new ElementBuilder(holder); |
| 4909 String className = "A"; | 4922 String className = "A"; |
| 4910 ConstructorDeclaration constructorDeclaration = AstFactory | 4923 ConstructorDeclaration constructorDeclaration = |
| 4911 .constructorDeclaration2( | 4924 AstFactory.constructorDeclaration2( |
| 4912 null, | 4925 null, |
| 4913 null, | 4926 null, |
| 4914 AstFactory.identifier3(className), | 4927 AstFactory.identifier3(className), |
| 4915 null, | 4928 null, |
| 4916 AstFactory.formalParameterList(), | 4929 AstFactory.formalParameterList(), |
| 4917 null, | 4930 null, |
| 4918 AstFactory.blockFunctionBody2()); | 4931 AstFactory.blockFunctionBody2()); |
| 4919 constructorDeclaration.documentationComment = AstFactory | 4932 constructorDeclaration.documentationComment = AstFactory |
| 4920 .documentationComment( | 4933 .documentationComment( |
| 4921 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 4934 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4933 expect(constructor.labels, hasLength(0)); | 4946 expect(constructor.labels, hasLength(0)); |
| 4934 expect(constructor.localVariables, hasLength(0)); | 4947 expect(constructor.localVariables, hasLength(0)); |
| 4935 expect(constructor.parameters, hasLength(0)); | 4948 expect(constructor.parameters, hasLength(0)); |
| 4936 } | 4949 } |
| 4937 | 4950 |
| 4938 void test_visitConstructorDeclaration_named() { | 4951 void test_visitConstructorDeclaration_named() { |
| 4939 ElementHolder holder = new ElementHolder(); | 4952 ElementHolder holder = new ElementHolder(); |
| 4940 ElementBuilder builder = new ElementBuilder(holder); | 4953 ElementBuilder builder = new ElementBuilder(holder); |
| 4941 String className = "A"; | 4954 String className = "A"; |
| 4942 String constructorName = "c"; | 4955 String constructorName = "c"; |
| 4943 ConstructorDeclaration constructorDeclaration = AstFactory | 4956 ConstructorDeclaration constructorDeclaration = |
| 4944 .constructorDeclaration2( | 4957 AstFactory.constructorDeclaration2( |
| 4945 null, | 4958 null, |
| 4946 null, | 4959 null, |
| 4947 AstFactory.identifier3(className), | 4960 AstFactory.identifier3(className), |
| 4948 constructorName, | 4961 constructorName, |
| 4949 AstFactory.formalParameterList(), | 4962 AstFactory.formalParameterList(), |
| 4950 null, | 4963 null, |
| 4951 AstFactory.blockFunctionBody2()); | 4964 AstFactory.blockFunctionBody2()); |
| 4952 constructorDeclaration.accept(builder); | 4965 constructorDeclaration.accept(builder); |
| 4953 List<ConstructorElement> constructors = holder.constructors; | 4966 List<ConstructorElement> constructors = holder.constructors; |
| 4954 expect(constructors, hasLength(1)); | 4967 expect(constructors, hasLength(1)); |
| 4955 ConstructorElement constructor = constructors[0]; | 4968 ConstructorElement constructor = constructors[0]; |
| 4956 expect(constructor, isNotNull); | 4969 expect(constructor, isNotNull); |
| 4957 expect(constructor.isExternal, isFalse); | 4970 expect(constructor.isExternal, isFalse); |
| 4958 expect(constructor.isFactory, isFalse); | 4971 expect(constructor.isFactory, isFalse); |
| 4959 expect(constructor.name, constructorName); | 4972 expect(constructor.name, constructorName); |
| 4960 expect(constructor.functions, hasLength(0)); | 4973 expect(constructor.functions, hasLength(0)); |
| 4961 expect(constructor.labels, hasLength(0)); | 4974 expect(constructor.labels, hasLength(0)); |
| 4962 expect(constructor.localVariables, hasLength(0)); | 4975 expect(constructor.localVariables, hasLength(0)); |
| 4963 expect(constructor.parameters, hasLength(0)); | 4976 expect(constructor.parameters, hasLength(0)); |
| 4964 expect(constructorDeclaration.name.staticElement, same(constructor)); | 4977 expect(constructorDeclaration.name.staticElement, same(constructor)); |
| 4965 expect(constructorDeclaration.element, same(constructor)); | 4978 expect(constructorDeclaration.element, same(constructor)); |
| 4966 } | 4979 } |
| 4967 | 4980 |
| 4968 void test_visitConstructorDeclaration_unnamed() { | 4981 void test_visitConstructorDeclaration_unnamed() { |
| 4969 ElementHolder holder = new ElementHolder(); | 4982 ElementHolder holder = new ElementHolder(); |
| 4970 ElementBuilder builder = new ElementBuilder(holder); | 4983 ElementBuilder builder = new ElementBuilder(holder); |
| 4971 String className = "A"; | 4984 String className = "A"; |
| 4972 ConstructorDeclaration constructorDeclaration = AstFactory | 4985 ConstructorDeclaration constructorDeclaration = |
| 4973 .constructorDeclaration2( | 4986 AstFactory.constructorDeclaration2( |
| 4974 null, | 4987 null, |
| 4975 null, | 4988 null, |
| 4976 AstFactory.identifier3(className), | 4989 AstFactory.identifier3(className), |
| 4977 null, | 4990 null, |
| 4978 AstFactory.formalParameterList(), | 4991 AstFactory.formalParameterList(), |
| 4979 null, | 4992 null, |
| 4980 AstFactory.blockFunctionBody2()); | 4993 AstFactory.blockFunctionBody2()); |
| 4981 constructorDeclaration.accept(builder); | 4994 constructorDeclaration.accept(builder); |
| 4982 List<ConstructorElement> constructors = holder.constructors; | 4995 List<ConstructorElement> constructors = holder.constructors; |
| 4983 expect(constructors, hasLength(1)); | 4996 expect(constructors, hasLength(1)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5043 expect(variable.isPublic, isTrue); | 5056 expect(variable.isPublic, isTrue); |
| 5044 expect(variable.isSynthetic, isFalse); | 5057 expect(variable.isSynthetic, isFalse); |
| 5045 expect(variable.name, variableName); | 5058 expect(variable.name, variableName); |
| 5046 } | 5059 } |
| 5047 | 5060 |
| 5048 void test_visitDefaultFormalParameter_noType() { | 5061 void test_visitDefaultFormalParameter_noType() { |
| 5049 // p = 0 | 5062 // p = 0 |
| 5050 ElementHolder holder = new ElementHolder(); | 5063 ElementHolder holder = new ElementHolder(); |
| 5051 ElementBuilder builder = new ElementBuilder(holder); | 5064 ElementBuilder builder = new ElementBuilder(holder); |
| 5052 String parameterName = 'p'; | 5065 String parameterName = 'p'; |
| 5053 DefaultFormalParameter formalParameter = AstFactory | 5066 DefaultFormalParameter formalParameter = |
| 5054 .positionalFormalParameter( | 5067 AstFactory.positionalFormalParameter( |
| 5055 AstFactory.simpleFormalParameter3(parameterName), | 5068 AstFactory.simpleFormalParameter3(parameterName), |
| 5056 AstFactory.integer(0)); | 5069 AstFactory.integer(0)); |
| 5057 formalParameter.accept(builder); | 5070 formalParameter.accept(builder); |
| 5058 | 5071 |
| 5059 List<ParameterElement> parameters = holder.parameters; | 5072 List<ParameterElement> parameters = holder.parameters; |
| 5060 expect(parameters, hasLength(1)); | 5073 expect(parameters, hasLength(1)); |
| 5061 ParameterElement parameter = parameters[0]; | 5074 ParameterElement parameter = parameters[0]; |
| 5062 expect(parameter.hasImplicitType, isTrue); | 5075 expect(parameter.hasImplicitType, isTrue); |
| 5063 expect(parameter.isConst, isFalse); | 5076 expect(parameter.isConst, isFalse); |
| 5064 expect(parameter.isDeprecated, isFalse); | 5077 expect(parameter.isDeprecated, isFalse); |
| (...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6448 | 6461 |
| 6449 void test_locate_FunctionDeclaration() { | 6462 void test_locate_FunctionDeclaration() { |
| 6450 AstNode id = _findNodeIn("f", "int f() => 3;"); | 6463 AstNode id = _findNodeIn("f", "int f() => 3;"); |
| 6451 FunctionDeclaration declaration = | 6464 FunctionDeclaration declaration = |
| 6452 id.getAncestor((node) => node is FunctionDeclaration); | 6465 id.getAncestor((node) => node is FunctionDeclaration); |
| 6453 Element element = ElementLocator.locate(declaration); | 6466 Element element = ElementLocator.locate(declaration); |
| 6454 EngineTestCase.assertInstanceOf( | 6467 EngineTestCase.assertInstanceOf( |
| 6455 (obj) => obj is FunctionElement, FunctionElement, element); | 6468 (obj) => obj is FunctionElement, FunctionElement, element); |
| 6456 } | 6469 } |
| 6457 | 6470 |
| 6458 void test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPa
rameter() { | 6471 void |
| 6472 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { |
| 6459 AstNode id = _findNodeIndexedIn( | 6473 AstNode id = _findNodeIndexedIn( |
| 6460 "Class", | 6474 "Class", |
| 6461 2, | 6475 2, |
| 6462 r''' | 6476 r''' |
| 6463 class Class { | 6477 class Class { |
| 6464 const Class.name(); | 6478 const Class.name(); |
| 6465 } | 6479 } |
| 6466 void main(@Class.name() parameter) { | 6480 void main(@Class.name() parameter) { |
| 6467 }'''); | 6481 }'''); |
| 6468 Element element = ElementLocator.locate(id); | 6482 Element element = ElementLocator.locate(id); |
| 6469 EngineTestCase.assertInstanceOf( | 6483 EngineTestCase.assertInstanceOf( |
| 6470 (obj) => obj is ClassElement, ClassElement, element); | 6484 (obj) => obj is ClassElement, ClassElement, element); |
| 6471 } | 6485 } |
| 6472 | 6486 |
| 6473 void test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormal
Parameter() { | 6487 void |
| 6488 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { |
| 6474 AstNode id = _findNodeIndexedIn( | 6489 AstNode id = _findNodeIndexedIn( |
| 6475 "Class", | 6490 "Class", |
| 6476 2, | 6491 2, |
| 6477 r''' | 6492 r''' |
| 6478 class Class { | 6493 class Class { |
| 6479 const Class(); | 6494 const Class(); |
| 6480 } | 6495 } |
| 6481 void main(@Class() parameter) { | 6496 void main(@Class() parameter) { |
| 6482 }'''); | 6497 }'''); |
| 6483 Element element = ElementLocator.locate(id); | 6498 Element element = ElementLocator.locate(id); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6570 Element element = ElementLocator.locate(node); | 6585 Element element = ElementLocator.locate(node); |
| 6571 EngineTestCase.assertInstanceOf( | 6586 EngineTestCase.assertInstanceOf( |
| 6572 (obj) => obj is ConstructorElement, ConstructorElement, element); | 6587 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 6573 } | 6588 } |
| 6574 | 6589 |
| 6575 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { | 6590 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { |
| 6576 // prepare: new pref.A() | 6591 // prepare: new pref.A() |
| 6577 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 6592 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| 6578 PrefixedIdentifier prefixedIdentifier = | 6593 PrefixedIdentifier prefixedIdentifier = |
| 6579 AstFactory.identifier4("pref", identifier); | 6594 AstFactory.identifier4("pref", identifier); |
| 6580 InstanceCreationExpression creation = AstFactory | 6595 InstanceCreationExpression creation = |
| 6581 .instanceCreationExpression2( | 6596 AstFactory.instanceCreationExpression2( |
| 6582 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); | 6597 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); |
| 6583 // set ClassElement | 6598 // set ClassElement |
| 6584 ClassElement classElement = ElementFactory.classElement2("A"); | 6599 ClassElement classElement = ElementFactory.classElement2("A"); |
| 6585 identifier.staticElement = classElement; | 6600 identifier.staticElement = classElement; |
| 6586 // set ConstructorElement | 6601 // set ConstructorElement |
| 6587 ConstructorElement constructorElement = | 6602 ConstructorElement constructorElement = |
| 6588 ElementFactory.constructorElement2(classElement, null); | 6603 ElementFactory.constructorElement2(classElement, null); |
| 6589 creation.constructorName.staticElement = constructorElement; | 6604 creation.constructorName.staticElement = constructorElement; |
| 6590 // verify that "A" is resolved to ConstructorElement | 6605 // verify that "A" is resolved to ConstructorElement |
| 6591 Element element = ElementLocator.locate(identifier); | 6606 Element element = ElementLocator.locate(identifier); |
| 6592 expect(element, same(classElement)); | 6607 expect(element, same(classElement)); |
| 6593 } | 6608 } |
| 6594 | 6609 |
| 6595 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { | 6610 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { |
| 6596 // prepare: new A() | 6611 // prepare: new A() |
| 6597 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 6612 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| 6598 InstanceCreationExpression creation = AstFactory | 6613 InstanceCreationExpression creation = |
| 6599 .instanceCreationExpression2( | 6614 AstFactory.instanceCreationExpression2( |
| 6600 Keyword.NEW, AstFactory.typeName3(identifier)); | 6615 Keyword.NEW, AstFactory.typeName3(identifier)); |
| 6601 // set ClassElement | 6616 // set ClassElement |
| 6602 ClassElement classElement = ElementFactory.classElement2("A"); | 6617 ClassElement classElement = ElementFactory.classElement2("A"); |
| 6603 identifier.staticElement = classElement; | 6618 identifier.staticElement = classElement; |
| 6604 // set ConstructorElement | 6619 // set ConstructorElement |
| 6605 ConstructorElement constructorElement = | 6620 ConstructorElement constructorElement = |
| 6606 ElementFactory.constructorElement2(classElement, null); | 6621 ElementFactory.constructorElement2(classElement, null); |
| 6607 creation.constructorName.staticElement = constructorElement; | 6622 creation.constructorName.staticElement = constructorElement; |
| 6608 // verify that "A" is resolved to ConstructorElement | 6623 // verify that "A" is resolved to ConstructorElement |
| 6609 Element element = ElementLocator.locate(identifier); | 6624 Element element = ElementLocator.locate(identifier); |
| (...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8094 } | 8109 } |
| 8095 | 8110 |
| 8096 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => | 8111 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => |
| 8097 new ReferenceFinder((ConstantEvaluationTarget dependency) { | 8112 new ReferenceFinder((ConstantEvaluationTarget dependency) { |
| 8098 _referenceGraph.addEdge(source, dependency); | 8113 _referenceGraph.addEdge(source, dependency); |
| 8099 }); | 8114 }); |
| 8100 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | 8115 SuperConstructorInvocation _makeTailSuperConstructorInvocation( |
| 8101 String name, bool isConst) { | 8116 String name, bool isConst) { |
| 8102 List<ConstructorInitializer> initializers = | 8117 List<ConstructorInitializer> initializers = |
| 8103 new List<ConstructorInitializer>(); | 8118 new List<ConstructorInitializer>(); |
| 8104 ConstructorDeclaration constructorDeclaration = AstFactory | 8119 ConstructorDeclaration constructorDeclaration = |
| 8105 .constructorDeclaration(AstFactory.identifier3(name), null, | 8120 AstFactory.constructorDeclaration(AstFactory.identifier3(name), null, |
| 8106 AstFactory.formalParameterList(), initializers); | 8121 AstFactory.formalParameterList(), initializers); |
| 8107 if (isConst) { | 8122 if (isConst) { |
| 8108 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | 8123 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); |
| 8109 } | 8124 } |
| 8110 ClassElementImpl classElement = ElementFactory.classElement2(name); | 8125 ClassElementImpl classElement = ElementFactory.classElement2(name); |
| 8111 SuperConstructorInvocation superConstructorInvocation = | 8126 SuperConstructorInvocation superConstructorInvocation = |
| 8112 AstFactory.superConstructorInvocation(); | 8127 AstFactory.superConstructorInvocation(); |
| 8113 ConstructorElementImpl constructorElement = | 8128 ConstructorElementImpl constructorElement = |
| 8114 ElementFactory.constructorElement(classElement, name, isConst); | 8129 ElementFactory.constructorElement(classElement, name, isConst); |
| 8115 _tail = constructorElement; | 8130 _tail = constructorElement; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8229 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 8244 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
| 8230 expect(UriKind.fromEncoding(0x58), same(null)); | 8245 expect(UriKind.fromEncoding(0x58), same(null)); |
| 8231 } | 8246 } |
| 8232 | 8247 |
| 8233 void test_getEncoding() { | 8248 void test_getEncoding() { |
| 8234 expect(UriKind.DART_URI.encoding, 0x64); | 8249 expect(UriKind.DART_URI.encoding, 0x64); |
| 8235 expect(UriKind.FILE_URI.encoding, 0x66); | 8250 expect(UriKind.FILE_URI.encoding, 0x66); |
| 8236 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 8251 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
| 8237 } | 8252 } |
| 8238 } | 8253 } |
| OLD | NEW |