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

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

Issue 2985293002: Add optional FunctionType.positionalParameterNames and use them to resynthesize function-type forma… (Closed)
Patch Set: Created 3 years, 4 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) 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 8085 matching lines...) Expand 10 before | Expand all | Expand 10 after
8096 */ 8096 */
8097 void set parameters(List<ParameterElement> parameters) { 8097 void set parameters(List<ParameterElement> parameters) {
8098 for (ParameterElement parameter in parameters) { 8098 for (ParameterElement parameter in parameters) {
8099 (parameter as ParameterElementImpl).enclosingElement = this; 8099 (parameter as ParameterElementImpl).enclosingElement = this;
8100 } 8100 }
8101 this._parameters = parameters; 8101 this._parameters = parameters;
8102 } 8102 }
8103 8103
8104 @override 8104 @override
8105 DartType get type { 8105 DartType get type {
8106 if (_kernel != null) {
8107 return _type ??= enclosingUnit._kernelContext.getType(this, _kernel.type);
8108 }
8109 _resynthesizeTypeAndParameters(); 8106 _resynthesizeTypeAndParameters();
8110 return super.type; 8107 return super.type;
8111 } 8108 }
8112 8109
8113 @override 8110 @override
8114 TopLevelInferenceError get typeInferenceError { 8111 TopLevelInferenceError get typeInferenceError {
8115 if (_unlinkedParam != null) { 8112 if (_unlinkedParam != null) {
8116 return enclosingUnit.resynthesizerContext 8113 return enclosingUnit.resynthesizerContext
8117 .getTypeInferenceError(_unlinkedParam.inferredTypeSlot); 8114 .getTypeInferenceError(_unlinkedParam.inferredTypeSlot);
8118 } 8115 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
8210 void visitChildren(ElementVisitor visitor) { 8207 void visitChildren(ElementVisitor visitor) {
8211 super.visitChildren(visitor); 8208 super.visitChildren(visitor);
8212 safelyVisitChildren(parameters, visitor); 8209 safelyVisitChildren(parameters, visitor);
8213 } 8210 }
8214 8211
8215 /** 8212 /**
8216 * If this element is resynthesized, and its type and parameters have not 8213 * If this element is resynthesized, and its type and parameters have not
8217 * been build yet, build them and remember in the corresponding fields. 8214 * been build yet, build them and remember in the corresponding fields.
8218 */ 8215 */
8219 void _resynthesizeTypeAndParameters() { 8216 void _resynthesizeTypeAndParameters() {
8217 if (_kernel != null && _type == null) {
8218 kernel.DartType type = _kernel.type;
8219 _type = enclosingUnit._kernelContext.getType(this, type);
8220 if (type is kernel.FunctionType) {
8221 _parameters = new List<ParameterElement>(
8222 type.positionalParameters.length + type.namedParameters.length);
8223 int index = 0;
8224 for (int i = 0; i < type.positionalParameters.length; i++) {
8225 String name = i < type.positionalParameterNames.length
8226 ? type.positionalParameterNames[i]
8227 : null;
8228 _parameters[index++] = new ParameterElementImpl.forKernel(
8229 enclosingElement,
8230 new kernel.VariableDeclaration(name,
8231 type: type.positionalParameters[i]),
8232 i < type.requiredParameterCount
8233 ? ParameterKind.REQUIRED
8234 : ParameterKind.POSITIONAL);
8235 }
8236 for (int i = 0; i < type.namedParameters.length; i++) {
8237 _parameters[index++] = new ParameterElementImpl.forKernel(
8238 enclosingElement,
8239 new kernel.VariableDeclaration(type.namedParameters[i].name,
8240 type: type.namedParameters[i].type),
8241 ParameterKind.NAMED);
8242 }
8243 } else {
8244 _parameters = const <ParameterElement>[];
8245 }
8246 }
8220 if (_unlinkedParam != null && _declaredType == null && _type == null) { 8247 if (_unlinkedParam != null && _declaredType == null && _type == null) {
8221 if (_unlinkedParam.isFunctionTyped) { 8248 if (_unlinkedParam.isFunctionTyped) {
8222 CompilationUnitElementImpl enclosingUnit = this.enclosingUnit; 8249 CompilationUnitElementImpl enclosingUnit = this.enclosingUnit;
8223 FunctionElementImpl parameterTypeElement = 8250 FunctionElementImpl parameterTypeElement =
8224 new FunctionElementImpl_forFunctionTypedParameter( 8251 new FunctionElementImpl_forFunctionTypedParameter(
8225 enclosingUnit, this); 8252 enclosingUnit, this);
8226 if (!isSynthetic) { 8253 if (!isSynthetic) {
8227 parameterTypeElement.enclosingElement = this; 8254 parameterTypeElement.enclosingElement = this;
8228 } 8255 }
8229 List<ParameterElement> subParameters = ParameterElementImpl 8256 List<ParameterElement> subParameters = ParameterElementImpl
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after
9707 9734
9708 @override 9735 @override
9709 DartObject computeConstantValue() => null; 9736 DartObject computeConstantValue() => null;
9710 9737
9711 @override 9738 @override
9712 void visitChildren(ElementVisitor visitor) { 9739 void visitChildren(ElementVisitor visitor) {
9713 super.visitChildren(visitor); 9740 super.visitChildren(visitor);
9714 _initializer?.accept(visitor); 9741 _initializer?.accept(visitor);
9715 } 9742 }
9716 } 9743 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | pkg/kernel/lib/ast.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698