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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2829843002: MethodElementImpl.getReifiedType() should always create new parameter elements. (Closed)
Patch Set: Created 3 years, 8 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 | 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.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 6643 matching lines...) Expand 10 before | Expand all | Expand 10 after
6654 buffer.write(displayName); 6654 buffer.write(displayName);
6655 super.appendTo(buffer); 6655 super.appendTo(buffer);
6656 } 6656 }
6657 6657
6658 @override 6658 @override
6659 MethodDeclaration computeNode() => 6659 MethodDeclaration computeNode() =>
6660 getNodeMatching((node) => node is MethodDeclaration); 6660 getNodeMatching((node) => node is MethodDeclaration);
6661 6661
6662 @override 6662 @override
6663 FunctionType getReifiedType(DartType objectType) { 6663 FunctionType getReifiedType(DartType objectType) {
6664 // Collect the covariant parameters. Do this first so we don't allocate 6664 // Check whether we have any covariant parameters.
6665 // anything in the common case where there are none. 6665 // Usually we don't, so we can use the same type.
6666 Set<String> covariantNames; 6666 bool hasCovariant = false;
6667 for (ParameterElement parameter in parameters) { 6667 for (ParameterElement parameter in parameters) {
6668 if (parameter.isCovariant) { 6668 if (parameter.isCovariant) {
6669 covariantNames ??= new Set(); 6669 hasCovariant = true;
6670 covariantNames.add(parameter.name); 6670 break;
6671 } 6671 }
6672 } 6672 }
6673 6673
6674 if (covariantNames == null) return type; 6674 if (!hasCovariant) {
6675 return type;
6676 }
6675 6677
6676 List<ParameterElement> covariantParameters = parameters.map((parameter) { 6678 List<ParameterElement> covariantParameters = parameters.map((parameter) {
6677 if (!covariantNames.contains(parameter.name)) { 6679 DartType type = parameter.isCovariant ? objectType : parameter.type;
6678 return parameter;
6679 }
6680
6681 return new ParameterElementImpl.synthetic( 6680 return new ParameterElementImpl.synthetic(
6682 parameter.name, objectType, parameter.parameterKind); 6681 parameter.name, objectType, parameter.parameterKind);
6683 }).toList(); 6682 }).toList();
6684 6683
6685 return new FunctionElementImpl.synthetic(covariantParameters, returnType) 6684 return new FunctionElementImpl.synthetic(covariantParameters, returnType)
6686 .type; 6685 .type;
6687 } 6686 }
6688 } 6687 }
6689 6688
6690 /** 6689 /**
(...skipping 2409 matching lines...) Expand 10 before | Expand all | Expand 10 after
9100 9099
9101 @override 9100 @override
9102 void visitElement(Element element) { 9101 void visitElement(Element element) {
9103 int offset = element.nameOffset; 9102 int offset = element.nameOffset;
9104 if (offset != -1) { 9103 if (offset != -1) {
9105 map[offset] = element; 9104 map[offset] = element;
9106 } 9105 }
9107 super.visitElement(element); 9106 super.visitElement(element);
9108 } 9107 }
9109 } 9108 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698