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.dart.element.builder_test; | 5 library analyzer.test.dart.element.builder_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
11 import 'package:analyzer/src/dart/ast/ast.dart'; | 11 import 'package:analyzer/src/dart/ast/ast.dart'; |
12 import 'package:analyzer/src/dart/element/builder.dart'; | 12 import 'package:analyzer/src/dart/element/builder.dart'; |
13 import 'package:analyzer/src/dart/element/element.dart'; | 13 import 'package:analyzer/src/dart/element/element.dart'; |
14 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 14 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/resolver.dart'; | 16 import 'package:analyzer/src/generated/resolver.dart'; |
17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
18 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; | 18 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
19 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 19 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 20 import 'package:analyzer/src/generated/testing/element_search.dart'; |
| 21 import 'package:analyzer/src/generated/testing/node_search.dart'; |
20 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 22 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
21 import 'package:analyzer/src/generated/utilities_dart.dart'; | 23 import 'package:analyzer/src/generated/utilities_dart.dart'; |
22 import 'package:test/test.dart'; | 24 import 'package:test/test.dart'; |
23 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 25 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
24 | 26 |
25 import '../../generated/parser_test.dart'; | 27 import '../../generated/parser_test.dart'; |
26 import '../../generated/test_support.dart'; | 28 import '../../generated/test_support.dart'; |
27 | 29 |
28 main() { | 30 main() { |
29 defineReflectiveSuite(() { | 31 defineReflectiveSuite(() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 74 } |
73 } | 75 } |
74 ''').types[0].methods[0]; | 76 ''').types[0].methods[0]; |
75 { | 77 { |
76 expect(method.parameters, hasLength(2)); | 78 expect(method.parameters, hasLength(2)); |
77 expect(method.parameters[0].displayName, 'a'); | 79 expect(method.parameters[0].displayName, 'a'); |
78 expect(method.parameters[0].initializer, isNull); | 80 expect(method.parameters[0].initializer, isNull); |
79 expect(method.parameters[1].displayName, 'b'); | 81 expect(method.parameters[1].displayName, 'b'); |
80 expect(method.parameters[1].initializer, isNull); | 82 expect(method.parameters[1].initializer, isNull); |
81 } | 83 } |
82 expect(method.functions, isEmpty); | 84 expect( |
| 85 findDeclaredIdentifiersByName(compilationUnit, 'v') |
| 86 .single |
| 87 .staticElement, |
| 88 isNull); |
| 89 expect( |
| 90 findDeclaredIdentifiersByName(compilationUnit, 'localFunction') |
| 91 .single |
| 92 .staticElement, |
| 93 isNull); |
83 } | 94 } |
84 | 95 |
85 void test_api_topLevelFunction_blockBody() { | 96 void test_api_topLevelFunction_blockBody() { |
86 FunctionElement function = buildElementsForText(r''' | 97 FunctionElement topLevelFunction = buildElementsForText(r''' |
87 void topLevelFunction() { | 98 void topLevelFunction() { |
88 int v = 0; | 99 int v = 0; |
89 localFunction() {} | 100 localFunction() {} |
90 } | 101 } |
91 ''').functions[0]; | 102 ''').functions[0]; |
92 expect(function.functions, isEmpty); | 103 expect(topLevelFunction, isNotNull); |
| 104 expect(topLevelFunction.name, 'topLevelFunction'); |
| 105 expect( |
| 106 findDeclaredIdentifiersByName(compilationUnit, 'v') |
| 107 .single |
| 108 .staticElement, |
| 109 isNull); |
| 110 expect( |
| 111 findDeclaredIdentifiersByName(compilationUnit, 'localFunction') |
| 112 .single |
| 113 .staticElement, |
| 114 isNull); |
93 } | 115 } |
94 | 116 |
95 void test_api_topLevelFunction_expressionBody() { | 117 void test_api_topLevelFunction_expressionBody() { |
96 FunctionElement function = buildElementsForText(r''' | 118 FunctionElement topLevelFunction = buildElementsForText(r''' |
97 topLevelFunction() => () { | 119 topLevelFunction() => () { |
98 int localVar = 0; | 120 int localVar = 0; |
99 }; | 121 }; |
100 ''').functions[0]; | 122 ''').functions[0]; |
101 expect(function.functions, isEmpty); | 123 expect(topLevelFunction, isNotNull); |
| 124 expect(topLevelFunction.name, 'topLevelFunction'); |
| 125 expect( |
| 126 findDeclaredIdentifiersByName(compilationUnit, 'localVar') |
| 127 .single |
| 128 .staticElement, |
| 129 isNull); |
102 } | 130 } |
103 | 131 |
104 void test_api_topLevelFunction_parameters() { | 132 void test_api_topLevelFunction_parameters() { |
105 FunctionElement function = buildElementsForText(r''' | 133 FunctionElement function = buildElementsForText(r''' |
106 void topLevelFunction(int a, int b(double b2), {c: () {int c2; c3() {} }}) { | 134 void topLevelFunction(int a, int b(double b2), {c: () {int c2; c3() {} }}) { |
107 } | 135 } |
108 ''').functions[0]; | 136 ''').functions[0]; |
109 List<ParameterElement> parameters = function.parameters; | 137 List<ParameterElement> parameters = function.parameters; |
110 expect(parameters, hasLength(3)); | 138 expect(parameters, hasLength(3)); |
111 { | 139 { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 expect(functions, hasLength(1)); | 385 expect(functions, hasLength(1)); |
358 FunctionElement function = functions[0]; | 386 FunctionElement function = functions[0]; |
359 expect(function, isNotNull); | 387 expect(function, isNotNull); |
360 expect(expression.element, same(function)); | 388 expect(expression.element, same(function)); |
361 expect(function.hasImplicitReturnType, isTrue); | 389 expect(function.hasImplicitReturnType, isTrue); |
362 expect(function.isSynthetic, isFalse); | 390 expect(function.isSynthetic, isFalse); |
363 expect(function.typeParameters, hasLength(0)); | 391 expect(function.typeParameters, hasLength(0)); |
364 } | 392 } |
365 | 393 |
366 void test_visitFunctionExpression_inBlockBody() { | 394 void test_visitFunctionExpression_inBlockBody() { |
367 List<FunctionElement> functions = | 395 buildElementsForText('f() { return () => 42; }'); |
368 buildElementsForText('f() { return () => 42; }').functions[0].functions; | 396 FunctionDeclaration f = compilationUnit.declarations[0]; |
369 expect(functions, hasLength(1)); | 397 BlockFunctionBody fBody = f.functionExpression.body; |
370 FunctionElement function = functions[0]; | 398 ReturnStatement returnStatement = fBody.block.statements[0]; |
| 399 FunctionExpression closure = returnStatement.expression; |
| 400 FunctionElement function = closure.element; |
371 expect(function, isNotNull); | 401 expect(function, isNotNull); |
372 expect(function.hasImplicitReturnType, isTrue); | 402 expect(function.hasImplicitReturnType, isTrue); |
373 expect(function.isSynthetic, isFalse); | 403 expect(function.isSynthetic, isFalse); |
374 expect(function.typeParameters, hasLength(0)); | 404 expect(function.typeParameters, hasLength(0)); |
375 } | 405 } |
376 | 406 |
377 void test_visitFunctionExpression_inExpressionBody() { | 407 void test_visitFunctionExpression_inExpressionBody() { |
378 List<FunctionElement> functions = | 408 buildElementsForText('f() => () => 42;'); |
379 buildElementsForText('f() => () => 42;').functions[0].functions; | 409 FunctionDeclaration f = compilationUnit.declarations[0]; |
380 expect(functions, hasLength(1)); | 410 ExpressionFunctionBody fBody = f.functionExpression.body; |
381 FunctionElement function = functions[0]; | 411 FunctionExpression closure = fBody.expression; |
| 412 FunctionElement function = closure.element; |
382 expect(function, isNotNull); | 413 expect(function, isNotNull); |
383 expect(function.hasImplicitReturnType, isTrue); | 414 expect(function.hasImplicitReturnType, isTrue); |
384 expect(function.isSynthetic, isFalse); | 415 expect(function.isSynthetic, isFalse); |
385 expect(function.typeParameters, hasLength(0)); | 416 expect(function.typeParameters, hasLength(0)); |
386 } | 417 } |
387 | 418 |
388 void test_visitFunctionTypeAlias() { | 419 void test_visitFunctionTypeAlias() { |
389 ElementHolder holder = new ElementHolder(); | 420 ElementHolder holder = new ElementHolder(); |
390 ElementBuilder builder = _makeBuilder(holder); | 421 ElementBuilder builder = _makeBuilder(holder); |
391 String aliasName = "F"; | 422 String aliasName = "F"; |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 ElementHolder holder = new ElementHolder(); | 845 ElementHolder holder = new ElementHolder(); |
815 ElementBuilder builder = _makeBuilder(holder); | 846 ElementBuilder builder = _makeBuilder(holder); |
816 // | 847 // |
817 // var f = () {var v;}; | 848 // var f = () {var v;}; |
818 // | 849 // |
819 String variableName = "v"; | 850 String variableName = "v"; |
820 VariableDeclaration variable = | 851 VariableDeclaration variable = |
821 AstTestFactory.variableDeclaration2(variableName, null); | 852 AstTestFactory.variableDeclaration2(variableName, null); |
822 Statement statement = | 853 Statement statement = |
823 AstTestFactory.variableDeclarationStatement2(null, [variable]); | 854 AstTestFactory.variableDeclarationStatement2(null, [variable]); |
824 Expression initializer = AstTestFactory.functionExpression2( | 855 FunctionExpression initializer = AstTestFactory.functionExpression2( |
825 AstTestFactory.formalParameterList(), | 856 AstTestFactory.formalParameterList(), |
826 AstTestFactory.blockFunctionBody2([statement])); | 857 AstTestFactory.blockFunctionBody2([statement])); |
827 String fieldName = "f"; | 858 String fieldName = "f"; |
828 VariableDeclaration field = | 859 VariableDeclaration field = |
829 AstTestFactory.variableDeclaration2(fieldName, initializer); | 860 AstTestFactory.variableDeclaration2(fieldName, initializer); |
830 FieldDeclaration fieldDeclaration = | 861 FieldDeclaration fieldDeclaration = |
831 AstTestFactory.fieldDeclaration2(false, null, [field]); | 862 AstTestFactory.fieldDeclaration2(false, null, [field]); |
832 fieldDeclaration.accept(builder); | 863 fieldDeclaration.accept(builder); |
833 | 864 |
834 List<FieldElement> variables = holder.fields; | 865 List<FieldElement> variables = holder.fields; |
835 expect(variables, hasLength(1)); | 866 expect(variables, hasLength(1)); |
836 FieldElement fieldElement = variables[0]; | 867 FieldElement fieldElement = variables[0]; |
837 expect(fieldElement, isNotNull); | 868 expect(fieldElement, isNotNull); |
838 FunctionElement initializerElement = fieldElement.initializer; | 869 FunctionElement initializerElement = fieldElement.initializer; |
839 expect(initializerElement, isNotNull); | 870 expect(initializerElement, isNotNull); |
840 expect(initializerElement.hasImplicitReturnType, isTrue); | 871 expect(initializerElement.hasImplicitReturnType, isTrue); |
841 List<FunctionElement> functionElements = initializerElement.functions; | 872 expect(initializer.element, new isInstanceOf<FunctionElement>()); |
842 expect(functionElements, hasLength(1)); | |
843 LocalVariableElement variableElement = variable.element; | 873 LocalVariableElement variableElement = variable.element; |
844 expect(variableElement.hasImplicitType, isTrue); | 874 expect(variableElement.hasImplicitType, isTrue); |
845 expect(variableElement.isConst, isFalse); | 875 expect(variableElement.isConst, isFalse); |
846 expect(variableElement.isFinal, isFalse); | 876 expect(variableElement.isFinal, isFalse); |
847 expect(variableElement.isSynthetic, isFalse); | 877 expect(variableElement.isSynthetic, isFalse); |
848 expect(variableElement.name, variableName); | 878 expect(variableElement.name, variableName); |
849 } | 879 } |
850 | 880 |
851 void test_visitVariableDeclaration_noInitializer() { | 881 void test_visitVariableDeclaration_noInitializer() { |
852 // var v; | 882 // var v; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 var mainAst = _compilationUnit.declarations.single as FunctionDeclaration; | 1034 var mainAst = _compilationUnit.declarations.single as FunctionDeclaration; |
1005 | 1035 |
1006 // Build API elements. | 1036 // Build API elements. |
1007 FunctionElementImpl main; | 1037 FunctionElementImpl main; |
1008 { | 1038 { |
1009 ElementHolder holder = new ElementHolder(); | 1039 ElementHolder holder = new ElementHolder(); |
1010 _compilationUnit | 1040 _compilationUnit |
1011 .accept(new ApiElementBuilder(holder, compilationUnitElement)); | 1041 .accept(new ApiElementBuilder(holder, compilationUnitElement)); |
1012 main = holder.functions.single as FunctionElementImpl; | 1042 main = holder.functions.single as FunctionElementImpl; |
1013 } | 1043 } |
1014 expect(main.functions, isEmpty); | |
1015 | 1044 |
1016 // Build local elements in body. | 1045 // Build local elements in body. |
1017 ElementHolder holder = new ElementHolder(); | 1046 ElementHolder holder = new ElementHolder(); |
1018 FunctionBody mainBody = mainAst.functionExpression.body; | 1047 FunctionBody mainBody = mainAst.functionExpression.body; |
1019 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); | 1048 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); |
1020 main.functions = holder.functions; | 1049 main.encloseElements(holder.functions); |
1021 main.encloseElements(holder.localVariables); | 1050 main.encloseElements(holder.localVariables); |
1022 | 1051 |
| 1052 var f1 = findLocalFunction(code, 'f1() {'); |
| 1053 var f2 = findLocalFunction(code, 'f2() {'); |
1023 var v1 = findLocalVariable(code, 'v1;'); | 1054 var v1 = findLocalVariable(code, 'v1;'); |
1024 var v2 = findLocalVariable(code, 'v2;'); | 1055 var v2 = findLocalVariable(code, 'v2;'); |
1025 var v3 = findLocalVariable(code, 'v3;'); | 1056 var v3 = findLocalVariable(code, 'v3;'); |
1026 | 1057 |
1027 expect(v1.enclosingElement, main); | 1058 expect(v1.enclosingElement, main); |
1028 expect(main.functions, hasLength(1)); | |
1029 { | 1059 { |
1030 FunctionElement f1 = main.functions[0]; | |
1031 expect(f1.name, 'f1'); | 1060 expect(f1.name, 'f1'); |
1032 expect(v2.enclosingElement, f1); | 1061 expect(v2.enclosingElement, f1); |
1033 expect(f1.functions, hasLength(1)); | |
1034 { | 1062 { |
1035 FunctionElement f2 = f1.functions[0]; | |
1036 expect(f2.name, 'f2'); | 1063 expect(f2.name, 'f2'); |
1037 expect(v3.enclosingElement, f2); | 1064 expect(v3.enclosingElement, f2); |
1038 expect(f2.functions, isEmpty); | |
1039 } | 1065 } |
1040 } | 1066 } |
1041 } | 1067 } |
1042 | 1068 |
1043 void test_buildParameterInitializer() { | 1069 void test_buildParameterInitializer() { |
1044 CompilationUnit unit = parseCompilationUnit('f({p: 42}) {}'); | 1070 CompilationUnit unit = parseCompilationUnit('f({p: 42}) {}'); |
1045 var function = unit.declarations.single as FunctionDeclaration; | 1071 var function = unit.declarations.single as FunctionDeclaration; |
1046 var parameter = function.functionExpression.parameters.parameters.single | 1072 var parameter = function.functionExpression.parameters.parameters.single |
1047 as DefaultFormalParameter; | 1073 as DefaultFormalParameter; |
1048 // Build API elements. | 1074 // Build API elements. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 FunctionElementImpl main; | 1130 FunctionElementImpl main; |
1105 { | 1131 { |
1106 ElementHolder holder = new ElementHolder(); | 1132 ElementHolder holder = new ElementHolder(); |
1107 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); | 1133 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); |
1108 main = holder.functions.single as FunctionElementImpl; | 1134 main = holder.functions.single as FunctionElementImpl; |
1109 } | 1135 } |
1110 // Build local elements in body. | 1136 // Build local elements in body. |
1111 ElementHolder holder = new ElementHolder(); | 1137 ElementHolder holder = new ElementHolder(); |
1112 FunctionBody mainBody = mainAst.functionExpression.body; | 1138 FunctionBody mainBody = mainAst.functionExpression.body; |
1113 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); | 1139 mainBody.accept(new LocalElementBuilder(holder, compilationUnitElement)); |
1114 main.functions = holder.functions; | 1140 |
1115 expect(main.functions, hasLength(1)); | 1141 List<FunctionElement> functions = holder.functions; |
1116 FunctionElement f = main.functions[0]; | 1142 main.encloseElements(functions); |
| 1143 |
| 1144 FunctionElement f = findElementsByName(unit, 'f').single; |
1117 expect(f.parameters, hasLength(1)); | 1145 expect(f.parameters, hasLength(1)); |
1118 expect(f.parameters[0].initializer, isNotNull); | 1146 expect(f.parameters[0].initializer, isNotNull); |
1119 } | 1147 } |
1120 | 1148 |
1121 void test_visitFieldFormalParameter() { | 1149 void test_visitFieldFormalParameter() { |
1122 CompilationUnit unit = parseCompilationUnit( | 1150 CompilationUnit unit = parseCompilationUnit( |
1123 r''' | 1151 r''' |
1124 main() { | 1152 main() { |
1125 f(a, this.b) {} | 1153 f(a, this.b) {} |
1126 } | 1154 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 class C { | 1446 class C { |
1419 @A(f: () {}) | 1447 @A(f: () {}) |
1420 void m() {} | 1448 void m() {} |
1421 } | 1449 } |
1422 '''; | 1450 '''; |
1423 ElementHolder holder = buildElementsForText(code); | 1451 ElementHolder holder = buildElementsForText(code); |
1424 ClassElement elementC = holder.types[1]; | 1452 ClassElement elementC = holder.types[1]; |
1425 expect(elementC, isNotNull); | 1453 expect(elementC, isNotNull); |
1426 MethodElement methodM = elementC.methods[0]; | 1454 MethodElement methodM = elementC.methods[0]; |
1427 expect(methodM, isNotNull); | 1455 expect(methodM, isNotNull); |
1428 expect(methodM.functions, isEmpty); | |
1429 } | 1456 } |
1430 | 1457 |
1431 void test_visitClassDeclaration_minimal() { | 1458 void test_visitClassDeclaration_minimal() { |
1432 String className = "C"; | 1459 String className = "C"; |
1433 ClassDeclaration classDeclaration = AstTestFactory.classDeclaration( | 1460 ClassDeclaration classDeclaration = AstTestFactory.classDeclaration( |
1434 null, className, null, null, null, null); | 1461 null, className, null, null, null, null); |
1435 classDeclaration.documentationComment = AstTestFactory.documentationComment( | 1462 classDeclaration.documentationComment = AstTestFactory.documentationComment( |
1436 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1463 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
1437 classDeclaration.endToken.offset = 80; | 1464 classDeclaration.endToken.offset = 80; |
1438 | 1465 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 1656 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
1630 | 1657 |
1631 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1658 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
1632 List<ConstructorElement> constructors = holder.constructors; | 1659 List<ConstructorElement> constructors = holder.constructors; |
1633 expect(constructors, hasLength(1)); | 1660 expect(constructors, hasLength(1)); |
1634 ConstructorElement constructor = constructors[0]; | 1661 ConstructorElement constructor = constructors[0]; |
1635 expect(constructor, isNotNull); | 1662 expect(constructor, isNotNull); |
1636 expect(constructor.isExternal, isTrue); | 1663 expect(constructor.isExternal, isTrue); |
1637 expect(constructor.isFactory, isFalse); | 1664 expect(constructor.isFactory, isFalse); |
1638 expect(constructor.name, ""); | 1665 expect(constructor.name, ""); |
1639 expect(constructor.functions, hasLength(0)); | |
1640 expect(constructor.parameters, hasLength(0)); | 1666 expect(constructor.parameters, hasLength(0)); |
1641 } | 1667 } |
1642 | 1668 |
1643 void test_visitConstructorDeclaration_factory() { | 1669 void test_visitConstructorDeclaration_factory() { |
1644 String className = "A"; | 1670 String className = "A"; |
1645 ConstructorDeclaration constructorDeclaration = | 1671 ConstructorDeclaration constructorDeclaration = |
1646 AstTestFactory.constructorDeclaration2( | 1672 AstTestFactory.constructorDeclaration2( |
1647 null, | 1673 null, |
1648 Keyword.FACTORY, | 1674 Keyword.FACTORY, |
1649 AstTestFactory.identifier3(className), | 1675 AstTestFactory.identifier3(className), |
1650 null, | 1676 null, |
1651 AstTestFactory.formalParameterList(), | 1677 AstTestFactory.formalParameterList(), |
1652 null, | 1678 null, |
1653 AstTestFactory.blockFunctionBody2()); | 1679 AstTestFactory.blockFunctionBody2()); |
1654 | 1680 |
1655 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1681 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
1656 List<ConstructorElement> constructors = holder.constructors; | 1682 List<ConstructorElement> constructors = holder.constructors; |
1657 expect(constructors, hasLength(1)); | 1683 expect(constructors, hasLength(1)); |
1658 ConstructorElement constructor = constructors[0]; | 1684 ConstructorElement constructor = constructors[0]; |
1659 expect(constructor, isNotNull); | 1685 expect(constructor, isNotNull); |
1660 expect(constructor.isExternal, isFalse); | 1686 expect(constructor.isExternal, isFalse); |
1661 expect(constructor.isFactory, isTrue); | 1687 expect(constructor.isFactory, isTrue); |
1662 expect(constructor.name, ""); | 1688 expect(constructor.name, ""); |
1663 expect(constructor.functions, hasLength(0)); | |
1664 expect(constructor.parameters, hasLength(0)); | 1689 expect(constructor.parameters, hasLength(0)); |
1665 } | 1690 } |
1666 | 1691 |
1667 void test_visitConstructorDeclaration_minimal() { | 1692 void test_visitConstructorDeclaration_minimal() { |
1668 String className = "A"; | 1693 String className = "A"; |
1669 ConstructorDeclaration constructorDeclaration = | 1694 ConstructorDeclaration constructorDeclaration = |
1670 AstTestFactory.constructorDeclaration2( | 1695 AstTestFactory.constructorDeclaration2( |
1671 null, | 1696 null, |
1672 null, | 1697 null, |
1673 AstTestFactory.identifier3(className), | 1698 AstTestFactory.identifier3(className), |
1674 null, | 1699 null, |
1675 AstTestFactory.formalParameterList(), | 1700 AstTestFactory.formalParameterList(), |
1676 null, | 1701 null, |
1677 AstTestFactory.blockFunctionBody2()); | 1702 AstTestFactory.blockFunctionBody2()); |
1678 constructorDeclaration.documentationComment = AstTestFactory | 1703 constructorDeclaration.documentationComment = AstTestFactory |
1679 .documentationComment( | 1704 .documentationComment( |
1680 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1705 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
1681 constructorDeclaration.endToken.offset = 80; | 1706 constructorDeclaration.endToken.offset = 80; |
1682 | 1707 |
1683 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1708 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
1684 List<ConstructorElement> constructors = holder.constructors; | 1709 List<ConstructorElement> constructors = holder.constructors; |
1685 expect(constructors, hasLength(1)); | 1710 expect(constructors, hasLength(1)); |
1686 ConstructorElement constructor = constructors[0]; | 1711 ConstructorElement constructor = constructors[0]; |
1687 expect(constructor, isNotNull); | 1712 expect(constructor, isNotNull); |
1688 assertHasCodeRange(constructor, 50, 31); | 1713 assertHasCodeRange(constructor, 50, 31); |
1689 expect(constructor.documentationComment, '/// aaa'); | 1714 expect(constructor.documentationComment, '/// aaa'); |
1690 expect(constructor.isExternal, isFalse); | 1715 expect(constructor.isExternal, isFalse); |
1691 expect(constructor.isFactory, isFalse); | 1716 expect(constructor.isFactory, isFalse); |
1692 expect(constructor.name, ""); | 1717 expect(constructor.name, ""); |
1693 expect(constructor.functions, hasLength(0)); | |
1694 expect(constructor.parameters, hasLength(0)); | 1718 expect(constructor.parameters, hasLength(0)); |
1695 } | 1719 } |
1696 | 1720 |
1697 void test_visitConstructorDeclaration_named() { | 1721 void test_visitConstructorDeclaration_named() { |
1698 String className = "A"; | 1722 String className = "A"; |
1699 String constructorName = "c"; | 1723 String constructorName = "c"; |
1700 ConstructorDeclaration constructorDeclaration = | 1724 ConstructorDeclaration constructorDeclaration = |
1701 AstTestFactory.constructorDeclaration2( | 1725 AstTestFactory.constructorDeclaration2( |
1702 null, | 1726 null, |
1703 null, | 1727 null, |
1704 AstTestFactory.identifier3(className), | 1728 AstTestFactory.identifier3(className), |
1705 constructorName, | 1729 constructorName, |
1706 AstTestFactory.formalParameterList(), | 1730 AstTestFactory.formalParameterList(), |
1707 null, | 1731 null, |
1708 AstTestFactory.blockFunctionBody2()); | 1732 AstTestFactory.blockFunctionBody2()); |
1709 | 1733 |
1710 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1734 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
1711 List<ConstructorElement> constructors = holder.constructors; | 1735 List<ConstructorElement> constructors = holder.constructors; |
1712 expect(constructors, hasLength(1)); | 1736 expect(constructors, hasLength(1)); |
1713 ConstructorElement constructor = constructors[0]; | 1737 ConstructorElement constructor = constructors[0]; |
1714 expect(constructor, isNotNull); | 1738 expect(constructor, isNotNull); |
1715 expect(constructor.isExternal, isFalse); | 1739 expect(constructor.isExternal, isFalse); |
1716 expect(constructor.isFactory, isFalse); | 1740 expect(constructor.isFactory, isFalse); |
1717 expect(constructor.name, constructorName); | 1741 expect(constructor.name, constructorName); |
1718 expect(constructor.functions, hasLength(0)); | |
1719 expect(constructor.parameters, hasLength(0)); | 1742 expect(constructor.parameters, hasLength(0)); |
1720 expect(constructorDeclaration.name.staticElement, same(constructor)); | 1743 expect(constructorDeclaration.name.staticElement, same(constructor)); |
1721 expect(constructorDeclaration.element, same(constructor)); | 1744 expect(constructorDeclaration.element, same(constructor)); |
1722 } | 1745 } |
1723 | 1746 |
1724 void test_visitConstructorDeclaration_unnamed() { | 1747 void test_visitConstructorDeclaration_unnamed() { |
1725 String className = "A"; | 1748 String className = "A"; |
1726 ConstructorDeclaration constructorDeclaration = | 1749 ConstructorDeclaration constructorDeclaration = |
1727 AstTestFactory.constructorDeclaration2( | 1750 AstTestFactory.constructorDeclaration2( |
1728 null, | 1751 null, |
1729 null, | 1752 null, |
1730 AstTestFactory.identifier3(className), | 1753 AstTestFactory.identifier3(className), |
1731 null, | 1754 null, |
1732 AstTestFactory.formalParameterList(), | 1755 AstTestFactory.formalParameterList(), |
1733 null, | 1756 null, |
1734 AstTestFactory.blockFunctionBody2()); | 1757 AstTestFactory.blockFunctionBody2()); |
1735 | 1758 |
1736 ElementHolder holder = buildElementsForAst(constructorDeclaration); | 1759 ElementHolder holder = buildElementsForAst(constructorDeclaration); |
1737 List<ConstructorElement> constructors = holder.constructors; | 1760 List<ConstructorElement> constructors = holder.constructors; |
1738 expect(constructors, hasLength(1)); | 1761 expect(constructors, hasLength(1)); |
1739 ConstructorElement constructor = constructors[0]; | 1762 ConstructorElement constructor = constructors[0]; |
1740 expect(constructor, isNotNull); | 1763 expect(constructor, isNotNull); |
1741 expect(constructor.isExternal, isFalse); | 1764 expect(constructor.isExternal, isFalse); |
1742 expect(constructor.isFactory, isFalse); | 1765 expect(constructor.isFactory, isFalse); |
1743 expect(constructor.name, ""); | 1766 expect(constructor.name, ""); |
1744 expect(constructor.functions, hasLength(0)); | |
1745 expect(constructor.parameters, hasLength(0)); | 1767 expect(constructor.parameters, hasLength(0)); |
1746 expect(constructorDeclaration.element, same(constructor)); | 1768 expect(constructorDeclaration.element, same(constructor)); |
1747 } | 1769 } |
1748 | 1770 |
1749 void test_visitEnumDeclaration() { | 1771 void test_visitEnumDeclaration() { |
1750 String enumName = "E"; | 1772 String enumName = "E"; |
1751 EnumDeclaration enumDeclaration = | 1773 EnumDeclaration enumDeclaration = |
1752 AstTestFactory.enumDeclaration2(enumName, ["ONE"]); | 1774 AstTestFactory.enumDeclaration2(enumName, ["ONE"]); |
1753 enumDeclaration.documentationComment = AstTestFactory.documentationComment( | 1775 enumDeclaration.documentationComment = AstTestFactory.documentationComment( |
1754 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1776 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2023 AstTestFactory.formalParameterList(), | 2045 AstTestFactory.formalParameterList(), |
2024 AstTestFactory.emptyFunctionBody()); | 2046 AstTestFactory.emptyFunctionBody()); |
2025 | 2047 |
2026 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2048 ElementHolder holder = buildElementsForAst(methodDeclaration); |
2027 List<MethodElement> methods = holder.methods; | 2049 List<MethodElement> methods = holder.methods; |
2028 expect(methods, hasLength(1)); | 2050 expect(methods, hasLength(1)); |
2029 MethodElement method = methods[0]; | 2051 MethodElement method = methods[0]; |
2030 expect(method, isNotNull); | 2052 expect(method, isNotNull); |
2031 expect(method.hasImplicitReturnType, isTrue); | 2053 expect(method.hasImplicitReturnType, isTrue); |
2032 expect(method.name, methodName); | 2054 expect(method.name, methodName); |
2033 expect(method.functions, hasLength(0)); | |
2034 expect(method.parameters, hasLength(0)); | 2055 expect(method.parameters, hasLength(0)); |
2035 expect(method.typeParameters, hasLength(0)); | 2056 expect(method.typeParameters, hasLength(0)); |
2036 expect(method.isAbstract, isTrue); | 2057 expect(method.isAbstract, isTrue); |
2037 expect(method.isExternal, isFalse); | 2058 expect(method.isExternal, isFalse); |
2038 expect(method.isStatic, isFalse); | 2059 expect(method.isStatic, isFalse); |
2039 expect(method.isSynthetic, isFalse); | 2060 expect(method.isSynthetic, isFalse); |
2040 } | 2061 } |
2041 | 2062 |
2042 void test_visitMethodDeclaration_duplicateField_synthetic() { | 2063 void test_visitMethodDeclaration_duplicateField_synthetic() { |
2043 buildElementsForText(r''' | 2064 buildElementsForText(r''' |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2090 methodDeclaration.externalKeyword = | 2111 methodDeclaration.externalKeyword = |
2091 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 2112 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
2092 | 2113 |
2093 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2114 ElementHolder holder = buildElementsForAst(methodDeclaration); |
2094 List<MethodElement> methods = holder.methods; | 2115 List<MethodElement> methods = holder.methods; |
2095 expect(methods, hasLength(1)); | 2116 expect(methods, hasLength(1)); |
2096 MethodElement method = methods[0]; | 2117 MethodElement method = methods[0]; |
2097 expect(method, isNotNull); | 2118 expect(method, isNotNull); |
2098 expect(method.hasImplicitReturnType, isTrue); | 2119 expect(method.hasImplicitReturnType, isTrue); |
2099 expect(method.name, methodName); | 2120 expect(method.name, methodName); |
2100 expect(method.functions, hasLength(0)); | |
2101 expect(method.parameters, hasLength(0)); | 2121 expect(method.parameters, hasLength(0)); |
2102 expect(method.typeParameters, hasLength(0)); | 2122 expect(method.typeParameters, hasLength(0)); |
2103 expect(method.isAbstract, isFalse); | 2123 expect(method.isAbstract, isFalse); |
2104 expect(method.isExternal, isTrue); | 2124 expect(method.isExternal, isTrue); |
2105 expect(method.isStatic, isFalse); | 2125 expect(method.isStatic, isFalse); |
2106 expect(method.isSynthetic, isFalse); | 2126 expect(method.isSynthetic, isFalse); |
2107 } | 2127 } |
2108 | 2128 |
2109 void test_visitMethodDeclaration_getter() { | 2129 void test_visitMethodDeclaration_getter() { |
2110 // get m() {} | 2130 // get m() {} |
(...skipping 23 matching lines...) Expand all Loading... |
2134 expect(getter, isNotNull); | 2154 expect(getter, isNotNull); |
2135 assertHasCodeRange(getter, 50, 31); | 2155 assertHasCodeRange(getter, 50, 31); |
2136 expect(getter.documentationComment, '/// aaa'); | 2156 expect(getter.documentationComment, '/// aaa'); |
2137 expect(getter.hasImplicitReturnType, isTrue); | 2157 expect(getter.hasImplicitReturnType, isTrue); |
2138 expect(getter.isAbstract, isFalse); | 2158 expect(getter.isAbstract, isFalse); |
2139 expect(getter.isExternal, isFalse); | 2159 expect(getter.isExternal, isFalse); |
2140 expect(getter.isGetter, isTrue); | 2160 expect(getter.isGetter, isTrue); |
2141 expect(getter.isSynthetic, isFalse); | 2161 expect(getter.isSynthetic, isFalse); |
2142 expect(getter.name, methodName); | 2162 expect(getter.name, methodName); |
2143 expect(getter.variable, field); | 2163 expect(getter.variable, field); |
2144 expect(getter.functions, hasLength(0)); | |
2145 expect(getter.parameters, hasLength(0)); | 2164 expect(getter.parameters, hasLength(0)); |
2146 } | 2165 } |
2147 | 2166 |
2148 void test_visitMethodDeclaration_getter_abstract() { | 2167 void test_visitMethodDeclaration_getter_abstract() { |
2149 // get m(); | 2168 // get m(); |
2150 String methodName = "m"; | 2169 String methodName = "m"; |
2151 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2170 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
2152 null, | 2171 null, |
2153 null, | 2172 null, |
2154 Keyword.GET, | 2173 Keyword.GET, |
(...skipping 12 matching lines...) Expand all Loading... |
2167 expect(field.setter, isNull); | 2186 expect(field.setter, isNull); |
2168 PropertyAccessorElement getter = field.getter; | 2187 PropertyAccessorElement getter = field.getter; |
2169 expect(getter, isNotNull); | 2188 expect(getter, isNotNull); |
2170 expect(getter.hasImplicitReturnType, isTrue); | 2189 expect(getter.hasImplicitReturnType, isTrue); |
2171 expect(getter.isAbstract, isTrue); | 2190 expect(getter.isAbstract, isTrue); |
2172 expect(getter.isExternal, isFalse); | 2191 expect(getter.isExternal, isFalse); |
2173 expect(getter.isGetter, isTrue); | 2192 expect(getter.isGetter, isTrue); |
2174 expect(getter.isSynthetic, isFalse); | 2193 expect(getter.isSynthetic, isFalse); |
2175 expect(getter.name, methodName); | 2194 expect(getter.name, methodName); |
2176 expect(getter.variable, field); | 2195 expect(getter.variable, field); |
2177 expect(getter.functions, hasLength(0)); | |
2178 expect(getter.parameters, hasLength(0)); | 2196 expect(getter.parameters, hasLength(0)); |
2179 } | 2197 } |
2180 | 2198 |
2181 void test_visitMethodDeclaration_getter_external() { | 2199 void test_visitMethodDeclaration_getter_external() { |
2182 // external get m(); | 2200 // external get m(); |
2183 String methodName = "m"; | 2201 String methodName = "m"; |
2184 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( | 2202 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( |
2185 null, | 2203 null, |
2186 null, | 2204 null, |
2187 Keyword.GET, | 2205 Keyword.GET, |
(...skipping 13 matching lines...) Expand all Loading... |
2201 expect(field.setter, isNull); | 2219 expect(field.setter, isNull); |
2202 PropertyAccessorElement getter = field.getter; | 2220 PropertyAccessorElement getter = field.getter; |
2203 expect(getter, isNotNull); | 2221 expect(getter, isNotNull); |
2204 expect(getter.hasImplicitReturnType, isTrue); | 2222 expect(getter.hasImplicitReturnType, isTrue); |
2205 expect(getter.isAbstract, isFalse); | 2223 expect(getter.isAbstract, isFalse); |
2206 expect(getter.isExternal, isTrue); | 2224 expect(getter.isExternal, isTrue); |
2207 expect(getter.isGetter, isTrue); | 2225 expect(getter.isGetter, isTrue); |
2208 expect(getter.isSynthetic, isFalse); | 2226 expect(getter.isSynthetic, isFalse); |
2209 expect(getter.name, methodName); | 2227 expect(getter.name, methodName); |
2210 expect(getter.variable, field); | 2228 expect(getter.variable, field); |
2211 expect(getter.functions, hasLength(0)); | |
2212 expect(getter.parameters, hasLength(0)); | 2229 expect(getter.parameters, hasLength(0)); |
2213 } | 2230 } |
2214 | 2231 |
2215 void test_visitMethodDeclaration_minimal() { | 2232 void test_visitMethodDeclaration_minimal() { |
2216 // T m() {} | 2233 // T m() {} |
2217 String methodName = "m"; | 2234 String methodName = "m"; |
2218 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2235 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
2219 null, | 2236 null, |
2220 AstTestFactory.typeName4('T'), | 2237 AstTestFactory.typeName4('T'), |
2221 null, | 2238 null, |
2222 null, | 2239 null, |
2223 AstTestFactory.identifier3(methodName), | 2240 AstTestFactory.identifier3(methodName), |
2224 AstTestFactory.formalParameterList(), | 2241 AstTestFactory.formalParameterList(), |
2225 AstTestFactory.blockFunctionBody2()); | 2242 AstTestFactory.blockFunctionBody2()); |
2226 methodDeclaration.documentationComment = AstTestFactory | 2243 methodDeclaration.documentationComment = AstTestFactory |
2227 .documentationComment( | 2244 .documentationComment( |
2228 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 2245 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
2229 methodDeclaration.endToken.offset = 80; | 2246 methodDeclaration.endToken.offset = 80; |
2230 | 2247 |
2231 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2248 ElementHolder holder = buildElementsForAst(methodDeclaration); |
2232 List<MethodElement> methods = holder.methods; | 2249 List<MethodElement> methods = holder.methods; |
2233 expect(methods, hasLength(1)); | 2250 expect(methods, hasLength(1)); |
2234 MethodElement method = methods[0]; | 2251 MethodElement method = methods[0]; |
2235 expect(method, isNotNull); | 2252 expect(method, isNotNull); |
2236 assertHasCodeRange(method, 50, 31); | 2253 assertHasCodeRange(method, 50, 31); |
2237 expect(method.documentationComment, '/// aaa'); | 2254 expect(method.documentationComment, '/// aaa'); |
2238 expect(method.hasImplicitReturnType, isFalse); | 2255 expect(method.hasImplicitReturnType, isFalse); |
2239 expect(method.name, methodName); | 2256 expect(method.name, methodName); |
2240 expect(method.functions, hasLength(0)); | |
2241 expect(method.parameters, hasLength(0)); | 2257 expect(method.parameters, hasLength(0)); |
2242 expect(method.typeParameters, hasLength(0)); | 2258 expect(method.typeParameters, hasLength(0)); |
2243 expect(method.isAbstract, isFalse); | 2259 expect(method.isAbstract, isFalse); |
2244 expect(method.isExternal, isFalse); | 2260 expect(method.isExternal, isFalse); |
2245 expect(method.isStatic, isFalse); | 2261 expect(method.isStatic, isFalse); |
2246 expect(method.isSynthetic, isFalse); | 2262 expect(method.isSynthetic, isFalse); |
2247 } | 2263 } |
2248 | 2264 |
2249 void test_visitMethodDeclaration_operator() { | 2265 void test_visitMethodDeclaration_operator() { |
2250 // operator +(addend) {} | 2266 // operator +(addend) {} |
2251 String methodName = "+"; | 2267 String methodName = "+"; |
2252 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2268 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
2253 null, | 2269 null, |
2254 null, | 2270 null, |
2255 null, | 2271 null, |
2256 Keyword.OPERATOR, | 2272 Keyword.OPERATOR, |
2257 AstTestFactory.identifier3(methodName), | 2273 AstTestFactory.identifier3(methodName), |
2258 AstTestFactory.formalParameterList( | 2274 AstTestFactory.formalParameterList( |
2259 [AstTestFactory.simpleFormalParameter3("addend")]), | 2275 [AstTestFactory.simpleFormalParameter3("addend")]), |
2260 AstTestFactory.blockFunctionBody2()); | 2276 AstTestFactory.blockFunctionBody2()); |
2261 | 2277 |
2262 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2278 ElementHolder holder = buildElementsForAst(methodDeclaration); |
2263 List<MethodElement> methods = holder.methods; | 2279 List<MethodElement> methods = holder.methods; |
2264 expect(methods, hasLength(1)); | 2280 expect(methods, hasLength(1)); |
2265 MethodElement method = methods[0]; | 2281 MethodElement method = methods[0]; |
2266 expect(method, isNotNull); | 2282 expect(method, isNotNull); |
2267 expect(method.hasImplicitReturnType, isTrue); | 2283 expect(method.hasImplicitReturnType, isTrue); |
2268 expect(method.name, methodName); | 2284 expect(method.name, methodName); |
2269 expect(method.functions, hasLength(0)); | |
2270 expect(method.parameters, hasLength(1)); | 2285 expect(method.parameters, hasLength(1)); |
2271 expect(method.typeParameters, hasLength(0)); | 2286 expect(method.typeParameters, hasLength(0)); |
2272 expect(method.isAbstract, isFalse); | 2287 expect(method.isAbstract, isFalse); |
2273 expect(method.isExternal, isFalse); | 2288 expect(method.isExternal, isFalse); |
2274 expect(method.isStatic, isFalse); | 2289 expect(method.isStatic, isFalse); |
2275 expect(method.isSynthetic, isFalse); | 2290 expect(method.isSynthetic, isFalse); |
2276 } | 2291 } |
2277 | 2292 |
2278 void test_visitMethodDeclaration_setter() { | 2293 void test_visitMethodDeclaration_setter() { |
2279 // set m() {} | 2294 // set m() {} |
(...skipping 25 matching lines...) Expand all Loading... |
2305 assertHasCodeRange(setter, 50, 31); | 2320 assertHasCodeRange(setter, 50, 31); |
2306 expect(setter.documentationComment, '/// aaa'); | 2321 expect(setter.documentationComment, '/// aaa'); |
2307 expect(setter.hasImplicitReturnType, isTrue); | 2322 expect(setter.hasImplicitReturnType, isTrue); |
2308 expect(setter.isAbstract, isFalse); | 2323 expect(setter.isAbstract, isFalse); |
2309 expect(setter.isExternal, isFalse); | 2324 expect(setter.isExternal, isFalse); |
2310 expect(setter.isSetter, isTrue); | 2325 expect(setter.isSetter, isTrue); |
2311 expect(setter.isSynthetic, isFalse); | 2326 expect(setter.isSynthetic, isFalse); |
2312 expect(setter.name, "$methodName="); | 2327 expect(setter.name, "$methodName="); |
2313 expect(setter.displayName, methodName); | 2328 expect(setter.displayName, methodName); |
2314 expect(setter.variable, field); | 2329 expect(setter.variable, field); |
2315 expect(setter.functions, hasLength(0)); | |
2316 expect(setter.parameters, hasLength(0)); | 2330 expect(setter.parameters, hasLength(0)); |
2317 } | 2331 } |
2318 | 2332 |
2319 void test_visitMethodDeclaration_setter_abstract() { | 2333 void test_visitMethodDeclaration_setter_abstract() { |
2320 // set m(); | 2334 // set m(); |
2321 String methodName = "m"; | 2335 String methodName = "m"; |
2322 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2336 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
2323 null, | 2337 null, |
2324 null, | 2338 null, |
2325 Keyword.SET, | 2339 Keyword.SET, |
(...skipping 13 matching lines...) Expand all Loading... |
2339 PropertyAccessorElement setter = field.setter; | 2353 PropertyAccessorElement setter = field.setter; |
2340 expect(setter, isNotNull); | 2354 expect(setter, isNotNull); |
2341 expect(setter.hasImplicitReturnType, isTrue); | 2355 expect(setter.hasImplicitReturnType, isTrue); |
2342 expect(setter.isAbstract, isTrue); | 2356 expect(setter.isAbstract, isTrue); |
2343 expect(setter.isExternal, isFalse); | 2357 expect(setter.isExternal, isFalse); |
2344 expect(setter.isSetter, isTrue); | 2358 expect(setter.isSetter, isTrue); |
2345 expect(setter.isSynthetic, isFalse); | 2359 expect(setter.isSynthetic, isFalse); |
2346 expect(setter.name, "$methodName="); | 2360 expect(setter.name, "$methodName="); |
2347 expect(setter.displayName, methodName); | 2361 expect(setter.displayName, methodName); |
2348 expect(setter.variable, field); | 2362 expect(setter.variable, field); |
2349 expect(setter.functions, hasLength(0)); | |
2350 expect(setter.parameters, hasLength(0)); | 2363 expect(setter.parameters, hasLength(0)); |
2351 } | 2364 } |
2352 | 2365 |
2353 void test_visitMethodDeclaration_setter_external() { | 2366 void test_visitMethodDeclaration_setter_external() { |
2354 // external m(); | 2367 // external m(); |
2355 String methodName = "m"; | 2368 String methodName = "m"; |
2356 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( | 2369 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( |
2357 null, | 2370 null, |
2358 null, | 2371 null, |
2359 Keyword.SET, | 2372 Keyword.SET, |
(...skipping 14 matching lines...) Expand all Loading... |
2374 PropertyAccessorElement setter = field.setter; | 2387 PropertyAccessorElement setter = field.setter; |
2375 expect(setter, isNotNull); | 2388 expect(setter, isNotNull); |
2376 expect(setter.hasImplicitReturnType, isTrue); | 2389 expect(setter.hasImplicitReturnType, isTrue); |
2377 expect(setter.isAbstract, isFalse); | 2390 expect(setter.isAbstract, isFalse); |
2378 expect(setter.isExternal, isTrue); | 2391 expect(setter.isExternal, isTrue); |
2379 expect(setter.isSetter, isTrue); | 2392 expect(setter.isSetter, isTrue); |
2380 expect(setter.isSynthetic, isFalse); | 2393 expect(setter.isSynthetic, isFalse); |
2381 expect(setter.name, "$methodName="); | 2394 expect(setter.name, "$methodName="); |
2382 expect(setter.displayName, methodName); | 2395 expect(setter.displayName, methodName); |
2383 expect(setter.variable, field); | 2396 expect(setter.variable, field); |
2384 expect(setter.functions, hasLength(0)); | |
2385 expect(setter.parameters, hasLength(0)); | 2397 expect(setter.parameters, hasLength(0)); |
2386 } | 2398 } |
2387 | 2399 |
2388 void test_visitMethodDeclaration_static() { | 2400 void test_visitMethodDeclaration_static() { |
2389 // static m() {} | 2401 // static m() {} |
2390 String methodName = "m"; | 2402 String methodName = "m"; |
2391 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2403 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
2392 Keyword.STATIC, | 2404 Keyword.STATIC, |
2393 null, | 2405 null, |
2394 null, | 2406 null, |
2395 null, | 2407 null, |
2396 AstTestFactory.identifier3(methodName), | 2408 AstTestFactory.identifier3(methodName), |
2397 AstTestFactory.formalParameterList(), | 2409 AstTestFactory.formalParameterList(), |
2398 AstTestFactory.blockFunctionBody2()); | 2410 AstTestFactory.blockFunctionBody2()); |
2399 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2411 ElementHolder holder = buildElementsForAst(methodDeclaration); |
2400 List<MethodElement> methods = holder.methods; | 2412 List<MethodElement> methods = holder.methods; |
2401 expect(methods, hasLength(1)); | 2413 expect(methods, hasLength(1)); |
2402 MethodElement method = methods[0]; | 2414 MethodElement method = methods[0]; |
2403 expect(method, isNotNull); | 2415 expect(method, isNotNull); |
2404 expect(method.hasImplicitReturnType, isTrue); | 2416 expect(method.hasImplicitReturnType, isTrue); |
2405 expect(method.name, methodName); | 2417 expect(method.name, methodName); |
2406 expect(method.functions, hasLength(0)); | |
2407 expect(method.parameters, hasLength(0)); | 2418 expect(method.parameters, hasLength(0)); |
2408 expect(method.typeParameters, hasLength(0)); | 2419 expect(method.typeParameters, hasLength(0)); |
2409 expect(method.isAbstract, isFalse); | 2420 expect(method.isAbstract, isFalse); |
2410 expect(method.isExternal, isFalse); | 2421 expect(method.isExternal, isFalse); |
2411 expect(method.isStatic, isTrue); | 2422 expect(method.isStatic, isTrue); |
2412 expect(method.isSynthetic, isFalse); | 2423 expect(method.isSynthetic, isFalse); |
2413 } | 2424 } |
2414 | 2425 |
2415 void test_visitMethodDeclaration_typeParameters() { | 2426 void test_visitMethodDeclaration_typeParameters() { |
2416 // m<E>() {} | 2427 // m<E>() {} |
2417 String methodName = "m"; | 2428 String methodName = "m"; |
2418 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( | 2429 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( |
2419 null, | 2430 null, |
2420 null, | 2431 null, |
2421 null, | 2432 null, |
2422 null, | 2433 null, |
2423 AstTestFactory.identifier3(methodName), | 2434 AstTestFactory.identifier3(methodName), |
2424 AstTestFactory.formalParameterList(), | 2435 AstTestFactory.formalParameterList(), |
2425 AstTestFactory.blockFunctionBody2()); | 2436 AstTestFactory.blockFunctionBody2()); |
2426 methodDeclaration.typeParameters = AstTestFactory.typeParameterList(['E']); | 2437 methodDeclaration.typeParameters = AstTestFactory.typeParameterList(['E']); |
2427 | 2438 |
2428 ElementHolder holder = buildElementsForAst(methodDeclaration); | 2439 ElementHolder holder = buildElementsForAst(methodDeclaration); |
2429 List<MethodElement> methods = holder.methods; | 2440 List<MethodElement> methods = holder.methods; |
2430 expect(methods, hasLength(1)); | 2441 expect(methods, hasLength(1)); |
2431 MethodElement method = methods[0]; | 2442 MethodElement method = methods[0]; |
2432 expect(method, isNotNull); | 2443 expect(method, isNotNull); |
2433 expect(method.hasImplicitReturnType, isTrue); | 2444 expect(method.hasImplicitReturnType, isTrue); |
2434 expect(method.name, methodName); | 2445 expect(method.name, methodName); |
2435 expect(method.functions, hasLength(0)); | |
2436 expect(method.parameters, hasLength(0)); | 2446 expect(method.parameters, hasLength(0)); |
2437 expect(method.typeParameters, hasLength(1)); | 2447 expect(method.typeParameters, hasLength(1)); |
2438 expect(method.isAbstract, isFalse); | 2448 expect(method.isAbstract, isFalse); |
2439 expect(method.isExternal, isFalse); | 2449 expect(method.isExternal, isFalse); |
2440 expect(method.isStatic, isFalse); | 2450 expect(method.isStatic, isFalse); |
2441 expect(method.isSynthetic, isFalse); | 2451 expect(method.isSynthetic, isFalse); |
2442 } | 2452 } |
2443 | 2453 |
2444 void test_visitTypeAlias_minimal() { | 2454 void test_visitTypeAlias_minimal() { |
2445 String aliasName = "F"; | 2455 String aliasName = "F"; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2589 expect(elementAnnotation.compilationUnit, isNotNull); | 2599 expect(elementAnnotation.compilationUnit, isNotNull); |
2590 expect(elementAnnotation.compilationUnit, compilationUnitElement); | 2600 expect(elementAnnotation.compilationUnit, compilationUnitElement); |
2591 } | 2601 } |
2592 | 2602 |
2593 AstVisitor createElementBuilder(ElementHolder holder); | 2603 AstVisitor createElementBuilder(ElementHolder holder); |
2594 | 2604 |
2595 SimpleIdentifier findIdentifier(String code, String prefix) { | 2605 SimpleIdentifier findIdentifier(String code, String prefix) { |
2596 return EngineTestCase.findSimpleIdentifier(compilationUnit, code, prefix); | 2606 return EngineTestCase.findSimpleIdentifier(compilationUnit, code, prefix); |
2597 } | 2607 } |
2598 | 2608 |
| 2609 LabelElement findLabel(String code, String prefix) { |
| 2610 return findIdentifier(code, prefix).staticElement; |
| 2611 } |
| 2612 |
| 2613 FunctionElement findLocalFunction(String code, String prefix) { |
| 2614 return findIdentifier(code, prefix).staticElement; |
| 2615 } |
| 2616 |
2599 LocalVariableElement findLocalVariable(String code, String prefix) { | 2617 LocalVariableElement findLocalVariable(String code, String prefix) { |
2600 return findIdentifier(code, prefix).staticElement; | 2618 return findIdentifier(code, prefix).staticElement; |
2601 } | 2619 } |
2602 | 2620 |
2603 LabelElement findLabel(String code, String prefix) { | |
2604 return findIdentifier(code, prefix).staticElement; | |
2605 } | |
2606 | |
2607 void setUp() { | 2621 void setUp() { |
2608 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); | 2622 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); |
2609 } | 2623 } |
2610 | 2624 |
2611 void _assertVisibleRange(LocalElement element, int offset, int end) { | 2625 void _assertVisibleRange(LocalElement element, int offset, int end) { |
2612 SourceRange visibleRange = element.visibleRange; | 2626 SourceRange visibleRange = element.visibleRange; |
2613 expect(visibleRange.offset, offset); | 2627 expect(visibleRange.offset, offset); |
2614 expect(visibleRange.end, end); | 2628 expect(visibleRange.end, end); |
2615 } | 2629 } |
2616 | 2630 |
2617 /** | 2631 /** |
2618 * Parse the given [code], and visit it with the given [visitor]. | 2632 * Parse the given [code], and visit it with the given [visitor]. |
2619 * Fail if any error is logged. | 2633 * Fail if any error is logged. |
2620 */ | 2634 */ |
2621 void _visitAstOfCode(String code, AstVisitor visitor) { | 2635 void _visitAstOfCode(String code, AstVisitor visitor) { |
2622 TestLogger logger = new TestLogger(); | 2636 TestLogger logger = new TestLogger(); |
2623 AnalysisEngine.instance.logger = logger; | 2637 AnalysisEngine.instance.logger = logger; |
2624 try { | 2638 try { |
2625 _compilationUnit = parseCompilationUnit(code); | 2639 _compilationUnit = parseCompilationUnit(code); |
2626 compilationUnit.accept(visitor); | 2640 compilationUnit.accept(visitor); |
2627 } finally { | 2641 } finally { |
2628 expect(logger.log, hasLength(0)); | 2642 expect(logger.log, hasLength(0)); |
2629 AnalysisEngine.instance.logger = Logger.NULL; | 2643 AnalysisEngine.instance.logger = Logger.NULL; |
2630 } | 2644 } |
2631 } | 2645 } |
2632 } | 2646 } |
OLD | NEW |