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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 2524903002: Rename AstFactory -> AstTestFactory. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
14 import 'package:analyzer/src/dart/element/handle.dart'; 14 import 'package:analyzer/src/dart/element/handle.dart';
15 import 'package:analyzer/src/dart/element/member.dart'; 15 import 'package:analyzer/src/dart/element/member.dart';
16 import 'package:analyzer/src/dart/element/type.dart'; 16 import 'package:analyzer/src/dart/element/type.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/resolver.dart'; 18 import 'package:analyzer/src/generated/resolver.dart';
19 import 'package:analyzer/src/generated/source_io.dart'; 19 import 'package:analyzer/src/generated/source_io.dart';
20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 20 import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
21 import 'package:analyzer/src/generated/testing/token_factory.dart'; 21 import 'package:analyzer/src/generated/testing/token_factory.dart';
22 import 'package:analyzer/src/summary/format.dart'; 22 import 'package:analyzer/src/summary/format.dart';
23 import 'package:analyzer/src/summary/idl.dart'; 23 import 'package:analyzer/src/summary/idl.dart';
24 24
25 /** 25 /**
26 * Implementation of [ElementResynthesizer] used when resynthesizing an element 26 * Implementation of [ElementResynthesizer] used when resynthesizing an element
27 * model from summaries. 27 * model from summaries.
28 */ 28 */
29 abstract class SummaryResynthesizer extends ElementResynthesizer { 29 abstract class SummaryResynthesizer extends ElementResynthesizer {
30 /** 30 /**
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (e is ConstructorElement) { 324 if (e is ConstructorElement) {
325 return e; 325 return e;
326 } 326 }
327 } 327 }
328 throw new StateError( 328 throw new StateError(
329 'Unable to find the enclosing constructor of $context'); 329 'Unable to find the enclosing constructor of $context');
330 } 330 }
331 331
332 Expression build() { 332 Expression build() {
333 if (!uc.isValidConst) { 333 if (!uc.isValidConst) {
334 return AstFactory.identifier3(r'$$invalidConstExpr$$'); 334 return AstTestFactory.identifier3(r'$$invalidConstExpr$$');
335 } 335 }
336 for (UnlinkedExprOperation operation in uc.operations) { 336 for (UnlinkedExprOperation operation in uc.operations) {
337 switch (operation) { 337 switch (operation) {
338 case UnlinkedExprOperation.pushNull: 338 case UnlinkedExprOperation.pushNull:
339 _push(AstFactory.nullLiteral()); 339 _push(AstTestFactory.nullLiteral());
340 break; 340 break;
341 // bool 341 // bool
342 case UnlinkedExprOperation.pushFalse: 342 case UnlinkedExprOperation.pushFalse:
343 _push(AstFactory.booleanLiteral(false)); 343 _push(AstTestFactory.booleanLiteral(false));
344 break; 344 break;
345 case UnlinkedExprOperation.pushTrue: 345 case UnlinkedExprOperation.pushTrue:
346 _push(AstFactory.booleanLiteral(true)); 346 _push(AstTestFactory.booleanLiteral(true));
347 break; 347 break;
348 // literals 348 // literals
349 case UnlinkedExprOperation.pushInt: 349 case UnlinkedExprOperation.pushInt:
350 int value = uc.ints[intPtr++]; 350 int value = uc.ints[intPtr++];
351 _push(AstFactory.integer(value)); 351 _push(AstTestFactory.integer(value));
352 break; 352 break;
353 case UnlinkedExprOperation.pushLongInt: 353 case UnlinkedExprOperation.pushLongInt:
354 int value = 0; 354 int value = 0;
355 int count = uc.ints[intPtr++]; 355 int count = uc.ints[intPtr++];
356 for (int i = 0; i < count; i++) { 356 for (int i = 0; i < count; i++) {
357 int next = uc.ints[intPtr++]; 357 int next = uc.ints[intPtr++];
358 value = value << 32 | next; 358 value = value << 32 | next;
359 } 359 }
360 _push(AstFactory.integer(value)); 360 _push(AstTestFactory.integer(value));
361 break; 361 break;
362 case UnlinkedExprOperation.pushDouble: 362 case UnlinkedExprOperation.pushDouble:
363 double value = uc.doubles[doublePtr++]; 363 double value = uc.doubles[doublePtr++];
364 _push(AstFactory.doubleLiteral(value)); 364 _push(AstTestFactory.doubleLiteral(value));
365 break; 365 break;
366 case UnlinkedExprOperation.makeSymbol: 366 case UnlinkedExprOperation.makeSymbol:
367 String component = uc.strings[stringPtr++]; 367 String component = uc.strings[stringPtr++];
368 _push(AstFactory.symbolLiteral([component])); 368 _push(AstTestFactory.symbolLiteral([component]));
369 break; 369 break;
370 // String 370 // String
371 case UnlinkedExprOperation.pushString: 371 case UnlinkedExprOperation.pushString:
372 String value = uc.strings[stringPtr++]; 372 String value = uc.strings[stringPtr++];
373 _push(AstFactory.string2(value)); 373 _push(AstTestFactory.string2(value));
374 break; 374 break;
375 case UnlinkedExprOperation.concatenate: 375 case UnlinkedExprOperation.concatenate:
376 int count = uc.ints[intPtr++]; 376 int count = uc.ints[intPtr++];
377 List<InterpolationElement> elements = <InterpolationElement>[]; 377 List<InterpolationElement> elements = <InterpolationElement>[];
378 for (int i = 0; i < count; i++) { 378 for (int i = 0; i < count; i++) {
379 Expression expr = _pop(); 379 Expression expr = _pop();
380 InterpolationElement element = _newInterpolationElement(expr); 380 InterpolationElement element = _newInterpolationElement(expr);
381 elements.insert(0, element); 381 elements.insert(0, element);
382 } 382 }
383 _push(AstFactory.string(elements)); 383 _push(AstTestFactory.string(elements));
384 break; 384 break;
385 // binary 385 // binary
386 case UnlinkedExprOperation.equal: 386 case UnlinkedExprOperation.equal:
387 _pushBinary(TokenType.EQ_EQ); 387 _pushBinary(TokenType.EQ_EQ);
388 break; 388 break;
389 case UnlinkedExprOperation.notEqual: 389 case UnlinkedExprOperation.notEqual:
390 _pushBinary(TokenType.BANG_EQ); 390 _pushBinary(TokenType.BANG_EQ);
391 break; 391 break;
392 case UnlinkedExprOperation.and: 392 case UnlinkedExprOperation.and:
393 _pushBinary(TokenType.AMPERSAND_AMPERSAND); 393 _pushBinary(TokenType.AMPERSAND_AMPERSAND);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 _pushPrefix(TokenType.MINUS); 448 _pushPrefix(TokenType.MINUS);
449 break; 449 break;
450 case UnlinkedExprOperation.not: 450 case UnlinkedExprOperation.not:
451 _pushPrefix(TokenType.BANG); 451 _pushPrefix(TokenType.BANG);
452 break; 452 break;
453 // conditional 453 // conditional
454 case UnlinkedExprOperation.conditional: 454 case UnlinkedExprOperation.conditional:
455 Expression elseExpr = _pop(); 455 Expression elseExpr = _pop();
456 Expression thenExpr = _pop(); 456 Expression thenExpr = _pop();
457 Expression condition = _pop(); 457 Expression condition = _pop();
458 _push( 458 _push(AstTestFactory.conditionalExpression(
459 AstFactory.conditionalExpression(condition, thenExpr, elseExpr)); 459 condition, thenExpr, elseExpr));
460 break; 460 break;
461 // invokeMethodRef 461 // invokeMethodRef
462 case UnlinkedExprOperation.invokeMethodRef: 462 case UnlinkedExprOperation.invokeMethodRef:
463 _pushInvokeMethodRef(); 463 _pushInvokeMethodRef();
464 break; 464 break;
465 // containers 465 // containers
466 case UnlinkedExprOperation.makeUntypedList: 466 case UnlinkedExprOperation.makeUntypedList:
467 _pushList(null); 467 _pushList(null);
468 break; 468 break;
469 case UnlinkedExprOperation.makeTypedList: 469 case UnlinkedExprOperation.makeTypedList:
470 TypeName itemType = _newTypeName(); 470 TypeName itemType = _newTypeName();
471 _pushList(AstFactory.typeArgumentList(<TypeName>[itemType])); 471 _pushList(AstTestFactory.typeArgumentList(<TypeName>[itemType]));
472 break; 472 break;
473 case UnlinkedExprOperation.makeUntypedMap: 473 case UnlinkedExprOperation.makeUntypedMap:
474 _pushMap(null); 474 _pushMap(null);
475 break; 475 break;
476 case UnlinkedExprOperation.makeTypedMap: 476 case UnlinkedExprOperation.makeTypedMap:
477 TypeName keyType = _newTypeName(); 477 TypeName keyType = _newTypeName();
478 TypeName valueType = _newTypeName(); 478 TypeName valueType = _newTypeName();
479 _pushMap(AstFactory.typeArgumentList(<TypeName>[keyType, valueType])); 479 _pushMap(
480 AstTestFactory.typeArgumentList(<TypeName>[keyType, valueType]));
480 break; 481 break;
481 case UnlinkedExprOperation.pushReference: 482 case UnlinkedExprOperation.pushReference:
482 _pushReference(); 483 _pushReference();
483 break; 484 break;
484 case UnlinkedExprOperation.extractProperty: 485 case UnlinkedExprOperation.extractProperty:
485 _pushExtractProperty(); 486 _pushExtractProperty();
486 break; 487 break;
487 case UnlinkedExprOperation.invokeConstructor: 488 case UnlinkedExprOperation.invokeConstructor:
488 _pushInstanceCreation(); 489 _pushInstanceCreation();
489 break; 490 break;
490 case UnlinkedExprOperation.pushParameter: 491 case UnlinkedExprOperation.pushParameter:
491 String name = uc.strings[stringPtr++]; 492 String name = uc.strings[stringPtr++];
492 SimpleIdentifier identifier = AstFactory.identifier3(name); 493 SimpleIdentifier identifier = AstTestFactory.identifier3(name);
493 identifier.staticElement = _enclosingConstructor.parameters 494 identifier.staticElement = _enclosingConstructor.parameters
494 .firstWhere((parameter) => parameter.name == name, 495 .firstWhere((parameter) => parameter.name == name,
495 orElse: () => throw new StateError( 496 orElse: () => throw new StateError(
496 'Unable to resolve constructor parameter: $name')); 497 'Unable to resolve constructor parameter: $name'));
497 _push(identifier); 498 _push(identifier);
498 break; 499 break;
499 case UnlinkedExprOperation.ifNull: 500 case UnlinkedExprOperation.ifNull:
500 _pushBinary(TokenType.QUESTION_QUESTION); 501 _pushBinary(TokenType.QUESTION_QUESTION);
501 break; 502 break;
502 case UnlinkedExprOperation.assignToRef: 503 case UnlinkedExprOperation.assignToRef:
(...skipping 18 matching lines...) Expand all
521 List<Expression> arguments; 522 List<Expression> arguments;
522 { 523 {
523 int numNamedArgs = uc.ints[intPtr++]; 524 int numNamedArgs = uc.ints[intPtr++];
524 int numPositionalArgs = uc.ints[intPtr++]; 525 int numPositionalArgs = uc.ints[intPtr++];
525 int numArgs = numNamedArgs + numPositionalArgs; 526 int numArgs = numNamedArgs + numPositionalArgs;
526 arguments = _removeTopItems(numArgs); 527 arguments = _removeTopItems(numArgs);
527 // add names to the named arguments 528 // add names to the named arguments
528 for (int i = 0; i < numNamedArgs; i++) { 529 for (int i = 0; i < numNamedArgs; i++) {
529 String name = uc.strings[stringPtr++]; 530 String name = uc.strings[stringPtr++];
530 int index = numPositionalArgs + i; 531 int index = numPositionalArgs + i;
531 arguments[index] = AstFactory.namedExpression2(name, arguments[index]); 532 arguments[index] =
533 AstTestFactory.namedExpression2(name, arguments[index]);
532 } 534 }
533 } 535 }
534 return arguments; 536 return arguments;
535 } 537 }
536 538
537 /** 539 /**
538 * Build the identifier sequence (a single or prefixed identifier, or a 540 * Build the identifier sequence (a single or prefixed identifier, or a
539 * property access) corresponding to the given reference [info]. 541 * property access) corresponding to the given reference [info].
540 */ 542 */
541 Expression _buildIdentifierSequence(_ReferenceInfo info) { 543 Expression _buildIdentifierSequence(_ReferenceInfo info) {
542 Expression enclosing; 544 Expression enclosing;
543 if (info.enclosing != null) { 545 if (info.enclosing != null) {
544 enclosing = _buildIdentifierSequence(info.enclosing); 546 enclosing = _buildIdentifierSequence(info.enclosing);
545 } 547 }
546 Element element = info.element; 548 Element element = info.element;
547 if (element == null && info.name == 'length') { 549 if (element == null && info.name == 'length') {
548 element = _getStringLengthElement(); 550 element = _getStringLengthElement();
549 } 551 }
550 if (enclosing == null) { 552 if (enclosing == null) {
551 return AstFactory.identifier3(info.name)..staticElement = element; 553 return AstTestFactory.identifier3(info.name)..staticElement = element;
552 } 554 }
553 if (enclosing is SimpleIdentifier) { 555 if (enclosing is SimpleIdentifier) {
554 SimpleIdentifier identifier = AstFactory.identifier3(info.name) 556 SimpleIdentifier identifier = AstTestFactory.identifier3(info.name)
555 ..staticElement = element; 557 ..staticElement = element;
556 return AstFactory.identifier(enclosing, identifier); 558 return AstTestFactory.identifier(enclosing, identifier);
557 } 559 }
558 SimpleIdentifier property = AstFactory.identifier3(info.name) 560 SimpleIdentifier property = AstTestFactory.identifier3(info.name)
559 ..staticElement = element; 561 ..staticElement = element;
560 return AstFactory.propertyAccess(enclosing, property); 562 return AstTestFactory.propertyAccess(enclosing, property);
561 } 563 }
562 564
563 TypeName _buildTypeAst(DartType type) { 565 TypeName _buildTypeAst(DartType type) {
564 List<TypeName> argumentNodes; 566 List<TypeName> argumentNodes;
565 if (type is ParameterizedType) { 567 if (type is ParameterizedType) {
566 if (!resynthesizer.libraryResynthesizer.typesWithImplicitTypeArguments 568 if (!resynthesizer.libraryResynthesizer.typesWithImplicitTypeArguments
567 .contains(type)) { 569 .contains(type)) {
568 List<DartType> typeArguments = type.typeArguments; 570 List<DartType> typeArguments = type.typeArguments;
569 argumentNodes = typeArguments.every((a) => a.isDynamic) 571 argumentNodes = typeArguments.every((a) => a.isDynamic)
570 ? null 572 ? null
571 : typeArguments.map(_buildTypeAst).toList(); 573 : typeArguments.map(_buildTypeAst).toList();
572 } 574 }
573 } 575 }
574 TypeName node = AstFactory.typeName4(type.name, argumentNodes); 576 TypeName node = AstTestFactory.typeName4(type.name, argumentNodes);
575 node.type = type; 577 node.type = type;
576 (node.name as SimpleIdentifier).staticElement = type.element; 578 (node.name as SimpleIdentifier).staticElement = type.element;
577 return node; 579 return node;
578 } 580 }
579 581
580 PropertyAccessorElement _getStringLengthElement() => 582 PropertyAccessorElement _getStringLengthElement() =>
581 resynthesizer.typeProvider.stringType.getGetter('length'); 583 resynthesizer.typeProvider.stringType.getGetter('length');
582 584
583 InterpolationElement _newInterpolationElement(Expression expr) { 585 InterpolationElement _newInterpolationElement(Expression expr) {
584 if (expr is SimpleStringLiteral) { 586 if (expr is SimpleStringLiteral) {
(...skipping 19 matching lines...) Expand all
604 606
605 Expression _pop() => stack.removeLast(); 607 Expression _pop() => stack.removeLast();
606 608
607 void _push(Expression expr) { 609 void _push(Expression expr) {
608 stack.add(expr); 610 stack.add(expr);
609 } 611 }
610 612
611 void _pushBinary(TokenType operator) { 613 void _pushBinary(TokenType operator) {
612 Expression right = _pop(); 614 Expression right = _pop();
613 Expression left = _pop(); 615 Expression left = _pop();
614 _push(AstFactory.binaryExpression(left, operator, right)); 616 _push(AstTestFactory.binaryExpression(left, operator, right));
615 } 617 }
616 618
617 void _pushExtractProperty() { 619 void _pushExtractProperty() {
618 Expression target = _pop(); 620 Expression target = _pop();
619 String name = uc.strings[stringPtr++]; 621 String name = uc.strings[stringPtr++];
620 SimpleIdentifier propertyNode = AstFactory.identifier3(name); 622 SimpleIdentifier propertyNode = AstTestFactory.identifier3(name);
621 // Only String.length property access can be potentially resolved. 623 // Only String.length property access can be potentially resolved.
622 if (name == 'length') { 624 if (name == 'length') {
623 propertyNode.staticElement = _getStringLengthElement(); 625 propertyNode.staticElement = _getStringLengthElement();
624 } 626 }
625 _push(AstFactory.propertyAccess(target, propertyNode)); 627 _push(AstTestFactory.propertyAccess(target, propertyNode));
626 } 628 }
627 629
628 void _pushInstanceCreation() { 630 void _pushInstanceCreation() {
629 EntityRef ref = uc.references[refPtr++]; 631 EntityRef ref = uc.references[refPtr++];
630 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference); 632 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference);
631 // prepare ConstructorElement 633 // prepare ConstructorElement
632 TypeName typeNode; 634 TypeName typeNode;
633 String constructorName; 635 String constructorName;
634 ConstructorElement constructorElement; 636 ConstructorElement constructorElement;
635 if (info.element != null) { 637 if (info.element != null) {
636 if (info.element is ConstructorElement) { 638 if (info.element is ConstructorElement) {
637 constructorName = info.name; 639 constructorName = info.name;
638 } else if (info.element is ClassElement) { 640 } else if (info.element is ClassElement) {
639 constructorName = null; 641 constructorName = null;
640 } else { 642 } else {
641 throw new StateError('Unsupported element for invokeConstructor ' 643 throw new StateError('Unsupported element for invokeConstructor '
642 '${info.element?.runtimeType}'); 644 '${info.element?.runtimeType}');
643 } 645 }
644 InterfaceType definingType = resynthesizer._createConstructorDefiningType( 646 InterfaceType definingType = resynthesizer._createConstructorDefiningType(
645 context?.typeParameterContext, info, ref.typeArguments); 647 context?.typeParameterContext, info, ref.typeArguments);
646 constructorElement = 648 constructorElement =
647 resynthesizer._getConstructorForInfo(definingType, info); 649 resynthesizer._getConstructorForInfo(definingType, info);
648 typeNode = _buildTypeAst(definingType); 650 typeNode = _buildTypeAst(definingType);
649 } else { 651 } else {
650 if (info.enclosing != null) { 652 if (info.enclosing != null) {
651 if (info.enclosing.enclosing != null) { 653 if (info.enclosing.enclosing != null) {
652 PrefixedIdentifier typeName = AstFactory.identifier5( 654 PrefixedIdentifier typeName = AstTestFactory.identifier5(
653 info.enclosing.enclosing.name, info.enclosing.name); 655 info.enclosing.enclosing.name, info.enclosing.name);
654 typeName.prefix.staticElement = info.enclosing.enclosing.element; 656 typeName.prefix.staticElement = info.enclosing.enclosing.element;
655 typeName.identifier.staticElement = info.enclosing.element; 657 typeName.identifier.staticElement = info.enclosing.element;
656 typeName.identifier.staticType = info.enclosing.type; 658 typeName.identifier.staticType = info.enclosing.type;
657 typeNode = AstFactory.typeName3(typeName); 659 typeNode = AstTestFactory.typeName3(typeName);
658 typeNode.type = info.enclosing.type; 660 typeNode.type = info.enclosing.type;
659 constructorName = info.name; 661 constructorName = info.name;
660 } else if (info.enclosing.element != null) { 662 } else if (info.enclosing.element != null) {
661 SimpleIdentifier typeName = 663 SimpleIdentifier typeName =
662 AstFactory.identifier3(info.enclosing.name); 664 AstTestFactory.identifier3(info.enclosing.name);
663 typeName.staticElement = info.enclosing.element; 665 typeName.staticElement = info.enclosing.element;
664 typeName.staticType = info.enclosing.type; 666 typeName.staticType = info.enclosing.type;
665 typeNode = AstFactory.typeName3(typeName); 667 typeNode = AstTestFactory.typeName3(typeName);
666 typeNode.type = info.enclosing.type; 668 typeNode.type = info.enclosing.type;
667 constructorName = info.name; 669 constructorName = info.name;
668 } else { 670 } else {
669 typeNode = AstFactory.typeName3( 671 typeNode = AstTestFactory.typeName3(
670 AstFactory.identifier5(info.enclosing.name, info.name)); 672 AstTestFactory.identifier5(info.enclosing.name, info.name));
671 constructorName = null; 673 constructorName = null;
672 } 674 }
673 } else { 675 } else {
674 typeNode = AstFactory.typeName4(info.name); 676 typeNode = AstTestFactory.typeName4(info.name);
675 } 677 }
676 } 678 }
677 // prepare arguments 679 // prepare arguments
678 List<Expression> arguments = _buildArguments(); 680 List<Expression> arguments = _buildArguments();
679 // create ConstructorName 681 // create ConstructorName
680 ConstructorName constructorNode; 682 ConstructorName constructorNode;
681 if (constructorName != null) { 683 if (constructorName != null) {
682 constructorNode = AstFactory.constructorName(typeNode, constructorName); 684 constructorNode =
685 AstTestFactory.constructorName(typeNode, constructorName);
683 constructorNode.name.staticElement = constructorElement; 686 constructorNode.name.staticElement = constructorElement;
684 } else { 687 } else {
685 constructorNode = AstFactory.constructorName(typeNode, null); 688 constructorNode = AstTestFactory.constructorName(typeNode, null);
686 } 689 }
687 constructorNode.staticElement = constructorElement; 690 constructorNode.staticElement = constructorElement;
688 // create InstanceCreationExpression 691 // create InstanceCreationExpression
689 InstanceCreationExpression instanceCreation = AstFactory 692 InstanceCreationExpression instanceCreation = AstTestFactory
690 .instanceCreationExpression(Keyword.CONST, constructorNode, arguments); 693 .instanceCreationExpression(Keyword.CONST, constructorNode, arguments);
691 instanceCreation.staticElement = constructorElement; 694 instanceCreation.staticElement = constructorElement;
692 _push(instanceCreation); 695 _push(instanceCreation);
693 } 696 }
694 697
695 void _pushInvokeMethodRef() { 698 void _pushInvokeMethodRef() {
696 List<Expression> arguments = _buildArguments(); 699 List<Expression> arguments = _buildArguments();
697 EntityRef ref = uc.references[refPtr++]; 700 EntityRef ref = uc.references[refPtr++];
698 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference); 701 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference);
699 Expression node = _buildIdentifierSequence(info); 702 Expression node = _buildIdentifierSequence(info);
700 TypeArgumentList typeArguments; 703 TypeArgumentList typeArguments;
701 int numTypeArguments = uc.ints[intPtr++]; 704 int numTypeArguments = uc.ints[intPtr++];
702 if (numTypeArguments > 0) { 705 if (numTypeArguments > 0) {
703 List<TypeName> typeNames = new List<TypeName>(numTypeArguments); 706 List<TypeName> typeNames = new List<TypeName>(numTypeArguments);
704 for (int i = 0; i < numTypeArguments; i++) { 707 for (int i = 0; i < numTypeArguments; i++) {
705 typeNames[i] = _newTypeName(); 708 typeNames[i] = _newTypeName();
706 } 709 }
707 typeArguments = AstFactory.typeArgumentList(typeNames); 710 typeArguments = AstTestFactory.typeArgumentList(typeNames);
708 } 711 }
709 if (node is SimpleIdentifier) { 712 if (node is SimpleIdentifier) {
710 _push(new MethodInvocation( 713 _push(new MethodInvocation(
711 null, 714 null,
712 TokenFactory.tokenFromType(TokenType.PERIOD), 715 TokenFactory.tokenFromType(TokenType.PERIOD),
713 node, 716 node,
714 typeArguments, 717 typeArguments,
715 AstFactory.argumentList(arguments))); 718 AstTestFactory.argumentList(arguments)));
716 } else { 719 } else {
717 throw new UnimplementedError('For ${node?.runtimeType}: $node'); 720 throw new UnimplementedError('For ${node?.runtimeType}: $node');
718 } 721 }
719 } 722 }
720 723
721 void _pushList(TypeArgumentList typeArguments) { 724 void _pushList(TypeArgumentList typeArguments) {
722 int count = uc.ints[intPtr++]; 725 int count = uc.ints[intPtr++];
723 List<Expression> elements = <Expression>[]; 726 List<Expression> elements = <Expression>[];
724 for (int i = 0; i < count; i++) { 727 for (int i = 0; i < count; i++) {
725 elements.insert(0, _pop()); 728 elements.insert(0, _pop());
726 } 729 }
727 _push(AstFactory.listLiteral2(Keyword.CONST, typeArguments, elements)); 730 _push(AstTestFactory.listLiteral2(Keyword.CONST, typeArguments, elements));
728 } 731 }
729 732
730 void _pushMap(TypeArgumentList typeArguments) { 733 void _pushMap(TypeArgumentList typeArguments) {
731 int count = uc.ints[intPtr++]; 734 int count = uc.ints[intPtr++];
732 List<MapLiteralEntry> entries = <MapLiteralEntry>[]; 735 List<MapLiteralEntry> entries = <MapLiteralEntry>[];
733 for (int i = 0; i < count; i++) { 736 for (int i = 0; i < count; i++) {
734 Expression value = _pop(); 737 Expression value = _pop();
735 Expression key = _pop(); 738 Expression key = _pop();
736 entries.insert(0, AstFactory.mapLiteralEntry2(key, value)); 739 entries.insert(0, AstTestFactory.mapLiteralEntry2(key, value));
737 } 740 }
738 _push(AstFactory.mapLiteral(Keyword.CONST, typeArguments, entries)); 741 _push(AstTestFactory.mapLiteral(Keyword.CONST, typeArguments, entries));
739 } 742 }
740 743
741 void _pushPrefix(TokenType operator) { 744 void _pushPrefix(TokenType operator) {
742 Expression operand = _pop(); 745 Expression operand = _pop();
743 _push(AstFactory.prefixExpression(operator, operand)); 746 _push(AstTestFactory.prefixExpression(operator, operand));
744 } 747 }
745 748
746 void _pushReference() { 749 void _pushReference() {
747 EntityRef ref = uc.references[refPtr++]; 750 EntityRef ref = uc.references[refPtr++];
748 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference); 751 _ReferenceInfo info = resynthesizer.getReferenceInfo(ref.reference);
749 Expression node = _buildIdentifierSequence(info); 752 Expression node = _buildIdentifierSequence(info);
750 _push(node); 753 _push(node);
751 } 754 }
752 755
753 List<Expression> _removeTopItems(int count) { 756 List<Expression> _removeTopItems(int count) {
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 TypeProvider get typeProvider => summaryResynthesizer.typeProvider; 1513 TypeProvider get typeProvider => summaryResynthesizer.typeProvider;
1511 1514
1512 /** 1515 /**
1513 * Build [ElementAnnotationImpl] for the given [UnlinkedExpr]. 1516 * Build [ElementAnnotationImpl] for the given [UnlinkedExpr].
1514 */ 1517 */
1515 ElementAnnotationImpl buildAnnotation(ElementImpl context, UnlinkedExpr uc) { 1518 ElementAnnotationImpl buildAnnotation(ElementImpl context, UnlinkedExpr uc) {
1516 ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit); 1519 ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit);
1517 Expression constExpr = _buildConstExpression(context, uc); 1520 Expression constExpr = _buildConstExpression(context, uc);
1518 if (constExpr is Identifier) { 1521 if (constExpr is Identifier) {
1519 elementAnnotation.element = constExpr.staticElement; 1522 elementAnnotation.element = constExpr.staticElement;
1520 elementAnnotation.annotationAst = AstFactory.annotation(constExpr); 1523 elementAnnotation.annotationAst = AstTestFactory.annotation(constExpr);
1521 } else if (constExpr is InstanceCreationExpression) { 1524 } else if (constExpr is InstanceCreationExpression) {
1522 elementAnnotation.element = constExpr.staticElement; 1525 elementAnnotation.element = constExpr.staticElement;
1523 Identifier typeName = constExpr.constructorName.type.name; 1526 Identifier typeName = constExpr.constructorName.type.name;
1524 SimpleIdentifier constructorName = constExpr.constructorName.name; 1527 SimpleIdentifier constructorName = constExpr.constructorName.name;
1525 if (typeName is SimpleIdentifier && constructorName != null) { 1528 if (typeName is SimpleIdentifier && constructorName != null) {
1526 // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as 1529 // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as
1527 // a PrefixedIdentifier, we need to resynthesize it as one. 1530 // a PrefixedIdentifier, we need to resynthesize it as one.
1528 typeName = AstFactory.identifier(typeName, constructorName); 1531 typeName = AstTestFactory.identifier(typeName, constructorName);
1529 constructorName = null; 1532 constructorName = null;
1530 } 1533 }
1531 elementAnnotation.annotationAst = AstFactory.annotation2( 1534 elementAnnotation.annotationAst = AstTestFactory.annotation2(
1532 typeName, constructorName, constExpr.argumentList) 1535 typeName, constructorName, constExpr.argumentList)
1533 ..element = constExpr.staticElement; 1536 ..element = constExpr.staticElement;
1534 } else { 1537 } else {
1535 throw new StateError( 1538 throw new StateError(
1536 'Unexpected annotation type: ${constExpr.runtimeType}'); 1539 'Unexpected annotation type: ${constExpr.runtimeType}');
1537 } 1540 }
1538 return elementAnnotation; 1541 return elementAnnotation;
1539 } 1542 }
1540 1543
1541 /** 1544 /**
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 static String _getElementIdentifier(String name, ReferenceKind kind) { 1883 static String _getElementIdentifier(String name, ReferenceKind kind) {
1881 if (kind == ReferenceKind.topLevelPropertyAccessor || 1884 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1882 kind == ReferenceKind.propertyAccessor) { 1885 kind == ReferenceKind.propertyAccessor) {
1883 if (!name.endsWith('=')) { 1886 if (!name.endsWith('=')) {
1884 return name + '?'; 1887 return name + '?';
1885 } 1888 }
1886 } 1889 }
1887 return name; 1890 return name;
1888 } 1891 }
1889 } 1892 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/testing/test_type_provider.dart ('k') | pkg/analyzer/test/dart/ast/ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698