Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: pkg/analyzer/test/dart/element/builder_test.dart

Issue 2974513002: Remove ExecutableElement.labels usages in tests. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 expect(parameter.initializer, isNull); 474 expect(parameter.initializer, isNull);
475 expect(parameter.isConst, isFalse); 475 expect(parameter.isConst, isFalse);
476 expect(parameter.isFinal, isFalse); 476 expect(parameter.isFinal, isFalse);
477 expect(parameter.isSynthetic, isFalse); 477 expect(parameter.isSynthetic, isFalse);
478 expect(parameter.parameterKind, ParameterKind.REQUIRED); 478 expect(parameter.parameterKind, ParameterKind.REQUIRED);
479 expect(parameter.typeParameters, hasLength(1)); 479 expect(parameter.typeParameters, hasLength(1));
480 _assertVisibleRange(parameter, 100, 110); 480 _assertVisibleRange(parameter, 100, 110);
481 } 481 }
482 482
483 void test_visitLabeledStatement() { 483 void test_visitLabeledStatement() {
484 List<LabelElement> labels = 484 String code = 'f() { l: print(42); }';
485 buildElementsForText('f() { l: print(42); }').functions[0].labels; 485 buildElementsForText(code);
486 expect(labels, hasLength(1)); 486 LabelElement label = findLabel(code, 'l:');
487 LabelElement label = labels[0];
488 expect(label, isNotNull); 487 expect(label, isNotNull);
489 expect(label.name, 'l'); 488 expect(label.name, 'l');
490 expect(label.isSynthetic, isFalse); 489 expect(label.isSynthetic, isFalse);
491 } 490 }
492 491
493 void test_visitMethodDeclaration_withMembers() { 492 void test_visitMethodDeclaration_withMembers() {
494 var code = 'class C { m(p) { var v; try { l: return; } catch (e) {} } }'; 493 var code = 'class C { m(p) { var v; try { l: return; } catch (e) {} } }';
495 MethodElement method = buildElementsForText(code).types[0].methods[0]; 494 MethodElement method = buildElementsForText(code).types[0].methods[0];
496 String methodName = "m"; 495 String methodName = "m";
497 String parameterName = "p"; 496 String parameterName = "p";
(...skipping 11 matching lines...) Expand all
509 VariableElement parameter = parameters[0]; 508 VariableElement parameter = parameters[0];
510 expect(parameter, isNotNull); 509 expect(parameter, isNotNull);
511 expect(parameter.name, parameterName); 510 expect(parameter.name, parameterName);
512 511
513 var v = findLocalVariable(code, 'v;'); 512 var v = findLocalVariable(code, 'v;');
514 expect(v.name, 'v'); 513 expect(v.name, 'v');
515 514
516 var e = findLocalVariable(code, 'e) {}'); 515 var e = findLocalVariable(code, 'e) {}');
517 expect(e.name, 'e'); 516 expect(e.name, 'e');
518 517
519 List<LabelElement> labels = method.labels; 518 LabelElement label = findLabel(code, 'l:');
520 expect(labels, hasLength(1));
521 LabelElement label = labels[0];
522 expect(label, isNotNull); 519 expect(label, isNotNull);
523 expect(label.name, labelName); 520 expect(label.name, labelName);
524 } 521 }
525 522
526 void test_visitNamedFormalParameter() { 523 void test_visitNamedFormalParameter() {
527 ElementHolder holder = new ElementHolder(); 524 ElementHolder holder = new ElementHolder();
528 ElementBuilder builder = _makeBuilder(holder); 525 ElementBuilder builder = _makeBuilder(holder);
529 String parameterName = "p"; 526 String parameterName = "p";
530 DefaultFormalParameter formalParameter = 527 DefaultFormalParameter formalParameter =
531 AstTestFactory.namedFormalParameter( 528 AstTestFactory.namedFormalParameter(
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 1630
1634 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1631 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1635 List<ConstructorElement> constructors = holder.constructors; 1632 List<ConstructorElement> constructors = holder.constructors;
1636 expect(constructors, hasLength(1)); 1633 expect(constructors, hasLength(1));
1637 ConstructorElement constructor = constructors[0]; 1634 ConstructorElement constructor = constructors[0];
1638 expect(constructor, isNotNull); 1635 expect(constructor, isNotNull);
1639 expect(constructor.isExternal, isTrue); 1636 expect(constructor.isExternal, isTrue);
1640 expect(constructor.isFactory, isFalse); 1637 expect(constructor.isFactory, isFalse);
1641 expect(constructor.name, ""); 1638 expect(constructor.name, "");
1642 expect(constructor.functions, hasLength(0)); 1639 expect(constructor.functions, hasLength(0));
1643 expect(constructor.labels, hasLength(0));
1644 expect(constructor.parameters, hasLength(0)); 1640 expect(constructor.parameters, hasLength(0));
1645 } 1641 }
1646 1642
1647 void test_visitConstructorDeclaration_factory() { 1643 void test_visitConstructorDeclaration_factory() {
1648 String className = "A"; 1644 String className = "A";
1649 ConstructorDeclaration constructorDeclaration = 1645 ConstructorDeclaration constructorDeclaration =
1650 AstTestFactory.constructorDeclaration2( 1646 AstTestFactory.constructorDeclaration2(
1651 null, 1647 null,
1652 Keyword.FACTORY, 1648 Keyword.FACTORY,
1653 AstTestFactory.identifier3(className), 1649 AstTestFactory.identifier3(className),
1654 null, 1650 null,
1655 AstTestFactory.formalParameterList(), 1651 AstTestFactory.formalParameterList(),
1656 null, 1652 null,
1657 AstTestFactory.blockFunctionBody2()); 1653 AstTestFactory.blockFunctionBody2());
1658 1654
1659 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1655 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1660 List<ConstructorElement> constructors = holder.constructors; 1656 List<ConstructorElement> constructors = holder.constructors;
1661 expect(constructors, hasLength(1)); 1657 expect(constructors, hasLength(1));
1662 ConstructorElement constructor = constructors[0]; 1658 ConstructorElement constructor = constructors[0];
1663 expect(constructor, isNotNull); 1659 expect(constructor, isNotNull);
1664 expect(constructor.isExternal, isFalse); 1660 expect(constructor.isExternal, isFalse);
1665 expect(constructor.isFactory, isTrue); 1661 expect(constructor.isFactory, isTrue);
1666 expect(constructor.name, ""); 1662 expect(constructor.name, "");
1667 expect(constructor.functions, hasLength(0)); 1663 expect(constructor.functions, hasLength(0));
1668 expect(constructor.labels, hasLength(0));
1669 expect(constructor.parameters, hasLength(0)); 1664 expect(constructor.parameters, hasLength(0));
1670 } 1665 }
1671 1666
1672 void test_visitConstructorDeclaration_minimal() { 1667 void test_visitConstructorDeclaration_minimal() {
1673 String className = "A"; 1668 String className = "A";
1674 ConstructorDeclaration constructorDeclaration = 1669 ConstructorDeclaration constructorDeclaration =
1675 AstTestFactory.constructorDeclaration2( 1670 AstTestFactory.constructorDeclaration2(
1676 null, 1671 null,
1677 null, 1672 null,
1678 AstTestFactory.identifier3(className), 1673 AstTestFactory.identifier3(className),
(...skipping 10 matching lines...) Expand all
1689 List<ConstructorElement> constructors = holder.constructors; 1684 List<ConstructorElement> constructors = holder.constructors;
1690 expect(constructors, hasLength(1)); 1685 expect(constructors, hasLength(1));
1691 ConstructorElement constructor = constructors[0]; 1686 ConstructorElement constructor = constructors[0];
1692 expect(constructor, isNotNull); 1687 expect(constructor, isNotNull);
1693 assertHasCodeRange(constructor, 50, 31); 1688 assertHasCodeRange(constructor, 50, 31);
1694 expect(constructor.documentationComment, '/// aaa'); 1689 expect(constructor.documentationComment, '/// aaa');
1695 expect(constructor.isExternal, isFalse); 1690 expect(constructor.isExternal, isFalse);
1696 expect(constructor.isFactory, isFalse); 1691 expect(constructor.isFactory, isFalse);
1697 expect(constructor.name, ""); 1692 expect(constructor.name, "");
1698 expect(constructor.functions, hasLength(0)); 1693 expect(constructor.functions, hasLength(0));
1699 expect(constructor.labels, hasLength(0));
1700 expect(constructor.parameters, hasLength(0)); 1694 expect(constructor.parameters, hasLength(0));
1701 } 1695 }
1702 1696
1703 void test_visitConstructorDeclaration_named() { 1697 void test_visitConstructorDeclaration_named() {
1704 String className = "A"; 1698 String className = "A";
1705 String constructorName = "c"; 1699 String constructorName = "c";
1706 ConstructorDeclaration constructorDeclaration = 1700 ConstructorDeclaration constructorDeclaration =
1707 AstTestFactory.constructorDeclaration2( 1701 AstTestFactory.constructorDeclaration2(
1708 null, 1702 null,
1709 null, 1703 null,
1710 AstTestFactory.identifier3(className), 1704 AstTestFactory.identifier3(className),
1711 constructorName, 1705 constructorName,
1712 AstTestFactory.formalParameterList(), 1706 AstTestFactory.formalParameterList(),
1713 null, 1707 null,
1714 AstTestFactory.blockFunctionBody2()); 1708 AstTestFactory.blockFunctionBody2());
1715 1709
1716 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1710 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1717 List<ConstructorElement> constructors = holder.constructors; 1711 List<ConstructorElement> constructors = holder.constructors;
1718 expect(constructors, hasLength(1)); 1712 expect(constructors, hasLength(1));
1719 ConstructorElement constructor = constructors[0]; 1713 ConstructorElement constructor = constructors[0];
1720 expect(constructor, isNotNull); 1714 expect(constructor, isNotNull);
1721 expect(constructor.isExternal, isFalse); 1715 expect(constructor.isExternal, isFalse);
1722 expect(constructor.isFactory, isFalse); 1716 expect(constructor.isFactory, isFalse);
1723 expect(constructor.name, constructorName); 1717 expect(constructor.name, constructorName);
1724 expect(constructor.functions, hasLength(0)); 1718 expect(constructor.functions, hasLength(0));
1725 expect(constructor.labels, hasLength(0));
1726 expect(constructor.parameters, hasLength(0)); 1719 expect(constructor.parameters, hasLength(0));
1727 expect(constructorDeclaration.name.staticElement, same(constructor)); 1720 expect(constructorDeclaration.name.staticElement, same(constructor));
1728 expect(constructorDeclaration.element, same(constructor)); 1721 expect(constructorDeclaration.element, same(constructor));
1729 } 1722 }
1730 1723
1731 void test_visitConstructorDeclaration_unnamed() { 1724 void test_visitConstructorDeclaration_unnamed() {
1732 String className = "A"; 1725 String className = "A";
1733 ConstructorDeclaration constructorDeclaration = 1726 ConstructorDeclaration constructorDeclaration =
1734 AstTestFactory.constructorDeclaration2( 1727 AstTestFactory.constructorDeclaration2(
1735 null, 1728 null,
1736 null, 1729 null,
1737 AstTestFactory.identifier3(className), 1730 AstTestFactory.identifier3(className),
1738 null, 1731 null,
1739 AstTestFactory.formalParameterList(), 1732 AstTestFactory.formalParameterList(),
1740 null, 1733 null,
1741 AstTestFactory.blockFunctionBody2()); 1734 AstTestFactory.blockFunctionBody2());
1742 1735
1743 ElementHolder holder = buildElementsForAst(constructorDeclaration); 1736 ElementHolder holder = buildElementsForAst(constructorDeclaration);
1744 List<ConstructorElement> constructors = holder.constructors; 1737 List<ConstructorElement> constructors = holder.constructors;
1745 expect(constructors, hasLength(1)); 1738 expect(constructors, hasLength(1));
1746 ConstructorElement constructor = constructors[0]; 1739 ConstructorElement constructor = constructors[0];
1747 expect(constructor, isNotNull); 1740 expect(constructor, isNotNull);
1748 expect(constructor.isExternal, isFalse); 1741 expect(constructor.isExternal, isFalse);
1749 expect(constructor.isFactory, isFalse); 1742 expect(constructor.isFactory, isFalse);
1750 expect(constructor.name, ""); 1743 expect(constructor.name, "");
1751 expect(constructor.functions, hasLength(0)); 1744 expect(constructor.functions, hasLength(0));
1752 expect(constructor.labels, hasLength(0));
1753 expect(constructor.parameters, hasLength(0)); 1745 expect(constructor.parameters, hasLength(0));
1754 expect(constructorDeclaration.element, same(constructor)); 1746 expect(constructorDeclaration.element, same(constructor));
1755 } 1747 }
1756 1748
1757 void test_visitEnumDeclaration() { 1749 void test_visitEnumDeclaration() {
1758 String enumName = "E"; 1750 String enumName = "E";
1759 EnumDeclaration enumDeclaration = 1751 EnumDeclaration enumDeclaration =
1760 AstTestFactory.enumDeclaration2(enumName, ["ONE"]); 1752 AstTestFactory.enumDeclaration2(enumName, ["ONE"]);
1761 enumDeclaration.documentationComment = AstTestFactory.documentationComment( 1753 enumDeclaration.documentationComment = AstTestFactory.documentationComment(
1762 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 1754 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 AstTestFactory.emptyFunctionBody()); 2024 AstTestFactory.emptyFunctionBody());
2033 2025
2034 ElementHolder holder = buildElementsForAst(methodDeclaration); 2026 ElementHolder holder = buildElementsForAst(methodDeclaration);
2035 List<MethodElement> methods = holder.methods; 2027 List<MethodElement> methods = holder.methods;
2036 expect(methods, hasLength(1)); 2028 expect(methods, hasLength(1));
2037 MethodElement method = methods[0]; 2029 MethodElement method = methods[0];
2038 expect(method, isNotNull); 2030 expect(method, isNotNull);
2039 expect(method.hasImplicitReturnType, isTrue); 2031 expect(method.hasImplicitReturnType, isTrue);
2040 expect(method.name, methodName); 2032 expect(method.name, methodName);
2041 expect(method.functions, hasLength(0)); 2033 expect(method.functions, hasLength(0));
2042 expect(method.labels, hasLength(0));
2043 expect(method.parameters, hasLength(0)); 2034 expect(method.parameters, hasLength(0));
2044 expect(method.typeParameters, hasLength(0)); 2035 expect(method.typeParameters, hasLength(0));
2045 expect(method.isAbstract, isTrue); 2036 expect(method.isAbstract, isTrue);
2046 expect(method.isExternal, isFalse); 2037 expect(method.isExternal, isFalse);
2047 expect(method.isStatic, isFalse); 2038 expect(method.isStatic, isFalse);
2048 expect(method.isSynthetic, isFalse); 2039 expect(method.isSynthetic, isFalse);
2049 } 2040 }
2050 2041
2051 void test_visitMethodDeclaration_duplicateField_synthetic() { 2042 void test_visitMethodDeclaration_duplicateField_synthetic() {
2052 buildElementsForText(r''' 2043 buildElementsForText(r'''
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); 2091 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
2101 2092
2102 ElementHolder holder = buildElementsForAst(methodDeclaration); 2093 ElementHolder holder = buildElementsForAst(methodDeclaration);
2103 List<MethodElement> methods = holder.methods; 2094 List<MethodElement> methods = holder.methods;
2104 expect(methods, hasLength(1)); 2095 expect(methods, hasLength(1));
2105 MethodElement method = methods[0]; 2096 MethodElement method = methods[0];
2106 expect(method, isNotNull); 2097 expect(method, isNotNull);
2107 expect(method.hasImplicitReturnType, isTrue); 2098 expect(method.hasImplicitReturnType, isTrue);
2108 expect(method.name, methodName); 2099 expect(method.name, methodName);
2109 expect(method.functions, hasLength(0)); 2100 expect(method.functions, hasLength(0));
2110 expect(method.labels, hasLength(0));
2111 expect(method.parameters, hasLength(0)); 2101 expect(method.parameters, hasLength(0));
2112 expect(method.typeParameters, hasLength(0)); 2102 expect(method.typeParameters, hasLength(0));
2113 expect(method.isAbstract, isFalse); 2103 expect(method.isAbstract, isFalse);
2114 expect(method.isExternal, isTrue); 2104 expect(method.isExternal, isTrue);
2115 expect(method.isStatic, isFalse); 2105 expect(method.isStatic, isFalse);
2116 expect(method.isSynthetic, isFalse); 2106 expect(method.isSynthetic, isFalse);
2117 } 2107 }
2118 2108
2119 void test_visitMethodDeclaration_getter() { 2109 void test_visitMethodDeclaration_getter() {
2120 // get m() {} 2110 // get m() {}
(...skipping 24 matching lines...) Expand all
2145 assertHasCodeRange(getter, 50, 31); 2135 assertHasCodeRange(getter, 50, 31);
2146 expect(getter.documentationComment, '/// aaa'); 2136 expect(getter.documentationComment, '/// aaa');
2147 expect(getter.hasImplicitReturnType, isTrue); 2137 expect(getter.hasImplicitReturnType, isTrue);
2148 expect(getter.isAbstract, isFalse); 2138 expect(getter.isAbstract, isFalse);
2149 expect(getter.isExternal, isFalse); 2139 expect(getter.isExternal, isFalse);
2150 expect(getter.isGetter, isTrue); 2140 expect(getter.isGetter, isTrue);
2151 expect(getter.isSynthetic, isFalse); 2141 expect(getter.isSynthetic, isFalse);
2152 expect(getter.name, methodName); 2142 expect(getter.name, methodName);
2153 expect(getter.variable, field); 2143 expect(getter.variable, field);
2154 expect(getter.functions, hasLength(0)); 2144 expect(getter.functions, hasLength(0));
2155 expect(getter.labels, hasLength(0));
2156 expect(getter.parameters, hasLength(0)); 2145 expect(getter.parameters, hasLength(0));
2157 } 2146 }
2158 2147
2159 void test_visitMethodDeclaration_getter_abstract() { 2148 void test_visitMethodDeclaration_getter_abstract() {
2160 // get m(); 2149 // get m();
2161 String methodName = "m"; 2150 String methodName = "m";
2162 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( 2151 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2163 null, 2152 null,
2164 null, 2153 null,
2165 Keyword.GET, 2154 Keyword.GET,
(...skipping 13 matching lines...) Expand all
2179 PropertyAccessorElement getter = field.getter; 2168 PropertyAccessorElement getter = field.getter;
2180 expect(getter, isNotNull); 2169 expect(getter, isNotNull);
2181 expect(getter.hasImplicitReturnType, isTrue); 2170 expect(getter.hasImplicitReturnType, isTrue);
2182 expect(getter.isAbstract, isTrue); 2171 expect(getter.isAbstract, isTrue);
2183 expect(getter.isExternal, isFalse); 2172 expect(getter.isExternal, isFalse);
2184 expect(getter.isGetter, isTrue); 2173 expect(getter.isGetter, isTrue);
2185 expect(getter.isSynthetic, isFalse); 2174 expect(getter.isSynthetic, isFalse);
2186 expect(getter.name, methodName); 2175 expect(getter.name, methodName);
2187 expect(getter.variable, field); 2176 expect(getter.variable, field);
2188 expect(getter.functions, hasLength(0)); 2177 expect(getter.functions, hasLength(0));
2189 expect(getter.labels, hasLength(0));
2190 expect(getter.parameters, hasLength(0)); 2178 expect(getter.parameters, hasLength(0));
2191 } 2179 }
2192 2180
2193 void test_visitMethodDeclaration_getter_external() { 2181 void test_visitMethodDeclaration_getter_external() {
2194 // external get m(); 2182 // external get m();
2195 String methodName = "m"; 2183 String methodName = "m";
2196 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( 2184 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration(
2197 null, 2185 null,
2198 null, 2186 null,
2199 Keyword.GET, 2187 Keyword.GET,
(...skipping 14 matching lines...) Expand all
2214 PropertyAccessorElement getter = field.getter; 2202 PropertyAccessorElement getter = field.getter;
2215 expect(getter, isNotNull); 2203 expect(getter, isNotNull);
2216 expect(getter.hasImplicitReturnType, isTrue); 2204 expect(getter.hasImplicitReturnType, isTrue);
2217 expect(getter.isAbstract, isFalse); 2205 expect(getter.isAbstract, isFalse);
2218 expect(getter.isExternal, isTrue); 2206 expect(getter.isExternal, isTrue);
2219 expect(getter.isGetter, isTrue); 2207 expect(getter.isGetter, isTrue);
2220 expect(getter.isSynthetic, isFalse); 2208 expect(getter.isSynthetic, isFalse);
2221 expect(getter.name, methodName); 2209 expect(getter.name, methodName);
2222 expect(getter.variable, field); 2210 expect(getter.variable, field);
2223 expect(getter.functions, hasLength(0)); 2211 expect(getter.functions, hasLength(0));
2224 expect(getter.labels, hasLength(0));
2225 expect(getter.parameters, hasLength(0)); 2212 expect(getter.parameters, hasLength(0));
2226 } 2213 }
2227 2214
2228 void test_visitMethodDeclaration_minimal() { 2215 void test_visitMethodDeclaration_minimal() {
2229 // T m() {} 2216 // T m() {}
2230 String methodName = "m"; 2217 String methodName = "m";
2231 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( 2218 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2232 null, 2219 null,
2233 AstTestFactory.typeName4('T'), 2220 AstTestFactory.typeName4('T'),
2234 null, 2221 null,
2235 null, 2222 null,
2236 AstTestFactory.identifier3(methodName), 2223 AstTestFactory.identifier3(methodName),
2237 AstTestFactory.formalParameterList(), 2224 AstTestFactory.formalParameterList(),
2238 AstTestFactory.blockFunctionBody2()); 2225 AstTestFactory.blockFunctionBody2());
2239 methodDeclaration.documentationComment = AstTestFactory 2226 methodDeclaration.documentationComment = AstTestFactory
2240 .documentationComment( 2227 .documentationComment(
2241 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 2228 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
2242 methodDeclaration.endToken.offset = 80; 2229 methodDeclaration.endToken.offset = 80;
2243 2230
2244 ElementHolder holder = buildElementsForAst(methodDeclaration); 2231 ElementHolder holder = buildElementsForAst(methodDeclaration);
2245 List<MethodElement> methods = holder.methods; 2232 List<MethodElement> methods = holder.methods;
2246 expect(methods, hasLength(1)); 2233 expect(methods, hasLength(1));
2247 MethodElement method = methods[0]; 2234 MethodElement method = methods[0];
2248 expect(method, isNotNull); 2235 expect(method, isNotNull);
2249 assertHasCodeRange(method, 50, 31); 2236 assertHasCodeRange(method, 50, 31);
2250 expect(method.documentationComment, '/// aaa'); 2237 expect(method.documentationComment, '/// aaa');
2251 expect(method.hasImplicitReturnType, isFalse); 2238 expect(method.hasImplicitReturnType, isFalse);
2252 expect(method.name, methodName); 2239 expect(method.name, methodName);
2253 expect(method.functions, hasLength(0)); 2240 expect(method.functions, hasLength(0));
2254 expect(method.labels, hasLength(0));
2255 expect(method.parameters, hasLength(0)); 2241 expect(method.parameters, hasLength(0));
2256 expect(method.typeParameters, hasLength(0)); 2242 expect(method.typeParameters, hasLength(0));
2257 expect(method.isAbstract, isFalse); 2243 expect(method.isAbstract, isFalse);
2258 expect(method.isExternal, isFalse); 2244 expect(method.isExternal, isFalse);
2259 expect(method.isStatic, isFalse); 2245 expect(method.isStatic, isFalse);
2260 expect(method.isSynthetic, isFalse); 2246 expect(method.isSynthetic, isFalse);
2261 } 2247 }
2262 2248
2263 void test_visitMethodDeclaration_operator() { 2249 void test_visitMethodDeclaration_operator() {
2264 // operator +(addend) {} 2250 // operator +(addend) {}
2265 String methodName = "+"; 2251 String methodName = "+";
2266 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( 2252 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2267 null, 2253 null,
2268 null, 2254 null,
2269 null, 2255 null,
2270 Keyword.OPERATOR, 2256 Keyword.OPERATOR,
2271 AstTestFactory.identifier3(methodName), 2257 AstTestFactory.identifier3(methodName),
2272 AstTestFactory.formalParameterList( 2258 AstTestFactory.formalParameterList(
2273 [AstTestFactory.simpleFormalParameter3("addend")]), 2259 [AstTestFactory.simpleFormalParameter3("addend")]),
2274 AstTestFactory.blockFunctionBody2()); 2260 AstTestFactory.blockFunctionBody2());
2275 2261
2276 ElementHolder holder = buildElementsForAst(methodDeclaration); 2262 ElementHolder holder = buildElementsForAst(methodDeclaration);
2277 List<MethodElement> methods = holder.methods; 2263 List<MethodElement> methods = holder.methods;
2278 expect(methods, hasLength(1)); 2264 expect(methods, hasLength(1));
2279 MethodElement method = methods[0]; 2265 MethodElement method = methods[0];
2280 expect(method, isNotNull); 2266 expect(method, isNotNull);
2281 expect(method.hasImplicitReturnType, isTrue); 2267 expect(method.hasImplicitReturnType, isTrue);
2282 expect(method.name, methodName); 2268 expect(method.name, methodName);
2283 expect(method.functions, hasLength(0)); 2269 expect(method.functions, hasLength(0));
2284 expect(method.labels, hasLength(0));
2285 expect(method.parameters, hasLength(1)); 2270 expect(method.parameters, hasLength(1));
2286 expect(method.typeParameters, hasLength(0)); 2271 expect(method.typeParameters, hasLength(0));
2287 expect(method.isAbstract, isFalse); 2272 expect(method.isAbstract, isFalse);
2288 expect(method.isExternal, isFalse); 2273 expect(method.isExternal, isFalse);
2289 expect(method.isStatic, isFalse); 2274 expect(method.isStatic, isFalse);
2290 expect(method.isSynthetic, isFalse); 2275 expect(method.isSynthetic, isFalse);
2291 } 2276 }
2292 2277
2293 void test_visitMethodDeclaration_setter() { 2278 void test_visitMethodDeclaration_setter() {
2294 // set m() {} 2279 // set m() {}
(...skipping 26 matching lines...) Expand all
2321 expect(setter.documentationComment, '/// aaa'); 2306 expect(setter.documentationComment, '/// aaa');
2322 expect(setter.hasImplicitReturnType, isTrue); 2307 expect(setter.hasImplicitReturnType, isTrue);
2323 expect(setter.isAbstract, isFalse); 2308 expect(setter.isAbstract, isFalse);
2324 expect(setter.isExternal, isFalse); 2309 expect(setter.isExternal, isFalse);
2325 expect(setter.isSetter, isTrue); 2310 expect(setter.isSetter, isTrue);
2326 expect(setter.isSynthetic, isFalse); 2311 expect(setter.isSynthetic, isFalse);
2327 expect(setter.name, "$methodName="); 2312 expect(setter.name, "$methodName=");
2328 expect(setter.displayName, methodName); 2313 expect(setter.displayName, methodName);
2329 expect(setter.variable, field); 2314 expect(setter.variable, field);
2330 expect(setter.functions, hasLength(0)); 2315 expect(setter.functions, hasLength(0));
2331 expect(setter.labels, hasLength(0));
2332 expect(setter.parameters, hasLength(0)); 2316 expect(setter.parameters, hasLength(0));
2333 } 2317 }
2334 2318
2335 void test_visitMethodDeclaration_setter_abstract() { 2319 void test_visitMethodDeclaration_setter_abstract() {
2336 // set m(); 2320 // set m();
2337 String methodName = "m"; 2321 String methodName = "m";
2338 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( 2322 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2339 null, 2323 null,
2340 null, 2324 null,
2341 Keyword.SET, 2325 Keyword.SET,
(...skipping 14 matching lines...) Expand all
2356 expect(setter, isNotNull); 2340 expect(setter, isNotNull);
2357 expect(setter.hasImplicitReturnType, isTrue); 2341 expect(setter.hasImplicitReturnType, isTrue);
2358 expect(setter.isAbstract, isTrue); 2342 expect(setter.isAbstract, isTrue);
2359 expect(setter.isExternal, isFalse); 2343 expect(setter.isExternal, isFalse);
2360 expect(setter.isSetter, isTrue); 2344 expect(setter.isSetter, isTrue);
2361 expect(setter.isSynthetic, isFalse); 2345 expect(setter.isSynthetic, isFalse);
2362 expect(setter.name, "$methodName="); 2346 expect(setter.name, "$methodName=");
2363 expect(setter.displayName, methodName); 2347 expect(setter.displayName, methodName);
2364 expect(setter.variable, field); 2348 expect(setter.variable, field);
2365 expect(setter.functions, hasLength(0)); 2349 expect(setter.functions, hasLength(0));
2366 expect(setter.labels, hasLength(0));
2367 expect(setter.parameters, hasLength(0)); 2350 expect(setter.parameters, hasLength(0));
2368 } 2351 }
2369 2352
2370 void test_visitMethodDeclaration_setter_external() { 2353 void test_visitMethodDeclaration_setter_external() {
2371 // external m(); 2354 // external m();
2372 String methodName = "m"; 2355 String methodName = "m";
2373 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration( 2356 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration(
2374 null, 2357 null,
2375 null, 2358 null,
2376 Keyword.SET, 2359 Keyword.SET,
(...skipping 15 matching lines...) Expand all
2392 expect(setter, isNotNull); 2375 expect(setter, isNotNull);
2393 expect(setter.hasImplicitReturnType, isTrue); 2376 expect(setter.hasImplicitReturnType, isTrue);
2394 expect(setter.isAbstract, isFalse); 2377 expect(setter.isAbstract, isFalse);
2395 expect(setter.isExternal, isTrue); 2378 expect(setter.isExternal, isTrue);
2396 expect(setter.isSetter, isTrue); 2379 expect(setter.isSetter, isTrue);
2397 expect(setter.isSynthetic, isFalse); 2380 expect(setter.isSynthetic, isFalse);
2398 expect(setter.name, "$methodName="); 2381 expect(setter.name, "$methodName=");
2399 expect(setter.displayName, methodName); 2382 expect(setter.displayName, methodName);
2400 expect(setter.variable, field); 2383 expect(setter.variable, field);
2401 expect(setter.functions, hasLength(0)); 2384 expect(setter.functions, hasLength(0));
2402 expect(setter.labels, hasLength(0));
2403 expect(setter.parameters, hasLength(0)); 2385 expect(setter.parameters, hasLength(0));
2404 } 2386 }
2405 2387
2406 void test_visitMethodDeclaration_static() { 2388 void test_visitMethodDeclaration_static() {
2407 // static m() {} 2389 // static m() {}
2408 String methodName = "m"; 2390 String methodName = "m";
2409 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( 2391 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2410 Keyword.STATIC, 2392 Keyword.STATIC,
2411 null, 2393 null,
2412 null, 2394 null,
2413 null, 2395 null,
2414 AstTestFactory.identifier3(methodName), 2396 AstTestFactory.identifier3(methodName),
2415 AstTestFactory.formalParameterList(), 2397 AstTestFactory.formalParameterList(),
2416 AstTestFactory.blockFunctionBody2()); 2398 AstTestFactory.blockFunctionBody2());
2417 ElementHolder holder = buildElementsForAst(methodDeclaration); 2399 ElementHolder holder = buildElementsForAst(methodDeclaration);
2418 List<MethodElement> methods = holder.methods; 2400 List<MethodElement> methods = holder.methods;
2419 expect(methods, hasLength(1)); 2401 expect(methods, hasLength(1));
2420 MethodElement method = methods[0]; 2402 MethodElement method = methods[0];
2421 expect(method, isNotNull); 2403 expect(method, isNotNull);
2422 expect(method.hasImplicitReturnType, isTrue); 2404 expect(method.hasImplicitReturnType, isTrue);
2423 expect(method.name, methodName); 2405 expect(method.name, methodName);
2424 expect(method.functions, hasLength(0)); 2406 expect(method.functions, hasLength(0));
2425 expect(method.labels, hasLength(0));
2426 expect(method.parameters, hasLength(0)); 2407 expect(method.parameters, hasLength(0));
2427 expect(method.typeParameters, hasLength(0)); 2408 expect(method.typeParameters, hasLength(0));
2428 expect(method.isAbstract, isFalse); 2409 expect(method.isAbstract, isFalse);
2429 expect(method.isExternal, isFalse); 2410 expect(method.isExternal, isFalse);
2430 expect(method.isStatic, isTrue); 2411 expect(method.isStatic, isTrue);
2431 expect(method.isSynthetic, isFalse); 2412 expect(method.isSynthetic, isFalse);
2432 } 2413 }
2433 2414
2434 void test_visitMethodDeclaration_typeParameters() { 2415 void test_visitMethodDeclaration_typeParameters() {
2435 // m<E>() {} 2416 // m<E>() {}
2436 String methodName = "m"; 2417 String methodName = "m";
2437 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2( 2418 MethodDeclaration methodDeclaration = AstTestFactory.methodDeclaration2(
2438 null, 2419 null,
2439 null, 2420 null,
2440 null, 2421 null,
2441 null, 2422 null,
2442 AstTestFactory.identifier3(methodName), 2423 AstTestFactory.identifier3(methodName),
2443 AstTestFactory.formalParameterList(), 2424 AstTestFactory.formalParameterList(),
2444 AstTestFactory.blockFunctionBody2()); 2425 AstTestFactory.blockFunctionBody2());
2445 methodDeclaration.typeParameters = AstTestFactory.typeParameterList(['E']); 2426 methodDeclaration.typeParameters = AstTestFactory.typeParameterList(['E']);
2446 2427
2447 ElementHolder holder = buildElementsForAst(methodDeclaration); 2428 ElementHolder holder = buildElementsForAst(methodDeclaration);
2448 List<MethodElement> methods = holder.methods; 2429 List<MethodElement> methods = holder.methods;
2449 expect(methods, hasLength(1)); 2430 expect(methods, hasLength(1));
2450 MethodElement method = methods[0]; 2431 MethodElement method = methods[0];
2451 expect(method, isNotNull); 2432 expect(method, isNotNull);
2452 expect(method.hasImplicitReturnType, isTrue); 2433 expect(method.hasImplicitReturnType, isTrue);
2453 expect(method.name, methodName); 2434 expect(method.name, methodName);
2454 expect(method.functions, hasLength(0)); 2435 expect(method.functions, hasLength(0));
2455 expect(method.labels, hasLength(0));
2456 expect(method.parameters, hasLength(0)); 2436 expect(method.parameters, hasLength(0));
2457 expect(method.typeParameters, hasLength(1)); 2437 expect(method.typeParameters, hasLength(1));
2458 expect(method.isAbstract, isFalse); 2438 expect(method.isAbstract, isFalse);
2459 expect(method.isExternal, isFalse); 2439 expect(method.isExternal, isFalse);
2460 expect(method.isStatic, isFalse); 2440 expect(method.isStatic, isFalse);
2461 expect(method.isSynthetic, isFalse); 2441 expect(method.isSynthetic, isFalse);
2462 } 2442 }
2463 2443
2464 void test_visitTypeAlias_minimal() { 2444 void test_visitTypeAlias_minimal() {
2465 String aliasName = "F"; 2445 String aliasName = "F";
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 AstVisitor createElementBuilder(ElementHolder holder); 2593 AstVisitor createElementBuilder(ElementHolder holder);
2614 2594
2615 SimpleIdentifier findIdentifier(String code, String prefix) { 2595 SimpleIdentifier findIdentifier(String code, String prefix) {
2616 return EngineTestCase.findSimpleIdentifier(compilationUnit, code, prefix); 2596 return EngineTestCase.findSimpleIdentifier(compilationUnit, code, prefix);
2617 } 2597 }
2618 2598
2619 LocalVariableElement findLocalVariable(String code, String prefix) { 2599 LocalVariableElement findLocalVariable(String code, String prefix) {
2620 return findIdentifier(code, prefix).staticElement; 2600 return findIdentifier(code, prefix).staticElement;
2621 } 2601 }
2622 2602
2603 LabelElement findLabel(String code, String prefix) {
2604 return findIdentifier(code, prefix).staticElement;
2605 }
2606
2623 void setUp() { 2607 void setUp() {
2624 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); 2608 compilationUnitElement = new CompilationUnitElementImpl('test.dart');
2625 } 2609 }
2626 2610
2627 void _assertVisibleRange(LocalElement element, int offset, int end) { 2611 void _assertVisibleRange(LocalElement element, int offset, int end) {
2628 SourceRange visibleRange = element.visibleRange; 2612 SourceRange visibleRange = element.visibleRange;
2629 expect(visibleRange.offset, offset); 2613 expect(visibleRange.offset, offset);
2630 expect(visibleRange.end, end); 2614 expect(visibleRange.end, end);
2631 } 2615 }
2632 2616
2633 /** 2617 /**
2634 * Parse the given [code], and visit it with the given [visitor]. 2618 * Parse the given [code], and visit it with the given [visitor].
2635 * Fail if any error is logged. 2619 * Fail if any error is logged.
2636 */ 2620 */
2637 void _visitAstOfCode(String code, AstVisitor visitor) { 2621 void _visitAstOfCode(String code, AstVisitor visitor) {
2638 TestLogger logger = new TestLogger(); 2622 TestLogger logger = new TestLogger();
2639 AnalysisEngine.instance.logger = logger; 2623 AnalysisEngine.instance.logger = logger;
2640 try { 2624 try {
2641 _compilationUnit = parseCompilationUnit(code); 2625 _compilationUnit = parseCompilationUnit(code);
2642 compilationUnit.accept(visitor); 2626 compilationUnit.accept(visitor);
2643 } finally { 2627 } finally {
2644 expect(logger.log, hasLength(0)); 2628 expect(logger.log, hasLength(0));
2645 AnalysisEngine.instance.logger = Logger.NULL; 2629 AnalysisEngine.instance.logger = Logger.NULL;
2646 } 2630 }
2647 } 2631 }
2648 } 2632 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698