| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.parser_test; | 5 library analyzer.test.generated.parser_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/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 Expression parseStringLiteral(String code); | 190 Expression parseStringLiteral(String code); |
| 191 | 191 |
| 192 SymbolLiteral parseSymbolLiteral(String code); | 192 SymbolLiteral parseSymbolLiteral(String code); |
| 193 | 193 |
| 194 Expression parseThrowExpression(String code); | 194 Expression parseThrowExpression(String code); |
| 195 | 195 |
| 196 Expression parseThrowExpressionWithoutCascade(String code); | 196 Expression parseThrowExpressionWithoutCascade(String code); |
| 197 | 197 |
| 198 PrefixExpression parseUnaryExpression(String code); | 198 PrefixExpression parseUnaryExpression(String code); |
| 199 |
| 200 VariableDeclarationList parseVariableDeclarationList(String source); |
| 199 } | 201 } |
| 200 | 202 |
| 201 /** | 203 /** |
| 202 * Instances of the class `AstValidator` are used to validate the correct constr
uction of an | 204 * Instances of the class `AstValidator` are used to validate the correct constr
uction of an |
| 203 * AST structure. | 205 * AST structure. |
| 204 */ | 206 */ |
| 205 class AstValidator extends UnifyingAstVisitor<Object> { | 207 class AstValidator extends UnifyingAstVisitor<Object> { |
| 206 /** | 208 /** |
| 207 * A list containing the errors found while traversing the AST structure. | 209 * A list containing the errors found while traversing the AST structure. |
| 208 */ | 210 */ |
| (...skipping 7902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8111 * Parses a single top level member of a compilation unit (other than a | 8113 * Parses a single top level member of a compilation unit (other than a |
| 8112 * directive), including any comment and/or metadata that precedes it. | 8114 * directive), including any comment and/or metadata that precedes it. |
| 8113 */ | 8115 */ |
| 8114 CompilationUnitMember parseFullCompilationUnitMember() => | 8116 CompilationUnitMember parseFullCompilationUnitMember() => |
| 8115 parser.parseCompilationUnitMember(parser.parseCommentAndMetadata()); | 8117 parser.parseCompilationUnitMember(parser.parseCommentAndMetadata()); |
| 8116 | 8118 |
| 8117 @override | 8119 @override |
| 8118 Directive parseFullDirective() => | 8120 Directive parseFullDirective() => |
| 8119 parser.parseDirective(parser.parseCommentAndMetadata()); | 8121 parser.parseDirective(parser.parseCommentAndMetadata()); |
| 8120 | 8122 |
| 8121 /** | |
| 8122 * Parses a variable declaration list (equivalent to a variable declaration | |
| 8123 * statement, but without the final comma). | |
| 8124 */ | |
| 8125 VariableDeclarationList parseFullVariableDeclarationList() => | |
| 8126 parser.parseVariableDeclarationListAfterMetadata( | |
| 8127 parser.parseCommentAndMetadata()); | |
| 8128 | |
| 8129 @override | 8123 @override |
| 8130 FunctionExpression parseFunctionExpression(String code) { | 8124 FunctionExpression parseFunctionExpression(String code) { |
| 8131 createParser(code); | 8125 createParser(code); |
| 8132 return parser.parseFunctionExpression(); | 8126 return parser.parseFunctionExpression(); |
| 8133 } | 8127 } |
| 8134 | 8128 |
| 8135 @override | 8129 @override |
| 8136 InstanceCreationExpression parseInstanceCreationExpression( | 8130 InstanceCreationExpression parseInstanceCreationExpression( |
| 8137 String code, Token newToken) { | 8131 String code, Token newToken) { |
| 8138 createParser(code); | 8132 createParser(code); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8321 return parser.parseThrowExpressionWithoutCascade(); | 8315 return parser.parseThrowExpressionWithoutCascade(); |
| 8322 } | 8316 } |
| 8323 | 8317 |
| 8324 @override | 8318 @override |
| 8325 PrefixExpression parseUnaryExpression(String code) { | 8319 PrefixExpression parseUnaryExpression(String code) { |
| 8326 createParser(code); | 8320 createParser(code); |
| 8327 return parser.parseUnaryExpression(); | 8321 return parser.parseUnaryExpression(); |
| 8328 } | 8322 } |
| 8329 | 8323 |
| 8330 @override | 8324 @override |
| 8325 VariableDeclarationList parseVariableDeclarationList(String code) { |
| 8326 createParser(code); |
| 8327 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 8328 return parser.parseVariableDeclarationListAfterMetadata(commentAndMetadata); |
| 8329 } |
| 8330 |
| 8331 @override |
| 8331 void setUp() { | 8332 void setUp() { |
| 8332 super.setUp(); | 8333 super.setUp(); |
| 8333 parseFunctionBodies = true; | 8334 parseFunctionBodies = true; |
| 8334 } | 8335 } |
| 8335 } | 8336 } |
| 8336 | 8337 |
| 8337 /** | 8338 /** |
| 8338 * Helper methods that aid in parser tests. | 8339 * Helper methods that aid in parser tests. |
| 8339 * | 8340 * |
| 8340 * Intended to be mixed in to parser test case classes. | 8341 * Intended to be mixed in to parser test case classes. |
| (...skipping 3386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11727 void test_parseVariableDeclaration_noEquals() { | 11728 void test_parseVariableDeclaration_noEquals() { |
| 11728 createParser('a'); | 11729 createParser('a'); |
| 11729 VariableDeclaration declaration = parser.parseVariableDeclaration(); | 11730 VariableDeclaration declaration = parser.parseVariableDeclaration(); |
| 11730 expectNotNullIfNoErrors(declaration); | 11731 expectNotNullIfNoErrors(declaration); |
| 11731 listener.assertNoErrors(); | 11732 listener.assertNoErrors(); |
| 11732 expect(declaration.name, isNotNull); | 11733 expect(declaration.name, isNotNull); |
| 11733 expect(declaration.equals, isNull); | 11734 expect(declaration.equals, isNull); |
| 11734 expect(declaration.initializer, isNull); | 11735 expect(declaration.initializer, isNull); |
| 11735 } | 11736 } |
| 11736 | 11737 |
| 11737 void test_parseVariableDeclarationListAfterMetadata_const_noType() { | |
| 11738 createParser('const a'); | |
| 11739 VariableDeclarationList declarationList = | |
| 11740 parseFullVariableDeclarationList(); | |
| 11741 expectNotNullIfNoErrors(declarationList); | |
| 11742 listener.assertNoErrors(); | |
| 11743 expect(declarationList.keyword, isNotNull); | |
| 11744 expect(declarationList.type, isNull); | |
| 11745 expect(declarationList.variables, hasLength(1)); | |
| 11746 } | |
| 11747 | |
| 11748 void test_parseVariableDeclarationListAfterMetadata_const_type() { | |
| 11749 createParser('const A a'); | |
| 11750 VariableDeclarationList declarationList = | |
| 11751 parseFullVariableDeclarationList(); | |
| 11752 expectNotNullIfNoErrors(declarationList); | |
| 11753 listener.assertNoErrors(); | |
| 11754 expect(declarationList.keyword, isNotNull); | |
| 11755 expect(declarationList.type, isNotNull); | |
| 11756 expect(declarationList.variables, hasLength(1)); | |
| 11757 } | |
| 11758 | |
| 11759 void test_parseVariableDeclarationListAfterMetadata_final_noType() { | |
| 11760 createParser('final a'); | |
| 11761 VariableDeclarationList declarationList = | |
| 11762 parseFullVariableDeclarationList(); | |
| 11763 expectNotNullIfNoErrors(declarationList); | |
| 11764 listener.assertNoErrors(); | |
| 11765 expect(declarationList.keyword, isNotNull); | |
| 11766 expect(declarationList.type, isNull); | |
| 11767 expect(declarationList.variables, hasLength(1)); | |
| 11768 } | |
| 11769 | |
| 11770 void test_parseVariableDeclarationListAfterMetadata_final_type() { | |
| 11771 createParser('final A a'); | |
| 11772 VariableDeclarationList declarationList = | |
| 11773 parseFullVariableDeclarationList(); | |
| 11774 expectNotNullIfNoErrors(declarationList); | |
| 11775 listener.assertNoErrors(); | |
| 11776 expect(declarationList.keyword, isNotNull); | |
| 11777 expect(declarationList.type, isNotNull); | |
| 11778 expect(declarationList.variables, hasLength(1)); | |
| 11779 } | |
| 11780 | |
| 11781 void test_parseVariableDeclarationListAfterMetadata_final_typeComment() { | |
| 11782 enableGenericMethodComments = true; | |
| 11783 createParser('final/*=T*/ x'); | |
| 11784 VariableDeclarationList declarationList = | |
| 11785 parseFullVariableDeclarationList(); | |
| 11786 expectNotNullIfNoErrors(declarationList); | |
| 11787 listener.assertNoErrors(); | |
| 11788 expect((declarationList.type as TypeName).name.name, 'T'); | |
| 11789 expect(declarationList.isFinal, true); | |
| 11790 } | |
| 11791 | |
| 11792 void test_parseVariableDeclarationListAfterMetadata_type_multiple() { | |
| 11793 createParser('A a, b, c'); | |
| 11794 VariableDeclarationList declarationList = | |
| 11795 parseFullVariableDeclarationList(); | |
| 11796 expectNotNullIfNoErrors(declarationList); | |
| 11797 listener.assertNoErrors(); | |
| 11798 expect(declarationList.keyword, isNull); | |
| 11799 expect(declarationList.type, isNotNull); | |
| 11800 expect(declarationList.variables, hasLength(3)); | |
| 11801 } | |
| 11802 | |
| 11803 void test_parseVariableDeclarationListAfterMetadata_type_single() { | |
| 11804 createParser('A a'); | |
| 11805 VariableDeclarationList declarationList = | |
| 11806 parseFullVariableDeclarationList(); | |
| 11807 expectNotNullIfNoErrors(declarationList); | |
| 11808 listener.assertNoErrors(); | |
| 11809 expect(declarationList.keyword, isNull); | |
| 11810 expect(declarationList.type, isNotNull); | |
| 11811 expect(declarationList.variables, hasLength(1)); | |
| 11812 } | |
| 11813 | |
| 11814 void test_parseVariableDeclarationListAfterMetadata_var_multiple() { | |
| 11815 createParser('var a, b, c'); | |
| 11816 VariableDeclarationList declarationList = | |
| 11817 parseFullVariableDeclarationList(); | |
| 11818 expectNotNullIfNoErrors(declarationList); | |
| 11819 listener.assertNoErrors(); | |
| 11820 expect(declarationList.keyword, isNotNull); | |
| 11821 expect(declarationList.type, isNull); | |
| 11822 expect(declarationList.variables, hasLength(3)); | |
| 11823 } | |
| 11824 | |
| 11825 void test_parseVariableDeclarationListAfterMetadata_var_single() { | |
| 11826 createParser('var a'); | |
| 11827 VariableDeclarationList declarationList = | |
| 11828 parseFullVariableDeclarationList(); | |
| 11829 expectNotNullIfNoErrors(declarationList); | |
| 11830 listener.assertNoErrors(); | |
| 11831 expect(declarationList.keyword, isNotNull); | |
| 11832 expect(declarationList.type, isNull); | |
| 11833 expect(declarationList.variables, hasLength(1)); | |
| 11834 } | |
| 11835 | |
| 11836 void test_parseVariableDeclarationListAfterMetadata_var_typeComment() { | |
| 11837 enableGenericMethodComments = true; | |
| 11838 createParser('var/*=T*/ x'); | |
| 11839 VariableDeclarationList declarationList = | |
| 11840 parseFullVariableDeclarationList(); | |
| 11841 expectNotNullIfNoErrors(declarationList); | |
| 11842 listener.assertNoErrors(); | |
| 11843 expect((declarationList.type as TypeName).name.name, 'T'); | |
| 11844 expect(declarationList.keyword, isNull); | |
| 11845 } | |
| 11846 | |
| 11847 void test_parseVariableDeclarationListAfterType_type() { | |
| 11848 createParser('T a'); | |
| 11849 VariableDeclarationList declarationList = | |
| 11850 parseFullVariableDeclarationList(); | |
| 11851 expectNotNullIfNoErrors(declarationList); | |
| 11852 listener.assertNoErrors(); | |
| 11853 expect(declarationList.keyword, isNull); | |
| 11854 expect((declarationList.type as TypeName).name.name, 'T'); | |
| 11855 expect(declarationList.variables, hasLength(1)); | |
| 11856 } | |
| 11857 | |
| 11858 void test_parseVariableDeclarationListAfterType_var() { | |
| 11859 createParser('var a, b, c'); | |
| 11860 VariableDeclarationList declarationList = | |
| 11861 parseFullVariableDeclarationList(); | |
| 11862 expectNotNullIfNoErrors(declarationList); | |
| 11863 listener.assertNoErrors(); | |
| 11864 expect(declarationList.keyword.lexeme, 'var'); | |
| 11865 expect(declarationList.type, isNull); | |
| 11866 expect(declarationList.variables, hasLength(3)); | |
| 11867 } | |
| 11868 | |
| 11869 void test_parseWithClause_multiple() { | 11738 void test_parseWithClause_multiple() { |
| 11870 createParser('with A, B, C'); | 11739 createParser('with A, B, C'); |
| 11871 WithClause clause = parser.parseWithClause(); | 11740 WithClause clause = parser.parseWithClause(); |
| 11872 expectNotNullIfNoErrors(clause); | 11741 expectNotNullIfNoErrors(clause); |
| 11873 listener.assertNoErrors(); | 11742 listener.assertNoErrors(); |
| 11874 expect(clause.withKeyword, isNotNull); | 11743 expect(clause.withKeyword, isNotNull); |
| 11875 expect(clause.mixinTypes, hasLength(3)); | 11744 expect(clause.mixinTypes, hasLength(3)); |
| 11876 } | 11745 } |
| 11877 | 11746 |
| 11878 void test_parseWithClause_single() { | 11747 void test_parseWithClause_single() { |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12914 expect(clause.exceptionType, isNotNull); | 12783 expect(clause.exceptionType, isNotNull); |
| 12915 expect(clause.catchKeyword, isNotNull); | 12784 expect(clause.catchKeyword, isNotNull); |
| 12916 expect(clause.exceptionParameter, isNotNull); | 12785 expect(clause.exceptionParameter, isNotNull); |
| 12917 expect(clause.comma, isNotNull); | 12786 expect(clause.comma, isNotNull); |
| 12918 expect(clause.stackTraceParameter, isNotNull); | 12787 expect(clause.stackTraceParameter, isNotNull); |
| 12919 expect(clause.body, isNotNull); | 12788 expect(clause.body, isNotNull); |
| 12920 expect(statement.finallyKeyword, isNotNull); | 12789 expect(statement.finallyKeyword, isNotNull); |
| 12921 expect(statement.finallyBlock, isNotNull); | 12790 expect(statement.finallyBlock, isNotNull); |
| 12922 } | 12791 } |
| 12923 | 12792 |
| 12793 void test_parseVariableDeclarationListAfterMetadata_const_noType() { |
| 12794 var declarationList = parseVariableDeclarationList('const a'); |
| 12795 assertNoErrors(); |
| 12796 expect(declarationList.keyword.lexeme, 'const'); |
| 12797 expect(declarationList.type, isNull); |
| 12798 expect(declarationList.variables, hasLength(1)); |
| 12799 } |
| 12800 |
| 12801 void test_parseVariableDeclarationListAfterMetadata_const_type() { |
| 12802 var declarationList = parseVariableDeclarationList('const A a'); |
| 12803 assertNoErrors(); |
| 12804 expect(declarationList.keyword.lexeme, 'const'); |
| 12805 expect(declarationList.type, isNotNull); |
| 12806 expect(declarationList.variables, hasLength(1)); |
| 12807 } |
| 12808 |
| 12809 void test_parseVariableDeclarationListAfterMetadata_const_typeComment() { |
| 12810 enableGenericMethodComments = true; |
| 12811 var declarationList = parseVariableDeclarationList('const/*=T*/ a'); |
| 12812 assertNoErrors(); |
| 12813 expect((declarationList.type as TypeName).name.name, 'T'); |
| 12814 expect(declarationList.isConst, true); |
| 12815 } |
| 12816 |
| 12817 void test_parseVariableDeclarationListAfterMetadata_dynamic_typeComment() { |
| 12818 enableGenericMethodComments = true; |
| 12819 var declarationList = parseVariableDeclarationList('dynamic/*=T*/ a'); |
| 12820 assertNoErrors(); |
| 12821 expect((declarationList.type as TypeName).name.name, 'T'); |
| 12822 expect(declarationList.keyword, isNull); |
| 12823 } |
| 12824 |
| 12825 void test_parseVariableDeclarationListAfterMetadata_final_noType() { |
| 12826 var declarationList = parseVariableDeclarationList('final a'); |
| 12827 assertNoErrors(); |
| 12828 expect(declarationList.keyword, isNotNull); |
| 12829 expect(declarationList.type, isNull); |
| 12830 expect(declarationList.variables, hasLength(1)); |
| 12831 } |
| 12832 |
| 12833 void test_parseVariableDeclarationListAfterMetadata_final_type() { |
| 12834 var declarationList = parseVariableDeclarationList('final A a'); |
| 12835 assertNoErrors(); |
| 12836 expect(declarationList.keyword.lexeme, 'final'); |
| 12837 expect(declarationList.type, isNotNull); |
| 12838 expect(declarationList.variables, hasLength(1)); |
| 12839 } |
| 12840 |
| 12841 void test_parseVariableDeclarationListAfterMetadata_final_typeComment() { |
| 12842 enableGenericMethodComments = true; |
| 12843 var declarationList = parseVariableDeclarationList('final/*=T*/ a'); |
| 12844 assertNoErrors(); |
| 12845 expect((declarationList.type as TypeName).name.name, 'T'); |
| 12846 expect(declarationList.isFinal, true); |
| 12847 } |
| 12848 |
| 12849 void test_parseVariableDeclarationListAfterMetadata_type_multiple() { |
| 12850 var declarationList = parseVariableDeclarationList('A a, b, c'); |
| 12851 assertNoErrors(); |
| 12852 expect(declarationList.keyword, isNull); |
| 12853 expect(declarationList.type, isNotNull); |
| 12854 expect(declarationList.variables, hasLength(3)); |
| 12855 } |
| 12856 |
| 12857 void test_parseVariableDeclarationListAfterMetadata_type_single() { |
| 12858 var declarationList = parseVariableDeclarationList('A a'); |
| 12859 assertNoErrors(); |
| 12860 expect(declarationList.keyword, isNull); |
| 12861 expect(declarationList.type, isNotNull); |
| 12862 expect(declarationList.variables, hasLength(1)); |
| 12863 } |
| 12864 |
| 12865 void test_parseVariableDeclarationListAfterMetadata_type_typeComment() { |
| 12866 enableGenericMethodComments = true; |
| 12867 var declarationList = parseVariableDeclarationList('int/*=T*/ a'); |
| 12868 assertNoErrors(); |
| 12869 expect((declarationList.type as TypeName).name.name, 'T'); |
| 12870 expect(declarationList.keyword, isNull); |
| 12871 } |
| 12872 |
| 12873 void test_parseVariableDeclarationListAfterMetadata_var_multiple() { |
| 12874 var declarationList = parseVariableDeclarationList('var a, b, c'); |
| 12875 assertNoErrors(); |
| 12876 expect(declarationList.keyword.lexeme, 'var'); |
| 12877 expect(declarationList.type, isNull); |
| 12878 expect(declarationList.variables, hasLength(3)); |
| 12879 } |
| 12880 |
| 12881 void test_parseVariableDeclarationListAfterMetadata_var_single() { |
| 12882 var declarationList = parseVariableDeclarationList('var a'); |
| 12883 assertNoErrors(); |
| 12884 expect(declarationList.keyword.lexeme, 'var'); |
| 12885 expect(declarationList.type, isNull); |
| 12886 expect(declarationList.variables, hasLength(1)); |
| 12887 } |
| 12888 |
| 12889 void test_parseVariableDeclarationListAfterMetadata_var_typeComment() { |
| 12890 enableGenericMethodComments = true; |
| 12891 var declarationList = parseVariableDeclarationList('var/*=T*/ a'); |
| 12892 assertNoErrors(); |
| 12893 expect((declarationList.type as TypeName).name.name, 'T'); |
| 12894 expect(declarationList.keyword, isNull); |
| 12895 } |
| 12896 |
| 12924 void test_parseVariableDeclarationStatementAfterMetadata_multiple() { | 12897 void test_parseVariableDeclarationStatementAfterMetadata_multiple() { |
| 12925 var statement = | 12898 var statement = |
| 12926 parseStatement('var x, y, z;') as VariableDeclarationStatement; | 12899 parseStatement('var x, y, z;') as VariableDeclarationStatement; |
| 12927 assertNoErrors(); | 12900 assertNoErrors(); |
| 12928 expect(statement.semicolon, isNotNull); | 12901 expect(statement.semicolon, isNotNull); |
| 12929 VariableDeclarationList variableList = statement.variables; | 12902 VariableDeclarationList variableList = statement.variables; |
| 12930 expect(variableList, isNotNull); | 12903 expect(variableList, isNotNull); |
| 12931 expect(variableList.variables, hasLength(3)); | 12904 expect(variableList.variables, hasLength(3)); |
| 12932 } | 12905 } |
| 12933 | 12906 |
| (...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14759 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 14732 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
| 14760 } | 14733 } |
| 14761 | 14734 |
| 14762 /** | 14735 /** |
| 14763 * Assert that the given [name] is in declaration context. | 14736 * Assert that the given [name] is in declaration context. |
| 14764 */ | 14737 */ |
| 14765 void _assertIsDeclarationName(SimpleIdentifier name) { | 14738 void _assertIsDeclarationName(SimpleIdentifier name) { |
| 14766 expect(name.inDeclarationContext(), isTrue); | 14739 expect(name.inDeclarationContext(), isTrue); |
| 14767 } | 14740 } |
| 14768 } | 14741 } |
| OLD | NEW |