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

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

Issue 2342383002: Initial support for the NNBD proposal (Closed)
Patch Set: Addressed comments and added tests Created 4 years, 3 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 | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | 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/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/error/error.dart'; 10 import 'package:analyzer/error/error.dart';
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 339 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
340 BinaryExpression, expression.condition); 340 BinaryExpression, expression.condition);
341 } 341 }
342 342
343 void test_conditionalExpression_precedence_logicalOrExpression() { 343 void test_conditionalExpression_precedence_logicalOrExpression() {
344 ConditionalExpression expression = parseExpression("a | b ? y : z"); 344 ConditionalExpression expression = parseExpression("a | b ? y : z");
345 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 345 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
346 BinaryExpression, expression.condition); 346 BinaryExpression, expression.condition);
347 } 347 }
348 348
349 void test_conditionalExpression_precedence_nullableType() {
350 enableNnbd = true;
351 Expression expression = parseExpression('x is String ? (x + y) : z');
352 expect(expression, isNotNull);
353 expect(expression, new isInstanceOf<ConditionalExpression>());
354 ConditionalExpression conditional = expression;
355 Expression condition = conditional.condition;
356 expect(condition, new isInstanceOf<IsExpression>());
357 Expression thenExpression = conditional.thenExpression;
358 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>());
359 Expression elseExpression = conditional.elseExpression;
360 expect(elseExpression, new isInstanceOf<SimpleIdentifier>());
361 }
362
349 void test_constructor_initializer_withParenthesizedExpression() { 363 void test_constructor_initializer_withParenthesizedExpression() {
350 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' 364 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r'''
351 class C { 365 class C {
352 C() : 366 C() :
353 this.a = (b == null ? c : d) { 367 this.a = (b == null ? c : d) {
354 } 368 }
355 }'''); 369 }''');
356 NodeList<CompilationUnitMember> declarations = unit.declarations; 370 NodeList<CompilationUnitMember> declarations = unit.declarations;
357 expect(declarations, hasLength(1)); 371 expect(declarations, hasLength(1));
358 } 372 }
(...skipping 29 matching lines...) Expand all
388 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 402 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
389 BinaryExpression, expression.leftOperand); 403 BinaryExpression, expression.leftOperand);
390 } 404 }
391 405
392 void test_ifNullExpression_precedence_logicalOr_left() { 406 void test_ifNullExpression_precedence_logicalOr_left() {
393 BinaryExpression expression = parseExpression('x || y ?? z'); 407 BinaryExpression expression = parseExpression('x || y ?? z');
394 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 408 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
395 BinaryExpression, expression.leftOperand); 409 BinaryExpression, expression.leftOperand);
396 } 410 }
397 411
398 void test_ifNullExpression_precendce_logicalOr_right() { 412 void test_ifNullExpression_precedence_logicalOr_right() {
399 BinaryExpression expression = parseExpression('x ?? y || z'); 413 BinaryExpression expression = parseExpression('x ?? y || z');
400 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 414 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
401 BinaryExpression, expression.rightOperand); 415 BinaryExpression, expression.rightOperand);
402 } 416 }
403 417
404 void test_logicalAndExpression() { 418 void test_logicalAndExpression() {
405 BinaryExpression expression = parseExpression("x && y && z"); 419 BinaryExpression expression = parseExpression("x && y && z");
406 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 420 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
407 BinaryExpression, expression.leftOperand);
408 } 421 }
409 422
410 void test_logicalAndExpression_precedence_bitwiseOr_left() { 423 void test_logicalAndExpression_precedence_bitwiseOr_left() {
411 BinaryExpression expression = parseExpression("x | y < z"); 424 BinaryExpression expression = parseExpression("x | y < z");
412 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 425 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
413 BinaryExpression, expression.leftOperand);
414 } 426 }
415 427
416 void test_logicalAndExpression_precedence_bitwiseOr_right() { 428 void test_logicalAndExpression_precedence_bitwiseOr_right() {
417 BinaryExpression expression = parseExpression("x < y | z"); 429 BinaryExpression expression = parseExpression("x < y | z");
418 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 430 expect(expression.rightOperand, new isInstanceOf<BinaryExpression>());
419 BinaryExpression, expression.rightOperand); 431 }
432
433 void test_logicalAndExpression_precedence_nullableType() {
434 enableNnbd = true;
435 BinaryExpression expression = parseExpression("x is C? && y is D");
436 expect(expression.leftOperand, new isInstanceOf<IsExpression>());
437 expect(expression.rightOperand, new isInstanceOf<IsExpression>());
420 } 438 }
421 439
422 void test_logicalOrExpression() { 440 void test_logicalOrExpression() {
423 BinaryExpression expression = parseExpression("x || y || z"); 441 BinaryExpression expression = parseExpression("x || y || z");
424 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 442 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
425 BinaryExpression, expression.leftOperand);
426 } 443 }
427 444
428 void test_logicalOrExpression_precedence_logicalAnd_left() { 445 void test_logicalOrExpression_precedence_logicalAnd_left() {
429 BinaryExpression expression = parseExpression("x && y || z"); 446 BinaryExpression expression = parseExpression("x && y || z");
430 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 447 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
431 BinaryExpression, expression.leftOperand);
432 } 448 }
433 449
434 void test_logicalOrExpression_precedence_logicalAnd_right() { 450 void test_logicalOrExpression_precedence_logicalAnd_right() {
435 BinaryExpression expression = parseExpression("x || y && z"); 451 BinaryExpression expression = parseExpression("x || y && z");
436 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 452 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
437 BinaryExpression, expression.rightOperand); 453 BinaryExpression, expression.rightOperand);
438 } 454 }
439 455
456 void test_logicalOrExpression_precedence_nullableType() {
457 enableNnbd = true;
458 BinaryExpression expression = parseExpression("a is X? || (b ? c : d)");
459 expect(expression.leftOperand, new isInstanceOf<IsExpression>());
460 expect(
461 expression.rightOperand, new isInstanceOf<ParenthesizedExpression>());
462 expect((expression.rightOperand as ParenthesizedExpression).expression,
463 new isInstanceOf<ConditionalExpression>());
464 }
465
440 void test_multipleLabels_statement() { 466 void test_multipleLabels_statement() {
441 LabeledStatement statement = 467 LabeledStatement statement =
442 ParserTestCase.parseStatement("a: b: c: return x;"); 468 ParserTestCase.parseStatement("a: b: c: return x;");
443 expect(statement.labels, hasLength(3)); 469 expect(statement.labels, hasLength(3));
444 EngineTestCase.assertInstanceOf( 470 EngineTestCase.assertInstanceOf(
445 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement); 471 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement);
446 } 472 }
447 473
448 void test_multiplicativeExpression_normal() { 474 void test_multiplicativeExpression_normal() {
449 BinaryExpression expression = parseExpression("x * y / z"); 475 BinaryExpression expression = parseExpression("x * y / z");
(...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after
2411 */ 2437 */
2412 bool enableGenericMethodComments = false; 2438 bool enableGenericMethodComments = false;
2413 2439
2414 /** 2440 /**
2415 * A flag indicating whether lazy assignment operators should be enabled for 2441 * A flag indicating whether lazy assignment operators should be enabled for
2416 * the test. 2442 * the test.
2417 */ 2443 */
2418 bool enableLazyAssignmentOperators = false; 2444 bool enableLazyAssignmentOperators = false;
2419 2445
2420 /** 2446 /**
2447 * A flag indicating whether the parser is to parse the non-nullable modifier
2448 * in type names.
2449 */
2450 bool enableNnbd = false;
2451
2452 /**
2421 * Return a CommentAndMetadata object with the given values that can be used f or testing. 2453 * Return a CommentAndMetadata object with the given values that can be used f or testing.
2422 * 2454 *
2423 * @param comment the comment to be wrapped in the object 2455 * @param comment the comment to be wrapped in the object
2424 * @param annotations the annotations to be wrapped in the object 2456 * @param annotations the annotations to be wrapped in the object
2425 * @return a CommentAndMetadata object that can be used for testing 2457 * @return a CommentAndMetadata object that can be used for testing
2426 */ 2458 */
2427 CommentAndMetadata commentAndMetadata(Comment comment, 2459 CommentAndMetadata commentAndMetadata(Comment comment,
2428 [List<Annotation> annotations]) { 2460 [List<Annotation> annotations]) {
2429 return new CommentAndMetadata(comment, annotations); 2461 return new CommentAndMetadata(comment, annotations);
2430 } 2462 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2466 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2498 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2467 // 2499 //
2468 // Parse the source. 2500 // Parse the source.
2469 // 2501 //
2470 Parser parser = createParser(listener); 2502 Parser parser = createParser(listener);
2471 parser.enableAssertInitializer = enableAssertInitializer; 2503 parser.enableAssertInitializer = enableAssertInitializer;
2472 parser.parseAsync = parseAsync; 2504 parser.parseAsync = parseAsync;
2473 parser.parseGenericMethods = enableGenericMethods; 2505 parser.parseGenericMethods = enableGenericMethods;
2474 parser.parseGenericMethodComments = enableGenericMethodComments; 2506 parser.parseGenericMethodComments = enableGenericMethodComments;
2475 parser.parseFunctionBodies = parseFunctionBodies; 2507 parser.parseFunctionBodies = parseFunctionBodies;
2508 parser.enableNnbd = enableNnbd;
2476 Object result = 2509 Object result =
2477 invokeParserMethodImpl(parser, methodName, objects, tokenStream); 2510 invokeParserMethodImpl(parser, methodName, objects, tokenStream);
2478 // 2511 //
2479 // Partially test the results. 2512 // Partially test the results.
2480 // 2513 //
2481 if (!listener.hasErrors) { 2514 if (!listener.hasErrors) {
2482 expect(result, isNotNull); 2515 expect(result, isNotNull);
2483 } 2516 }
2484 return result; 2517 return result;
2485 } 2518 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 Scanner scanner = 2629 Scanner scanner =
2597 new Scanner(null, new CharSequenceReader(source), listener); 2630 new Scanner(null, new CharSequenceReader(source), listener);
2598 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2631 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2599 Token token = scanner.tokenize(); 2632 Token token = scanner.tokenize();
2600 Parser parser = createParser(listener); 2633 Parser parser = createParser(listener);
2601 parser.enableAssertInitializer = enableAssertInitializer; 2634 parser.enableAssertInitializer = enableAssertInitializer;
2602 parser.parseAsync = parseAsync; 2635 parser.parseAsync = parseAsync;
2603 parser.parseFunctionBodies = parseFunctionBodies; 2636 parser.parseFunctionBodies = parseFunctionBodies;
2604 parser.parseGenericMethods = enableGenericMethods; 2637 parser.parseGenericMethods = enableGenericMethods;
2605 parser.parseGenericMethodComments = enableGenericMethodComments; 2638 parser.parseGenericMethodComments = enableGenericMethodComments;
2639 parser.enableNnbd = enableNnbd;
2606 CompilationUnit unit = parser.parseCompilationUnit(token); 2640 CompilationUnit unit = parser.parseCompilationUnit(token);
2607 expect(unit, isNotNull); 2641 expect(unit, isNotNull);
2608 listener.assertErrorsWithCodes(errorCodes); 2642 listener.assertErrorsWithCodes(errorCodes);
2609 return unit; 2643 return unit;
2610 } 2644 }
2611 2645
2612 /** 2646 /**
2613 * Parse the given source as an expression. 2647 * Parse the given source as an expression.
2614 * 2648 *
2615 * @param source the source to be parsed 2649 * @param source the source to be parsed
2616 * @param errorCodes the error codes of the errors that are expected to be fou nd 2650 * @param errorCodes the error codes of the errors that are expected to be fou nd
2617 * @return the expression that was parsed 2651 * @return the expression that was parsed
2618 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 2652 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
2619 * not match those that are expected, or if the result would have be en `null` 2653 * not match those that are expected, or if the result would have be en `null`
2620 */ 2654 */
2621 Expression parseExpression(String source, 2655 Expression parseExpression(String source,
2622 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 2656 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) {
2623 GatheringErrorListener listener = new GatheringErrorListener(); 2657 GatheringErrorListener listener = new GatheringErrorListener();
2624 Scanner scanner = 2658 Scanner scanner =
2625 new Scanner(null, new CharSequenceReader(source), listener); 2659 new Scanner(null, new CharSequenceReader(source), listener);
2626 scanner.scanGenericMethodComments = enableGenericMethodComments; 2660 scanner.scanGenericMethodComments = enableGenericMethodComments;
2627 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2661 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2628 Token token = scanner.tokenize(); 2662 Token token = scanner.tokenize();
2629 Parser parser = createParser(listener); 2663 Parser parser = createParser(listener);
2630 parser.parseGenericMethods = enableGenericMethods; 2664 parser.parseGenericMethods = enableGenericMethods;
2631 parser.parseGenericMethodComments = enableGenericMethodComments; 2665 parser.parseGenericMethodComments = enableGenericMethodComments;
2666 parser.enableNnbd = enableNnbd;
2632 Expression expression = parser.parseExpression(token); 2667 Expression expression = parser.parseExpression(token);
2633 expect(expression, isNotNull); 2668 expect(expression, isNotNull);
2634 listener.assertErrorsWithCodes(errorCodes); 2669 listener.assertErrorsWithCodes(errorCodes);
2635 return expression; 2670 return expression;
2636 } 2671 }
2637 2672
2638 @override 2673 @override
2639 void setUp() { 2674 void setUp() {
2640 super.setUp(); 2675 super.setUp();
2641 parseFunctionBodies = true; 2676 parseFunctionBodies = true;
(...skipping 6447 matching lines...) Expand 10 before | Expand all | Expand 10 after
9089 9124
9090 void test_parseNormalFormalParameter_function_noType() { 9125 void test_parseNormalFormalParameter_function_noType() {
9091 FunctionTypedFormalParameter parameter = 9126 FunctionTypedFormalParameter parameter =
9092 parse4("parseNormalFormalParameter", "a())"); 9127 parse4("parseNormalFormalParameter", "a())");
9093 expect(parameter.returnType, isNull); 9128 expect(parameter.returnType, isNull);
9094 expect(parameter.identifier, isNotNull); 9129 expect(parameter.identifier, isNotNull);
9095 expect(parameter.typeParameters, isNull); 9130 expect(parameter.typeParameters, isNull);
9096 expect(parameter.parameters, isNotNull); 9131 expect(parameter.parameters, isNotNull);
9097 } 9132 }
9098 9133
9134 void test_parseNormalFormalParameter_function_noType_nullable() {
9135 enableNnbd = true;
9136 FunctionTypedFormalParameter parameter =
9137 parse4("parseNormalFormalParameter", "a()?)");
9138 expect(parameter.returnType, isNull);
9139 expect(parameter.identifier, isNotNull);
9140 expect(parameter.typeParameters, isNull);
9141 expect(parameter.parameters, isNotNull);
9142 expect(parameter.question, isNotNull);
9143 }
9144
9099 void test_parseNormalFormalParameter_function_noType_typeParameterComments() { 9145 void test_parseNormalFormalParameter_function_noType_typeParameterComments() {
9100 enableGenericMethodComments = true; 9146 enableGenericMethodComments = true;
9101 FunctionTypedFormalParameter parameter = 9147 FunctionTypedFormalParameter parameter =
9102 parse4("parseNormalFormalParameter", "a/*<E>*/())"); 9148 parse4("parseNormalFormalParameter", "a/*<E>*/())");
9103 expect(parameter.returnType, isNull); 9149 expect(parameter.returnType, isNull);
9104 expect(parameter.identifier, isNotNull); 9150 expect(parameter.identifier, isNotNull);
9105 expect(parameter.typeParameters, isNotNull); 9151 expect(parameter.typeParameters, isNotNull);
9106 expect(parameter.parameters, isNotNull); 9152 expect(parameter.parameters, isNotNull);
9107 } 9153 }
9108 9154
9109 void test_parseNormalFormalParameter_function_noType_typeParameters() { 9155 void test_parseNormalFormalParameter_function_noType_typeParameters() {
9110 enableGenericMethods = true; 9156 enableGenericMethods = true;
9111 FunctionTypedFormalParameter parameter = 9157 FunctionTypedFormalParameter parameter =
9112 parse4("parseNormalFormalParameter", "a<E>())"); 9158 parse4("parseNormalFormalParameter", "a<E>())");
9113 expect(parameter.returnType, isNull); 9159 expect(parameter.returnType, isNull);
9114 expect(parameter.identifier, isNotNull); 9160 expect(parameter.identifier, isNotNull);
9115 expect(parameter.typeParameters, isNotNull); 9161 expect(parameter.typeParameters, isNotNull);
9116 expect(parameter.parameters, isNotNull); 9162 expect(parameter.parameters, isNotNull);
9163 expect(parameter.question, isNull);
9164 expect(parameter.question, isNull);
9165 }
9166
9167 void
9168 test_parseNormalFormalParameter_function_noType_typeParameters_nullable() {
9169 enableGenericMethods = true;
9170 enableNnbd = true;
9171 FunctionTypedFormalParameter parameter =
9172 parse4("parseNormalFormalParameter", "a<E>()?)");
9173 expect(parameter.returnType, isNull);
9174 expect(parameter.identifier, isNotNull);
9175 expect(parameter.typeParameters, isNotNull);
9176 expect(parameter.parameters, isNotNull);
9177 expect(parameter.question, isNotNull);
9117 } 9178 }
9118 9179
9119 void test_parseNormalFormalParameter_function_type() { 9180 void test_parseNormalFormalParameter_function_type() {
9120 FunctionTypedFormalParameter parameter = 9181 FunctionTypedFormalParameter parameter =
9121 parse4("parseNormalFormalParameter", "A a())"); 9182 parse4("parseNormalFormalParameter", "A a())");
9122 expect(parameter.returnType, isNotNull); 9183 expect(parameter.returnType, isNotNull);
9123 expect(parameter.identifier, isNotNull); 9184 expect(parameter.identifier, isNotNull);
9124 expect(parameter.typeParameters, isNull); 9185 expect(parameter.typeParameters, isNull);
9125 expect(parameter.parameters, isNotNull); 9186 expect(parameter.parameters, isNotNull);
9187 expect(parameter.question, isNull);
9188 }
9189
9190 void test_parseNormalFormalParameter_function_type_nullable() {
9191 enableNnbd = true;
9192 FunctionTypedFormalParameter parameter =
9193 parse4("parseNormalFormalParameter", "A a()?)");
9194 expect(parameter.returnType, isNotNull);
9195 expect(parameter.identifier, isNotNull);
9196 expect(parameter.typeParameters, isNull);
9197 expect(parameter.parameters, isNotNull);
9198 expect(parameter.question, isNotNull);
9126 } 9199 }
9127 9200
9128 void test_parseNormalFormalParameter_function_type_typeParameterComments() { 9201 void test_parseNormalFormalParameter_function_type_typeParameterComments() {
9129 enableGenericMethodComments = true; 9202 enableGenericMethodComments = true;
9130 FunctionTypedFormalParameter parameter = 9203 FunctionTypedFormalParameter parameter =
9131 parse4("parseNormalFormalParameter", "A a/*<E>*/())"); 9204 parse4("parseNormalFormalParameter", "A a/*<E>*/())");
9132 expect(parameter.returnType, isNotNull); 9205 expect(parameter.returnType, isNotNull);
9133 expect(parameter.identifier, isNotNull); 9206 expect(parameter.identifier, isNotNull);
9134 expect(parameter.typeParameters, isNotNull); 9207 expect(parameter.typeParameters, isNotNull);
9135 expect(parameter.parameters, isNotNull); 9208 expect(parameter.parameters, isNotNull);
9209 expect(parameter.question, isNull);
9136 } 9210 }
9137 9211
9138 void test_parseNormalFormalParameter_function_type_typeParameters() { 9212 void test_parseNormalFormalParameter_function_type_typeParameters() {
9139 enableGenericMethods = true; 9213 enableGenericMethods = true;
9140 FunctionTypedFormalParameter parameter = 9214 FunctionTypedFormalParameter parameter =
9141 parse4("parseNormalFormalParameter", "A a<E>())"); 9215 parse4("parseNormalFormalParameter", "A a<E>())");
9142 expect(parameter.returnType, isNotNull); 9216 expect(parameter.returnType, isNotNull);
9143 expect(parameter.identifier, isNotNull); 9217 expect(parameter.identifier, isNotNull);
9144 expect(parameter.typeParameters, isNotNull); 9218 expect(parameter.typeParameters, isNotNull);
9145 expect(parameter.parameters, isNotNull); 9219 expect(parameter.parameters, isNotNull);
9220 expect(parameter.question, isNull);
9221 }
9222
9223 void test_parseNormalFormalParameter_function_type_typeParameters_nullable() {
9224 enableGenericMethods = true;
9225 enableNnbd = true;
9226 FunctionTypedFormalParameter parameter =
9227 parse4("parseNormalFormalParameter", "A a<E>()?)");
9228 expect(parameter.returnType, isNotNull);
9229 expect(parameter.identifier, isNotNull);
9230 expect(parameter.typeParameters, isNotNull);
9231 expect(parameter.parameters, isNotNull);
9232 expect(parameter.question, isNotNull);
9146 } 9233 }
9147 9234
9148 void test_parseNormalFormalParameter_function_void() { 9235 void test_parseNormalFormalParameter_function_void() {
9149 FunctionTypedFormalParameter parameter = 9236 FunctionTypedFormalParameter parameter =
9150 parse4("parseNormalFormalParameter", "void a())"); 9237 parse4("parseNormalFormalParameter", "void a())");
9151 expect(parameter.returnType, isNotNull); 9238 expect(parameter.returnType, isNotNull);
9152 expect(parameter.identifier, isNotNull); 9239 expect(parameter.identifier, isNotNull);
9153 expect(parameter.typeParameters, isNull); 9240 expect(parameter.typeParameters, isNull);
9154 expect(parameter.parameters, isNotNull); 9241 expect(parameter.parameters, isNotNull);
9242 expect(parameter.question, isNull);
9243 }
9244
9245 void test_parseNormalFormalParameter_function_void_nullable() {
9246 enableNnbd = true;
9247 FunctionTypedFormalParameter parameter =
9248 parse4("parseNormalFormalParameter", "void a()?)");
9249 expect(parameter.returnType, isNotNull);
9250 expect(parameter.identifier, isNotNull);
9251 expect(parameter.typeParameters, isNull);
9252 expect(parameter.parameters, isNotNull);
9253 expect(parameter.question, isNotNull);
9155 } 9254 }
9156 9255
9157 void test_parseNormalFormalParameter_function_void_typeParameterComments() { 9256 void test_parseNormalFormalParameter_function_void_typeParameterComments() {
9158 enableGenericMethodComments = true; 9257 enableGenericMethodComments = true;
9159 FunctionTypedFormalParameter parameter = 9258 FunctionTypedFormalParameter parameter =
9160 parse4("parseNormalFormalParameter", "void a/*<E>*/())"); 9259 parse4("parseNormalFormalParameter", "void a/*<E>*/())");
9161 expect(parameter.returnType, isNotNull); 9260 expect(parameter.returnType, isNotNull);
9162 expect(parameter.identifier, isNotNull); 9261 expect(parameter.identifier, isNotNull);
9163 expect(parameter.typeParameters, isNotNull); 9262 expect(parameter.typeParameters, isNotNull);
9164 expect(parameter.parameters, isNotNull); 9263 expect(parameter.parameters, isNotNull);
9264 expect(parameter.question, isNull);
9165 } 9265 }
9166 9266
9167 void test_parseNormalFormalParameter_function_void_typeParameters() { 9267 void test_parseNormalFormalParameter_function_void_typeParameters() {
9168 enableGenericMethods = true; 9268 enableGenericMethods = true;
9169 FunctionTypedFormalParameter parameter = 9269 FunctionTypedFormalParameter parameter =
9170 parse4("parseNormalFormalParameter", "void a<E>())"); 9270 parse4("parseNormalFormalParameter", "void a<E>())");
9171 expect(parameter.returnType, isNotNull); 9271 expect(parameter.returnType, isNotNull);
9172 expect(parameter.identifier, isNotNull); 9272 expect(parameter.identifier, isNotNull);
9173 expect(parameter.typeParameters, isNotNull); 9273 expect(parameter.typeParameters, isNotNull);
9174 expect(parameter.parameters, isNotNull); 9274 expect(parameter.parameters, isNotNull);
9275 expect(parameter.question, isNull);
9276 }
9277
9278 void test_parseNormalFormalParameter_function_void_typeParameters_nullable() {
9279 enableGenericMethods = true;
9280 enableNnbd = true;
9281 FunctionTypedFormalParameter parameter =
9282 parse4("parseNormalFormalParameter", "void a<E>()?)");
9283 expect(parameter.returnType, isNotNull);
9284 expect(parameter.identifier, isNotNull);
9285 expect(parameter.typeParameters, isNotNull);
9286 expect(parameter.parameters, isNotNull);
9287 expect(parameter.question, isNotNull);
9175 } 9288 }
9176 9289
9177 void test_parseNormalFormalParameter_simple_const_noType() { 9290 void test_parseNormalFormalParameter_simple_const_noType() {
9178 SimpleFormalParameter parameter = 9291 SimpleFormalParameter parameter =
9179 parse4("parseNormalFormalParameter", "const a)"); 9292 parse4("parseNormalFormalParameter", "const a)");
9180 expect(parameter.keyword, isNotNull); 9293 expect(parameter.keyword, isNotNull);
9181 expect(parameter.type, isNull); 9294 expect(parameter.type, isNull);
9182 expect(parameter.identifier, isNotNull); 9295 expect(parameter.identifier, isNotNull);
9183 } 9296 }
9184 9297
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
10365 TypeArgumentList argumentList = parse4("parseTypeArgumentList", "<int>"); 10478 TypeArgumentList argumentList = parse4("parseTypeArgumentList", "<int>");
10366 expect(argumentList.leftBracket, isNotNull); 10479 expect(argumentList.leftBracket, isNotNull);
10367 expect(argumentList.arguments, hasLength(1)); 10480 expect(argumentList.arguments, hasLength(1));
10368 expect(argumentList.rightBracket, isNotNull); 10481 expect(argumentList.rightBracket, isNotNull);
10369 } 10482 }
10370 10483
10371 void test_parseTypeName_parameterized() { 10484 void test_parseTypeName_parameterized() {
10372 TypeName typeName = parse4("parseTypeName", "List<int>"); 10485 TypeName typeName = parse4("parseTypeName", "List<int>");
10373 expect(typeName.name, isNotNull); 10486 expect(typeName.name, isNotNull);
10374 expect(typeName.typeArguments, isNotNull); 10487 expect(typeName.typeArguments, isNotNull);
10488 expect(typeName.question, isNull);
10489 }
10490
10491 void test_parseTypeName_parameterized_nullable() {
10492 enableNnbd = true;
10493 TypeName typeName = parse4("parseTypeName", "List<int>?");
10494 expect(typeName.name, isNotNull);
10495 expect(typeName.typeArguments, isNotNull);
10496 expect(typeName.question, isNotNull);
10375 } 10497 }
10376 10498
10377 void test_parseTypeName_simple() { 10499 void test_parseTypeName_simple() {
10378 TypeName typeName = parse4("parseTypeName", "int"); 10500 TypeName typeName = parse4("parseTypeName", "int");
10379 expect(typeName.name, isNotNull); 10501 expect(typeName.name, isNotNull);
10380 expect(typeName.typeArguments, isNull); 10502 expect(typeName.typeArguments, isNull);
10503 expect(typeName.question, isNull);
10504 }
10505
10506 void test_parseTypeName_simple_nullable() {
10507 enableNnbd = true;
10508 TypeName typeName = parse4("parseTypeName", "String?");
10509 expect(typeName.name, isNotNull);
10510 expect(typeName.typeArguments, isNull);
10511 expect(typeName.question, isNotNull);
10381 } 10512 }
10382 10513
10383 void test_parseTypeParameter_bounded() { 10514 void test_parseTypeParameter_bounded() {
10384 TypeParameter parameter = parse4("parseTypeParameter", "A extends B"); 10515 TypeParameter parameter = parse4("parseTypeParameter", "A extends B");
10385 expect(parameter.bound, isNotNull); 10516 expect(parameter.bound, isNotNull);
10386 expect(parameter.extendsKeyword, isNotNull); 10517 expect(parameter.extendsKeyword, isNotNull);
10387 expect(parameter.name, isNotNull); 10518 expect(parameter.name, isNotNull);
10388 } 10519 }
10389 10520
10390 void test_parseTypeParameter_simple() { 10521 void test_parseTypeParameter_simple() {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
11006 new Scanner(null, new CharSequenceReader(source), listener); 11137 new Scanner(null, new CharSequenceReader(source), listener);
11007 Token tokenStream = scanner.tokenize(); 11138 Token tokenStream = scanner.tokenize();
11008 // 11139 //
11009 // Parse the source. 11140 // Parse the source.
11010 // 11141 //
11011 Parser parser = new Parser(null, listener); 11142 Parser parser = new Parser(null, listener);
11012 return invokeParserMethodImpl( 11143 return invokeParserMethodImpl(
11013 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 11144 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
11014 } 11145 }
11015 } 11146 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698