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

Side by Side Diff: pkg/analyzer/test/generated/parser_test.dart

Issue 2749643002: Create DeclaredSimpleIdentifier when parse a declaration with Fasta. (Closed)
Patch Set: Fixes for review comments. Created 3 years, 9 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/front_end/lib/src/fasta/analyzer/ast_builder.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.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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 expect(field.covariantKeyword, isNull); 403 expect(field.covariantKeyword, isNull);
404 expect(field.documentationComment, isNull); 404 expect(field.documentationComment, isNull);
405 expect(field.metadata, hasLength(0)); 405 expect(field.metadata, hasLength(0));
406 expect(field.staticKeyword, isNull); 406 expect(field.staticKeyword, isNull);
407 VariableDeclarationList list = field.fields; 407 VariableDeclarationList list = field.fields;
408 expect(list, isNotNull); 408 expect(list, isNotNull);
409 NodeList<VariableDeclaration> variables = list.variables; 409 NodeList<VariableDeclaration> variables = list.variables;
410 expect(variables, hasLength(1)); 410 expect(variables, hasLength(1));
411 VariableDeclaration variable = variables[0]; 411 VariableDeclaration variable = variables[0];
412 expect(variable.name, isNotNull); 412 expect(variable.name, isNotNull);
413 _assertIsDeclarationName(variable.name);
413 } 414 }
414 415
415 void test_parseClassMember_field_namedGet() { 416 void test_parseClassMember_field_namedGet() {
416 createParser('var get;'); 417 createParser('var get;');
417 ClassMember member = parser.parseClassMember('C'); 418 ClassMember member = parser.parseClassMember('C');
418 expect(member, isNotNull); 419 expect(member, isNotNull);
419 assertNoErrors(); 420 assertNoErrors();
420 expect(member, new isInstanceOf<FieldDeclaration>()); 421 expect(member, new isInstanceOf<FieldDeclaration>());
421 FieldDeclaration field = member; 422 FieldDeclaration field = member;
422 expect(field.covariantKeyword, isNull); 423 expect(field.covariantKeyword, isNull);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 expect(member, isNotNull); 533 expect(member, isNotNull);
533 assertNoErrors(); 534 assertNoErrors();
534 expect(member, new isInstanceOf<MethodDeclaration>()); 535 expect(member, new isInstanceOf<MethodDeclaration>());
535 MethodDeclaration method = member; 536 MethodDeclaration method = member;
536 expect(method.documentationComment, isNull); 537 expect(method.documentationComment, isNull);
537 expect(method.externalKeyword, isNull); 538 expect(method.externalKeyword, isNull);
538 expect(method.modifierKeyword, isNull); 539 expect(method.modifierKeyword, isNull);
539 expect(method.propertyKeyword, isNotNull); 540 expect(method.propertyKeyword, isNotNull);
540 expect(method.returnType, isNotNull); 541 expect(method.returnType, isNotNull);
541 expect(method.name, isNotNull); 542 expect(method.name, isNotNull);
543 _assertIsDeclarationName(method.name);
542 expect(method.operatorKeyword, isNull); 544 expect(method.operatorKeyword, isNull);
543 expect(method.body, isNotNull); 545 expect(method.body, isNotNull);
544 expect(method.parameters, isNull); 546 expect(method.parameters, isNull);
545 } 547 }
546 548
547 void test_parseClassMember_method_external() { 549 void test_parseClassMember_method_external() {
548 createParser('external m();'); 550 createParser('external m();');
549 ClassMember member = parser.parseClassMember('C'); 551 ClassMember member = parser.parseClassMember('C');
550 expect(member, isNotNull); 552 expect(member, isNotNull);
551 assertNoErrors(); 553 assertNoErrors();
552 expect(member, new isInstanceOf<MethodDeclaration>()); 554 expect(member, new isInstanceOf<MethodDeclaration>());
553 MethodDeclaration method = member; 555 MethodDeclaration method = member;
554 expect(method.documentationComment, isNull); 556 expect(method.documentationComment, isNull);
555 expect(method.externalKeyword, isNotNull); 557 expect(method.externalKeyword, isNotNull);
556 expect(method.modifierKeyword, isNull); 558 expect(method.modifierKeyword, isNull);
557 expect(method.name, isNotNull); 559 expect(method.name, isNotNull);
560 _assertIsDeclarationName(method.name);
558 expect(method.operatorKeyword, isNull); 561 expect(method.operatorKeyword, isNull);
559 expect(method.typeParameters, isNull); 562 expect(method.typeParameters, isNull);
560 expect(method.parameters, isNotNull); 563 expect(method.parameters, isNotNull);
561 expect(method.propertyKeyword, isNull); 564 expect(method.propertyKeyword, isNull);
562 expect(method.returnType, isNull); 565 expect(method.returnType, isNull);
563 566
564 var body = method.body as EmptyFunctionBody; 567 var body = method.body as EmptyFunctionBody;
565 expect(body.keyword, isNull); 568 expect(body.keyword, isNull);
566 expect(body.star, isNull); 569 expect(body.star, isNull);
567 expect(body.semicolon.type, TokenType.SEMICOLON); 570 expect(body.semicolon.type, TokenType.SEMICOLON);
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 createParser('const factory C() = prefix.B.foo;'); 1024 createParser('const factory C() = prefix.B.foo;');
1022 var constructor = parser.parseClassMember('C') as ConstructorDeclaration; 1025 var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
1023 assertNoErrors(); 1026 assertNoErrors();
1024 expect(constructor, isNotNull); 1027 expect(constructor, isNotNull);
1025 expect(constructor.externalKeyword, isNull); 1028 expect(constructor.externalKeyword, isNull);
1026 expect(constructor.constKeyword.keyword, Keyword.CONST); 1029 expect(constructor.constKeyword.keyword, Keyword.CONST);
1027 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY); 1030 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY);
1028 expect(constructor.returnType.name, 'C'); 1031 expect(constructor.returnType.name, 'C');
1029 expect(constructor.period, isNull); 1032 expect(constructor.period, isNull);
1030 expect(constructor.name, isNull); 1033 expect(constructor.name, isNull);
1034 _assertIsDeclarationName(constructor.returnType, false);
1031 expect(constructor.parameters, isNotNull); 1035 expect(constructor.parameters, isNotNull);
1032 expect(constructor.parameters.parameters, isEmpty); 1036 expect(constructor.parameters.parameters, isEmpty);
1033 expect(constructor.separator.type, TokenType.EQ); 1037 expect(constructor.separator.type, TokenType.EQ);
1034 expect(constructor.initializers, isEmpty); 1038 expect(constructor.initializers, isEmpty);
1035 expect(constructor.redirectedConstructor, isNotNull); 1039 expect(constructor.redirectedConstructor, isNotNull);
1036 expect(constructor.redirectedConstructor.type.name.name, 'prefix.B'); 1040 expect(constructor.redirectedConstructor.type.name.name, 'prefix.B');
1037 expect(constructor.redirectedConstructor.period.type, TokenType.PERIOD); 1041 expect(constructor.redirectedConstructor.period.type, TokenType.PERIOD);
1038 expect(constructor.redirectedConstructor.name.name, 'foo'); 1042 expect(constructor.redirectedConstructor.name.name, 'foo');
1039 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>()); 1043 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>());
1040 } 1044 }
(...skipping 16 matching lines...) Expand all
1057 expect(constructor.redirectedConstructor, isNull); 1061 expect(constructor.redirectedConstructor, isNull);
1058 1062
1059 var body = constructor.body as ExpressionFunctionBody; 1063 var body = constructor.body as ExpressionFunctionBody;
1060 expect(body.keyword, isNull); 1064 expect(body.keyword, isNull);
1061 expect(body.star, isNull); 1065 expect(body.star, isNull);
1062 expect(body.functionDefinition.type, TokenType.FUNCTION); 1066 expect(body.functionDefinition.type, TokenType.FUNCTION);
1063 expect(body.expression, isNotNull); 1067 expect(body.expression, isNotNull);
1064 expect(body.semicolon, isNotNull); 1068 expect(body.semicolon, isNotNull);
1065 } 1069 }
1066 1070
1067 void test_parseConstructor_named() {
1068 createParser('C.foo();');
1069 var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
1070 assertNoErrors();
1071 expect(constructor, isNotNull);
1072 expect(constructor.externalKeyword, isNull);
1073 expect(constructor.constKeyword, isNull);
1074 expect(constructor.factoryKeyword, isNull);
1075 expect(constructor.returnType.name, 'C');
1076 expect(constructor.period.type, TokenType.PERIOD);
1077 expect(constructor.name.name, 'foo');
1078 expect(constructor.parameters, isNotNull);
1079 expect(constructor.parameters.parameters, isEmpty);
1080 expect(constructor.separator, isNull);
1081 expect(constructor.initializers, isEmpty);
1082 expect(constructor.redirectedConstructor, isNull);
1083 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>());
1084 }
1085
1086 void test_parseClassMember_redirectingFactory_nonConst() { 1071 void test_parseClassMember_redirectingFactory_nonConst() {
1087 createParser('factory C() = B;'); 1072 createParser('factory C() = B;');
1088 ClassMember member = parser.parseClassMember('C'); 1073 ClassMember member = parser.parseClassMember('C');
1089 expect(member, isNotNull); 1074 expect(member, isNotNull);
1090 assertNoErrors(); 1075 assertNoErrors();
1091 expect(member, new isInstanceOf<ConstructorDeclaration>()); 1076 expect(member, new isInstanceOf<ConstructorDeclaration>());
1092 ConstructorDeclaration constructor = member; 1077 ConstructorDeclaration constructor = member;
1093 expect(constructor.externalKeyword, isNull); 1078 expect(constructor.externalKeyword, isNull);
1094 expect(constructor.constKeyword, isNull); 1079 expect(constructor.constKeyword, isNull);
1095 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY); 1080 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY);
1096 expect(constructor.returnType.name, 'C'); 1081 expect(constructor.returnType.name, 'C');
1082 _assertIsDeclarationName(constructor.returnType, false);
1097 expect(constructor.period, isNull); 1083 expect(constructor.period, isNull);
1098 expect(constructor.name, isNull); 1084 expect(constructor.name, isNull);
1099 expect(constructor.parameters, isNotNull); 1085 expect(constructor.parameters, isNotNull);
1100 expect(constructor.parameters.parameters, isEmpty); 1086 expect(constructor.parameters.parameters, isEmpty);
1101 expect(constructor.separator.type, TokenType.EQ); 1087 expect(constructor.separator.type, TokenType.EQ);
1102 expect(constructor.initializers, isEmpty); 1088 expect(constructor.initializers, isEmpty);
1103 expect(constructor.redirectedConstructor, isNotNull); 1089 expect(constructor.redirectedConstructor, isNotNull);
1104 expect(constructor.redirectedConstructor.type.name.name, 'B'); 1090 expect(constructor.redirectedConstructor.type.name.name, 'B');
1105 expect(constructor.redirectedConstructor.period, isNull); 1091 expect(constructor.redirectedConstructor.period, isNull);
1106 expect(constructor.redirectedConstructor.name, isNull); 1092 expect(constructor.redirectedConstructor.name, isNull);
(...skipping 10 matching lines...) Expand all
1117 ConstructorDeclaration constructor = member as ConstructorDeclaration; 1103 ConstructorDeclaration constructor = member as ConstructorDeclaration;
1118 NodeList<ConstructorInitializer> initializers = constructor.initializers; 1104 NodeList<ConstructorInitializer> initializers = constructor.initializers;
1119 expect(initializers, hasLength(3)); 1105 expect(initializers, hasLength(3));
1120 ConstructorInitializer initializer = initializers[1]; 1106 ConstructorInitializer initializer = initializers[1];
1121 expect(initializer, new isInstanceOf<AssertInitializer>()); 1107 expect(initializer, new isInstanceOf<AssertInitializer>());
1122 AssertInitializer assertInitializer = initializer; 1108 AssertInitializer assertInitializer = initializer;
1123 expect(assertInitializer.condition, isNotNull); 1109 expect(assertInitializer.condition, isNotNull);
1124 expect(assertInitializer.message, isNull); 1110 expect(assertInitializer.message, isNull);
1125 } 1111 }
1126 1112
1113 void test_parseConstructor_named() {
1114 createParser('C.foo();');
1115 var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
1116 assertNoErrors();
1117 expect(constructor, isNotNull);
1118 expect(constructor.externalKeyword, isNull);
1119 expect(constructor.constKeyword, isNull);
1120 expect(constructor.factoryKeyword, isNull);
1121 expect(constructor.returnType.name, 'C');
1122 _assertIsDeclarationName(constructor.returnType, false);
1123 expect(constructor.period.type, TokenType.PERIOD);
1124 expect(constructor.name.name, 'foo');
1125 _assertIsDeclarationName(constructor.name);
1126 expect(constructor.parameters, isNotNull);
1127 expect(constructor.parameters.parameters, isEmpty);
1128 expect(constructor.separator, isNull);
1129 expect(constructor.initializers, isEmpty);
1130 expect(constructor.redirectedConstructor, isNull);
1131 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>());
1132 }
1133
1134 void test_parseConstructor_unnamed() {
1135 createParser('C();');
1136 var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
1137 assertNoErrors();
1138 expect(constructor, isNotNull);
1139 expect(constructor.externalKeyword, isNull);
1140 expect(constructor.constKeyword, isNull);
1141 expect(constructor.factoryKeyword, isNull);
1142 expect(constructor.returnType.name, 'C');
1143 _assertIsDeclarationName(constructor.returnType, false);
1144 expect(constructor.period, isNull);
1145 expect(constructor.name, isNull);
1146 expect(constructor.parameters, isNotNull);
1147 expect(constructor.parameters.parameters, isEmpty);
1148 expect(constructor.separator, isNull);
1149 expect(constructor.initializers, isEmpty);
1150 expect(constructor.redirectedConstructor, isNull);
1151 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>());
1152 }
1153
1127 void test_parseConstructor_with_pseudo_function_literal() { 1154 void test_parseConstructor_with_pseudo_function_literal() {
1128 // "(b) {}" should not be misinterpreted as a function literal even though 1155 // "(b) {}" should not be misinterpreted as a function literal even though
1129 // it looks like one. 1156 // it looks like one.
1130 createParser('C() : a = (b) {}'); 1157 createParser('C() : a = (b) {}');
1131 ClassMember member = parser.parseClassMember('C'); 1158 ClassMember member = parser.parseClassMember('C');
1132 expect(member, isNotNull); 1159 expect(member, isNotNull);
1133 assertNoErrors(); 1160 assertNoErrors();
1134 expect(member, new isInstanceOf<ConstructorDeclaration>()); 1161 expect(member, new isInstanceOf<ConstructorDeclaration>());
1135 ConstructorDeclaration constructor = member as ConstructorDeclaration; 1162 ConstructorDeclaration constructor = member as ConstructorDeclaration;
1136 NodeList<ConstructorInitializer> initializers = constructor.initializers; 1163 NodeList<ConstructorInitializer> initializers = constructor.initializers;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 createParser(''' 1317 createParser('''
1291 int f( 1318 int f(
1292 /// Doc 1319 /// Doc
1293 int x) {} 1320 int x) {}
1294 '''); 1321 ''');
1295 var function = parseFullCompilationUnitMember() as FunctionDeclaration; 1322 var function = parseFullCompilationUnitMember() as FunctionDeclaration;
1296 var parameter = function.functionExpression.parameters.parameters[0] 1323 var parameter = function.functionExpression.parameters.parameters[0]
1297 as NormalFormalParameter; 1324 as NormalFormalParameter;
1298 expectCommentText(parameter.documentationComment, '/// Doc'); 1325 expectCommentText(parameter.documentationComment, '/// Doc');
1299 } 1326 }
1327
1328 /**
1329 * Assert that the given [name] is in declaration context.
1330 */
1331 void _assertIsDeclarationName(SimpleIdentifier name, [bool expected = true]) {
1332 expect(name.inDeclarationContext(), expected);
1333 }
1300 } 1334 }
1301 1335
1302 /** 1336 /**
1303 * Tests of the analyzer parser based on [ComplexParserTestMixin]. 1337 * Tests of the analyzer parser based on [ComplexParserTestMixin].
1304 */ 1338 */
1305 @reflectiveTest 1339 @reflectiveTest
1306 class ComplexParserTest extends ParserTestCase with ComplexParserTestMixin {} 1340 class ComplexParserTest extends ParserTestCase with ComplexParserTestMixin {}
1307 1341
1308 /** 1342 /**
1309 * The class `ComplexParserTest` defines parser tests that test the parsing of m ore complex 1343 * The class `ComplexParserTest` defines parser tests that test the parsing of m ore complex
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 listener.assertErrorsWithCodes([ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); 3509 listener.assertErrorsWithCodes([ParserErrorCode.NON_CONSTRUCTOR_FACTORY]);
3476 } 3510 }
3477 3511
3478 void test_nonIdentifierLibraryName_library() { 3512 void test_nonIdentifierLibraryName_library() {
3479 CompilationUnit unit = parseCompilationUnit( 3513 CompilationUnit unit = parseCompilationUnit(
3480 "library 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); 3514 "library 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]);
3481 expect(unit, isNotNull); 3515 expect(unit, isNotNull);
3482 } 3516 }
3483 3517
3484 void test_nonIdentifierLibraryName_partOf() { 3518 void test_nonIdentifierLibraryName_partOf() {
3485 CompilationUnit unit = parseCompilationUnit( 3519 CompilationUnit unit = parseCompilationUnit("part of 3;", [
3486 "part of 3;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE, 3520 ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE,
3487 ParserErrorCode.UNEXPECTED_TOKEN]); 3521 ParserErrorCode.UNEXPECTED_TOKEN
3522 ]);
3488 expect(unit, isNotNull); 3523 expect(unit, isNotNull);
3489 } 3524 }
3490 3525
3491 void test_nonPartOfDirectiveInPart_after() { 3526 void test_nonPartOfDirectiveInPart_after() {
3492 parseCompilationUnit("part of l; part 'f.dart';", 3527 parseCompilationUnit("part of l; part 'f.dart';",
3493 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); 3528 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]);
3494 } 3529 }
3495 3530
3496 void test_nonPartOfDirectiveInPart_before() { 3531 void test_nonPartOfDirectiveInPart_before() {
3497 parseCompilationUnit("part 'f.dart'; part of m;", 3532 parseCompilationUnit("part 'f.dart'; part of m;",
(...skipping 9672 matching lines...) Expand 10 before | Expand all | Expand 10 after
13170 assertNoErrors(); 13205 assertNoErrors();
13171 expect(member, new isInstanceOf<ClassDeclaration>()); 13206 expect(member, new isInstanceOf<ClassDeclaration>());
13172 ClassDeclaration declaration = member; 13207 ClassDeclaration declaration = member;
13173 expect(declaration.documentationComment, isNull); 13208 expect(declaration.documentationComment, isNull);
13174 expect(declaration.abstractKeyword, isNull); 13209 expect(declaration.abstractKeyword, isNull);
13175 expect(declaration.extendsClause, isNull); 13210 expect(declaration.extendsClause, isNull);
13176 expect(declaration.implementsClause, isNull); 13211 expect(declaration.implementsClause, isNull);
13177 expect(declaration.classKeyword, isNotNull); 13212 expect(declaration.classKeyword, isNotNull);
13178 expect(declaration.leftBracket, isNotNull); 13213 expect(declaration.leftBracket, isNotNull);
13179 expect(declaration.name, isNotNull); 13214 expect(declaration.name, isNotNull);
13215 _assertIsDeclarationName(declaration.name);
13180 expect(declaration.members, hasLength(0)); 13216 expect(declaration.members, hasLength(0));
13181 expect(declaration.rightBracket, isNotNull); 13217 expect(declaration.rightBracket, isNotNull);
13182 expect(declaration.typeParameters, isNull); 13218 expect(declaration.typeParameters, isNull);
13183 } 13219 }
13184 13220
13185 void test_parseClassDeclaration_extends() { 13221 void test_parseClassDeclaration_extends() {
13186 createParser('class A extends B {}'); 13222 createParser('class A extends B {}');
13187 CompilationUnitMember member = parseFullCompilationUnitMember(); 13223 CompilationUnitMember member = parseFullCompilationUnitMember();
13188 expect(member, isNotNull); 13224 expect(member, isNotNull);
13189 assertNoErrors(); 13225 assertNoErrors();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
13315 13351
13316 void test_parseClassDeclaration_typeAlias_implementsC() { 13352 void test_parseClassDeclaration_typeAlias_implementsC() {
13317 createParser('class A = Object with B implements C;'); 13353 createParser('class A = Object with B implements C;');
13318 CompilationUnitMember member = parseFullCompilationUnitMember(); 13354 CompilationUnitMember member = parseFullCompilationUnitMember();
13319 expect(member, isNotNull); 13355 expect(member, isNotNull);
13320 assertNoErrors(); 13356 assertNoErrors();
13321 expect(member, new isInstanceOf<ClassTypeAlias>()); 13357 expect(member, new isInstanceOf<ClassTypeAlias>());
13322 ClassTypeAlias typeAlias = member; 13358 ClassTypeAlias typeAlias = member;
13323 expect(typeAlias.typedefKeyword, isNotNull); 13359 expect(typeAlias.typedefKeyword, isNotNull);
13324 expect(typeAlias.name, isNotNull); 13360 expect(typeAlias.name, isNotNull);
13361 _assertIsDeclarationName(typeAlias.name);
13325 expect(typeAlias.typeParameters, isNull); 13362 expect(typeAlias.typeParameters, isNull);
13326 expect(typeAlias.withClause, isNotNull); 13363 expect(typeAlias.withClause, isNotNull);
13327 expect(typeAlias.implementsClause, isNotNull); 13364 expect(typeAlias.implementsClause, isNotNull);
13328 expect(typeAlias.implementsClause.implementsKeyword, isNotNull); 13365 expect(typeAlias.implementsClause.implementsKeyword, isNotNull);
13329 expect(typeAlias.implementsClause.interfaces.length, 1); 13366 expect(typeAlias.implementsClause.interfaces.length, 1);
13330 expect(typeAlias.semicolon, isNotNull); 13367 expect(typeAlias.semicolon, isNotNull);
13331 } 13368 }
13332 13369
13333 void test_parseClassDeclaration_typeAlias_withB() { 13370 void test_parseClassDeclaration_typeAlias_withB() {
13334 createParser('class A = Object with B;'); 13371 createParser('class A = Object with B;');
(...skipping 19 matching lines...) Expand all
13354 assertNoErrors(); 13391 assertNoErrors();
13355 expect(member, new isInstanceOf<ClassDeclaration>()); 13392 expect(member, new isInstanceOf<ClassDeclaration>());
13356 ClassDeclaration declaration = member; 13393 ClassDeclaration declaration = member;
13357 expect(declaration.documentationComment, isNull); 13394 expect(declaration.documentationComment, isNull);
13358 expect(declaration.abstractKeyword, isNull); 13395 expect(declaration.abstractKeyword, isNull);
13359 expect(declaration.extendsClause, isNull); 13396 expect(declaration.extendsClause, isNull);
13360 expect(declaration.implementsClause, isNull); 13397 expect(declaration.implementsClause, isNull);
13361 expect(declaration.classKeyword, isNotNull); 13398 expect(declaration.classKeyword, isNotNull);
13362 expect(declaration.leftBracket, isNotNull); 13399 expect(declaration.leftBracket, isNotNull);
13363 expect(declaration.name, isNotNull); 13400 expect(declaration.name, isNotNull);
13401 _assertIsDeclarationName(declaration.name);
13364 expect(declaration.members, hasLength(0)); 13402 expect(declaration.members, hasLength(0));
13365 expect(declaration.rightBracket, isNotNull); 13403 expect(declaration.rightBracket, isNotNull);
13366 expect(declaration.typeParameters, isNotNull); 13404 expect(declaration.typeParameters, isNotNull);
13367 expect(declaration.typeParameters.typeParameters, hasLength(1)); 13405 expect(declaration.typeParameters.typeParameters, hasLength(1));
13406 _assertIsDeclarationName(declaration.typeParameters.typeParameters[0].name);
13368 } 13407 }
13369 13408
13370 void test_parseClassDeclaration_withDocumentationComment() { 13409 void test_parseClassDeclaration_withDocumentationComment() {
13371 createParser('/// Doc\nclass C {}'); 13410 createParser('/// Doc\nclass C {}');
13372 var classDeclaration = parseFullCompilationUnitMember() as ClassDeclaration; 13411 var classDeclaration = parseFullCompilationUnitMember() as ClassDeclaration;
13373 expectCommentText(classDeclaration.documentationComment, '/// Doc'); 13412 expectCommentText(classDeclaration.documentationComment, '/// Doc');
13374 } 13413 }
13375 13414
13376 void test_parseClassTypeAlias_withDocumentationComment() { 13415 void test_parseClassTypeAlias_withDocumentationComment() {
13377 createParser('/// Doc\nclass C = D with E;'); 13416 createParser('/// Doc\nclass C = D with E;');
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
13543 void test_parseCompilationUnitMember_constVariable() { 13582 void test_parseCompilationUnitMember_constVariable() {
13544 createParser('const int x = 0;'); 13583 createParser('const int x = 0;');
13545 CompilationUnitMember member = parseFullCompilationUnitMember(); 13584 CompilationUnitMember member = parseFullCompilationUnitMember();
13546 expect(member, isNotNull); 13585 expect(member, isNotNull);
13547 assertNoErrors(); 13586 assertNoErrors();
13548 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); 13587 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13549 TopLevelVariableDeclaration declaration = member; 13588 TopLevelVariableDeclaration declaration = member;
13550 expect(declaration.semicolon, isNotNull); 13589 expect(declaration.semicolon, isNotNull);
13551 expect(declaration.variables, isNotNull); 13590 expect(declaration.variables, isNotNull);
13552 expect(declaration.variables.keyword.lexeme, 'const'); 13591 expect(declaration.variables.keyword.lexeme, 'const');
13592 _assertIsDeclarationName(declaration.variables.variables[0].name);
13553 } 13593 }
13554 13594
13555 void test_parseCompilationUnitMember_expressionFunctionBody_tokens() { 13595 void test_parseCompilationUnitMember_expressionFunctionBody_tokens() {
13556 createParser('f() => 0;'); 13596 createParser('f() => 0;');
13557 var f = parseFullCompilationUnitMember() as FunctionDeclaration; 13597 var f = parseFullCompilationUnitMember() as FunctionDeclaration;
13558 var body = f.functionExpression.body as ExpressionFunctionBody; 13598 var body = f.functionExpression.body as ExpressionFunctionBody;
13559 expect(body.functionDefinition.lexeme, '=>'); 13599 expect(body.functionDefinition.lexeme, '=>');
13560 expect(body.semicolon.lexeme, ';'); 13600 expect(body.semicolon.lexeme, ';');
13601 _assertIsDeclarationName(f.name);
13561 } 13602 }
13562 13603
13563 void test_parseCompilationUnitMember_finalVariable() { 13604 void test_parseCompilationUnitMember_finalVariable() {
13564 createParser('final x = 0;'); 13605 createParser('final x = 0;');
13565 CompilationUnitMember member = parseFullCompilationUnitMember(); 13606 CompilationUnitMember member = parseFullCompilationUnitMember();
13566 expect(member, isNotNull); 13607 expect(member, isNotNull);
13567 assertNoErrors(); 13608 assertNoErrors();
13568 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); 13609 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13569 TopLevelVariableDeclaration declaration = member; 13610 TopLevelVariableDeclaration declaration = member;
13570 expect(declaration.semicolon, isNotNull); 13611 expect(declaration.semicolon, isNotNull);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
13676 void test_parseCompilationUnitMember_getter_external_noType() { 13717 void test_parseCompilationUnitMember_getter_external_noType() {
13677 createParser('external get p;'); 13718 createParser('external get p;');
13678 CompilationUnitMember member = parseFullCompilationUnitMember(); 13719 CompilationUnitMember member = parseFullCompilationUnitMember();
13679 expect(member, isNotNull); 13720 expect(member, isNotNull);
13680 assertNoErrors(); 13721 assertNoErrors();
13681 expect(member, new isInstanceOf<FunctionDeclaration>()); 13722 expect(member, new isInstanceOf<FunctionDeclaration>());
13682 FunctionDeclaration declaration = member; 13723 FunctionDeclaration declaration = member;
13683 expect(declaration.externalKeyword, isNotNull); 13724 expect(declaration.externalKeyword, isNotNull);
13684 expect(declaration.functionExpression, isNotNull); 13725 expect(declaration.functionExpression, isNotNull);
13685 expect(declaration.propertyKeyword, isNotNull); 13726 expect(declaration.propertyKeyword, isNotNull);
13727 _assertIsDeclarationName(declaration.name);
13686 } 13728 }
13687 13729
13688 void test_parseCompilationUnitMember_getter_external_type() { 13730 void test_parseCompilationUnitMember_getter_external_type() {
13689 createParser('external int get p;'); 13731 createParser('external int get p;');
13690 CompilationUnitMember member = parseFullCompilationUnitMember(); 13732 CompilationUnitMember member = parseFullCompilationUnitMember();
13691 expect(member, isNotNull); 13733 expect(member, isNotNull);
13692 assertNoErrors(); 13734 assertNoErrors();
13693 expect(member, new isInstanceOf<FunctionDeclaration>()); 13735 expect(member, new isInstanceOf<FunctionDeclaration>());
13694 FunctionDeclaration declaration = member; 13736 FunctionDeclaration declaration = member;
13695 expect(declaration.externalKeyword, isNotNull); 13737 expect(declaration.externalKeyword, isNotNull);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
13745 13787
13746 void test_parseCompilationUnitMember_setter_noType() { 13788 void test_parseCompilationUnitMember_setter_noType() {
13747 createParser('set p(v) {}'); 13789 createParser('set p(v) {}');
13748 CompilationUnitMember member = parseFullCompilationUnitMember(); 13790 CompilationUnitMember member = parseFullCompilationUnitMember();
13749 expect(member, isNotNull); 13791 expect(member, isNotNull);
13750 assertNoErrors(); 13792 assertNoErrors();
13751 expect(member, new isInstanceOf<FunctionDeclaration>()); 13793 expect(member, new isInstanceOf<FunctionDeclaration>());
13752 FunctionDeclaration declaration = member; 13794 FunctionDeclaration declaration = member;
13753 expect(declaration.functionExpression, isNotNull); 13795 expect(declaration.functionExpression, isNotNull);
13754 expect(declaration.propertyKeyword, isNotNull); 13796 expect(declaration.propertyKeyword, isNotNull);
13797 _assertIsDeclarationName(declaration.name);
13755 } 13798 }
13756 13799
13757 void test_parseCompilationUnitMember_setter_type() { 13800 void test_parseCompilationUnitMember_setter_type() {
13758 createParser('void set p(int v) {}'); 13801 createParser('void set p(int v) {}');
13759 CompilationUnitMember member = parseFullCompilationUnitMember(); 13802 CompilationUnitMember member = parseFullCompilationUnitMember();
13760 expect(member, isNotNull); 13803 expect(member, isNotNull);
13761 assertNoErrors(); 13804 assertNoErrors();
13762 expect(member, new isInstanceOf<FunctionDeclaration>()); 13805 expect(member, new isInstanceOf<FunctionDeclaration>());
13763 FunctionDeclaration declaration = member; 13806 FunctionDeclaration declaration = member;
13764 expect(declaration.functionExpression, isNotNull); 13807 expect(declaration.functionExpression, isNotNull);
13765 expect(declaration.propertyKeyword, isNotNull); 13808 expect(declaration.propertyKeyword, isNotNull);
13766 expect(declaration.returnType, isNotNull); 13809 expect(declaration.returnType, isNotNull);
13767 } 13810 }
13768 13811
13769 void test_parseCompilationUnitMember_typeAlias_abstract() { 13812 void test_parseCompilationUnitMember_typeAlias_abstract() {
13770 createParser('abstract class C = S with M;'); 13813 createParser('abstract class C = S with M;');
13771 CompilationUnitMember member = parseFullCompilationUnitMember(); 13814 CompilationUnitMember member = parseFullCompilationUnitMember();
13772 expect(member, isNotNull); 13815 expect(member, isNotNull);
13773 assertNoErrors(); 13816 assertNoErrors();
13774 expect(member, new isInstanceOf<ClassTypeAlias>()); 13817 expect(member, new isInstanceOf<ClassTypeAlias>());
13775 ClassTypeAlias typeAlias = member; 13818 ClassTypeAlias typeAlias = member;
13776 expect(typeAlias.typedefKeyword, isNotNull); 13819 expect(typeAlias.typedefKeyword, isNotNull);
13777 expect(typeAlias.name.name, "C"); 13820 expect(typeAlias.name.name, "C");
13821 _assertIsDeclarationName(typeAlias.name);
13778 expect(typeAlias.typeParameters, isNull); 13822 expect(typeAlias.typeParameters, isNull);
13779 expect(typeAlias.equals, isNotNull); 13823 expect(typeAlias.equals, isNotNull);
13780 expect(typeAlias.abstractKeyword, isNotNull); 13824 expect(typeAlias.abstractKeyword, isNotNull);
13781 expect(typeAlias.superclass.name.name, "S"); 13825 expect(typeAlias.superclass.name.name, "S");
13782 expect(typeAlias.withClause, isNotNull); 13826 expect(typeAlias.withClause, isNotNull);
13783 expect(typeAlias.implementsClause, isNull); 13827 expect(typeAlias.implementsClause, isNull);
13784 expect(typeAlias.semicolon, isNotNull); 13828 expect(typeAlias.semicolon, isNotNull);
13785 } 13829 }
13786 13830
13787 void test_parseCompilationUnitMember_typeAlias_generic() { 13831 void test_parseCompilationUnitMember_typeAlias_generic() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
13840 13884
13841 void test_parseCompilationUnitMember_typedef() { 13885 void test_parseCompilationUnitMember_typedef() {
13842 createParser('typedef F();'); 13886 createParser('typedef F();');
13843 CompilationUnitMember member = parseFullCompilationUnitMember(); 13887 CompilationUnitMember member = parseFullCompilationUnitMember();
13844 expect(member, isNotNull); 13888 expect(member, isNotNull);
13845 assertNoErrors(); 13889 assertNoErrors();
13846 expect(member, new isInstanceOf<FunctionTypeAlias>()); 13890 expect(member, new isInstanceOf<FunctionTypeAlias>());
13847 FunctionTypeAlias typeAlias = member; 13891 FunctionTypeAlias typeAlias = member;
13848 expect(typeAlias.name.name, "F"); 13892 expect(typeAlias.name.name, "F");
13849 expect(typeAlias.parameters.parameters, hasLength(0)); 13893 expect(typeAlias.parameters.parameters, hasLength(0));
13894 _assertIsDeclarationName(typeAlias.name);
13850 } 13895 }
13851 13896
13852 void test_parseCompilationUnitMember_typedef_withDocComment() { 13897 void test_parseCompilationUnitMember_typedef_withDocComment() {
13853 createParser('/// Doc\ntypedef F();'); 13898 createParser('/// Doc\ntypedef F();');
13854 var typeAlias = parseFullCompilationUnitMember() as FunctionTypeAlias; 13899 var typeAlias = parseFullCompilationUnitMember() as FunctionTypeAlias;
13855 expectCommentText(typeAlias.documentationComment, '/// Doc'); 13900 expectCommentText(typeAlias.documentationComment, '/// Doc');
13856 } 13901 }
13857 13902
13858 void test_parseCompilationUnitMember_typedVariable() { 13903 void test_parseCompilationUnitMember_typedVariable() {
13859 createParser('int x = 0;'); 13904 createParser('int x = 0;');
13860 CompilationUnitMember member = parseFullCompilationUnitMember(); 13905 CompilationUnitMember member = parseFullCompilationUnitMember();
13861 expect(member, isNotNull); 13906 expect(member, isNotNull);
13862 assertNoErrors(); 13907 assertNoErrors();
13863 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); 13908 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13864 TopLevelVariableDeclaration declaration = member; 13909 TopLevelVariableDeclaration declaration = member;
13865 expect(declaration.semicolon, isNotNull); 13910 expect(declaration.semicolon, isNotNull);
13866 expect(declaration.variables, isNotNull); 13911 expect(declaration.variables, isNotNull);
13867 expect(declaration.variables.type, isNotNull); 13912 expect(declaration.variables.type, isNotNull);
13868 expect(declaration.variables.keyword, isNull); 13913 expect(declaration.variables.keyword, isNull);
13914 _assertIsDeclarationName(declaration.variables.variables[0].name);
13869 } 13915 }
13870 13916
13871 void test_parseCompilationUnitMember_variable() { 13917 void test_parseCompilationUnitMember_variable() {
13872 createParser('var x = 0;'); 13918 createParser('var x = 0;');
13873 CompilationUnitMember member = parseFullCompilationUnitMember(); 13919 CompilationUnitMember member = parseFullCompilationUnitMember();
13874 expect(member, isNotNull); 13920 expect(member, isNotNull);
13875 assertNoErrors(); 13921 assertNoErrors();
13876 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); 13922 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13877 TopLevelVariableDeclaration declaration = member; 13923 TopLevelVariableDeclaration declaration = member;
13878 expect(declaration.semicolon, isNotNull); 13924 expect(declaration.semicolon, isNotNull);
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
14790 void test_parseTypeVariable_withDocumentationComment() { 14836 void test_parseTypeVariable_withDocumentationComment() {
14791 createParser(''' 14837 createParser('''
14792 class A< 14838 class A<
14793 /// Doc 14839 /// Doc
14794 B> {} 14840 B> {}
14795 '''); 14841 ''');
14796 var classDeclaration = parseFullCompilationUnitMember() as ClassDeclaration; 14842 var classDeclaration = parseFullCompilationUnitMember() as ClassDeclaration;
14797 var typeVariable = classDeclaration.typeParameters.typeParameters[0]; 14843 var typeVariable = classDeclaration.typeParameters.typeParameters[0];
14798 expectCommentText(typeVariable.documentationComment, '/// Doc'); 14844 expectCommentText(typeVariable.documentationComment, '/// Doc');
14799 } 14845 }
14846
14847 /**
14848 * Assert that the given [name] is in declaration context.
14849 */
14850 void _assertIsDeclarationName(SimpleIdentifier name) {
14851 expect(name.inDeclarationContext(), isTrue);
14852 }
14800 } 14853 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698