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

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

Issue 1683813005: Fix summarization of generic redirecting constructors (again). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
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/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 int numArgs = numNamedArgs + numPositionalArgs; 523 int numArgs = numNamedArgs + numPositionalArgs;
524 arguments = _removeTopItems(numArgs); 524 arguments = _removeTopItems(numArgs);
525 // add names to the named arguments 525 // add names to the named arguments
526 for (int i = 0; i < numNamedArgs; i++) { 526 for (int i = 0; i < numNamedArgs; i++) {
527 String name = uc.strings[stringPtr++]; 527 String name = uc.strings[stringPtr++];
528 int index = numPositionalArgs + i; 528 int index = numPositionalArgs + i;
529 arguments[index] = AstFactory.namedExpression2(name, arguments[index]); 529 arguments[index] = AstFactory.namedExpression2(name, arguments[index]);
530 } 530 }
531 } 531 }
532 // create TypeName 532 // create TypeName
533 TypeName typeNode = _buildTypeAst(constructorElement.definingType); 533 TypeName typeNode = _buildTypeAst(constructorElement._definingType);
534 // create ConstructorName 534 // create ConstructorName
535 ConstructorName constructorNode; 535 ConstructorName constructorNode;
536 if (constructorName != null) { 536 if (constructorName != null) {
537 constructorNode = AstFactory.constructorName(typeNode, constructorName); 537 constructorNode = AstFactory.constructorName(typeNode, constructorName);
538 constructorNode.name.staticElement = constructorElement; 538 constructorNode.name.staticElement = constructorElement;
539 } else { 539 } else {
540 constructorNode = AstFactory.constructorName(typeNode, null); 540 constructorNode = AstFactory.constructorName(typeNode, null);
541 } 541 }
542 constructorNode.staticElement = constructorElement; 542 constructorNode.staticElement = constructorElement;
543 // create InstanceCreationExpression 543 // create InstanceCreationExpression
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 int end = stack.length; 577 int end = stack.length;
578 List<Expression> items = stack.getRange(start, end).toList(); 578 List<Expression> items = stack.getRange(start, end).toList();
579 stack.removeRange(start, end); 579 stack.removeRange(start, end);
580 return items; 580 return items;
581 } 581 }
582 } 582 }
583 583
584 /** 584 /**
585 * The constructor element that has been resynthesized from a summary. The 585 * The constructor element that has been resynthesized from a summary. The
586 * actual element won't be constructed until it is requested. But properties 586 * actual element won't be constructed until it is requested. But properties
587 * [definingType], [displayName], [enclosingElement] and [name] can be used 587 * [_definingType], [displayName], [enclosingElement] and [name] can be used
scheglov 2016/02/10 20:37:53 Maybe we should exclude "_definingType" from the l
Paul Berry 2016/02/10 20:54:36 Done.
588 * without creating the actual element. 588 * without creating the actual element.
589 */ 589 */
590 class _DeferredConstructorElement extends ConstructorElementHandle { 590 class _DeferredConstructorElement extends ConstructorElementHandle {
591 final InterfaceType definingType; 591 /**
592 * The type defining this constructor element. If [_isMember] is `false`,
593 * then the type parameters of [_definingType] are not guaranteed to be
594 * valid.
595 */
596 final InterfaceType _definingType;
597
598 /**
599 * The constructor name.
600 */
592 final String name; 601 final String name;
593 602
603 /**
604 * Indicates whether the deferred element is a [ConstructorMember] or simply
605 * a [ConstructorElement].
606 */
607 final bool _isMember;
608
594 factory _DeferredConstructorElement(InterfaceType definingType, String name) { 609 factory _DeferredConstructorElement(InterfaceType definingType, String name) {
595 List<String> components = definingType.element.location.components.toList(); 610 List<String> components = definingType.element.location.components.toList();
596 components.add(name); 611 components.add(name);
597 ElementLocationImpl location = new ElementLocationImpl.con3(components); 612 ElementLocationImpl location = new ElementLocationImpl.con3(components);
598 return new _DeferredConstructorElement._(definingType, name, location); 613 return new _DeferredConstructorElement._(
614 definingType, name, location, true);
599 } 615 }
600 616
601 _DeferredConstructorElement._( 617 _DeferredConstructorElement._(
602 this.definingType, this.name, ElementLocation location) 618 this._definingType, this.name, ElementLocation location, this._isMember)
603 : super(null, location); 619 : super(null, location);
604 620
605 @override 621 @override
606 Element get actualElement { 622 Element get actualElement {
607 ConstructorElement element = enclosingElement.getNamedConstructor(name); 623 ConstructorElement element = enclosingElement.getNamedConstructor(name);
608 return new ConstructorMember(element, definingType); 624 if (_isMember && _definingType.typeArguments.isNotEmpty) {
625 return new ConstructorMember(element, _definingType);
626 } else {
627 return element;
628 }
609 } 629 }
610 630
611 @override 631 @override
612 AnalysisContext get context => definingType.element.context; 632 AnalysisContext get context => _definingType.element.context;
613 633
614 @override 634 @override
615 String get displayName => name; 635 String get displayName => name;
616 636
617 @override 637 @override
618 ClassElement get enclosingElement { 638 ClassElement get enclosingElement {
619 return definingType.element; 639 return _definingType.element;
620 } 640 }
621 } 641 }
622 642
623 /** 643 /**
624 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the 644 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the
625 * elements in a single library from that library's summary. 645 * elements in a single library from that library's summary.
626 */ 646 */
627 class _LibraryResynthesizer { 647 class _LibraryResynthesizer {
628 /** 648 /**
629 * The [SummaryResynthesizer] which is being used to obtain summaries. 649 * The [SummaryResynthesizer] which is being used to obtain summaries.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 redirectedConstructor.typeArguments); 946 redirectedConstructor.typeArguments);
927 } else { 947 } else {
928 List<String> locationComponents = 948 List<String> locationComponents =
929 currentCompilationUnit.location.components.toList(); 949 currentCompilationUnit.location.components.toList();
930 locationComponents.add(classType.name); 950 locationComponents.add(classType.name);
931 locationComponents.add(serializedExecutable.redirectedConstructorName); 951 locationComponents.add(serializedExecutable.redirectedConstructorName);
932 currentConstructor.redirectedConstructor = 952 currentConstructor.redirectedConstructor =
933 new _DeferredConstructorElement._( 953 new _DeferredConstructorElement._(
934 classType, 954 classType,
935 serializedExecutable.redirectedConstructorName, 955 serializedExecutable.redirectedConstructorName,
936 new ElementLocationImpl.con3(locationComponents)); 956 new ElementLocationImpl.con3(locationComponents),
957 false);
937 } 958 }
938 } 959 }
939 holder.addConstructor(currentConstructor); 960 holder.addConstructor(currentConstructor);
940 currentConstructor = null; 961 currentConstructor = null;
941 } 962 }
942 963
943 /** 964 /**
944 * Build the documentation for the given [element]. Does nothing if 965 * Build the documentation for the given [element]. Does nothing if
945 * [serializedDocumentationComment] is `null`. 966 * [serializedDocumentationComment] is `null`.
946 */ 967 */
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 } 2059 }
2039 : () => this.element; 2060 : () => this.element;
2040 // TODO(paulberry): Is it a bug that we have to pass `false` for 2061 // TODO(paulberry): Is it a bug that we have to pass `false` for
2041 // isInstantiated? 2062 // isInstantiated?
2042 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 2063 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
2043 } else { 2064 } else {
2044 return null; 2065 return null;
2045 } 2066 }
2046 } 2067 }
2047 } 2068 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698