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

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

Issue 2023443003: Convert buildParameter() into a factory constructor. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 | pkg/analyzer/lib/src/summary/resynthesize.dart » ('j') | 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 6020 matching lines...) Expand 10 before | Expand all | Expand 10 after
6031 super.forNode(name); 6031 super.forNode(name);
6032 6032
6033 /** 6033 /**
6034 * Initialize using the given serialized information. 6034 * Initialize using the given serialized information.
6035 */ 6035 */
6036 ParameterElementImpl.forSerialized( 6036 ParameterElementImpl.forSerialized(
6037 this._unlinkedParam, ElementImpl enclosingElement) 6037 this._unlinkedParam, ElementImpl enclosingElement)
6038 : super.forSerialized(enclosingElement); 6038 : super.forSerialized(enclosingElement);
6039 6039
6040 /** 6040 /**
6041 * Initialize using the given serialized information.
6042 */
6043 factory ParameterElementImpl.forSerializedFactory(
6044 UnlinkedParam unlinkedParameter, ElementImpl enclosingElement,
6045 {bool synthetic: false}) {
6046 ParameterElementImpl element;
6047 if (unlinkedParameter.isInitializingFormal) {
6048 if (unlinkedParameter.kind == UnlinkedParamKind.required) {
6049 element = new FieldFormalParameterElementImpl.forSerialized(
6050 unlinkedParameter, enclosingElement);
6051 } else {
6052 element = new DefaultFieldFormalParameterElementImpl.forSerialized(
6053 unlinkedParameter, enclosingElement);
6054 }
6055 } else {
6056 if (unlinkedParameter.kind == UnlinkedParamKind.required) {
6057 element = new ParameterElementImpl.forSerialized(
6058 unlinkedParameter, enclosingElement);
6059 } else {
6060 element = new DefaultParameterElementImpl.forSerialized(
6061 unlinkedParameter, enclosingElement);
6062 }
6063 }
6064 element.synthetic = synthetic;
6065 return element;
6066 }
6067
6068 /**
6041 * Creates a synthetic parameter with [name], [type] and [kind]. 6069 * Creates a synthetic parameter with [name], [type] and [kind].
6042 */ 6070 */
6043 factory ParameterElementImpl.synthetic( 6071 factory ParameterElementImpl.synthetic(
6044 String name, DartType type, ParameterKind kind) { 6072 String name, DartType type, ParameterKind kind) {
6045 ParameterElementImpl element = new ParameterElementImpl(name, -1); 6073 ParameterElementImpl element = new ParameterElementImpl(name, -1);
6046 element.type = type; 6074 element.type = type;
6047 element.synthetic = true; 6075 element.synthetic = true;
6048 element.parameterKind = kind; 6076 element.parameterKind = kind;
6049 return element; 6077 return element;
6050 } 6078 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
6201 } 6229 }
6202 return _parameterKind; 6230 return _parameterKind;
6203 } 6231 }
6204 6232
6205 void set parameterKind(ParameterKind parameterKind) { 6233 void set parameterKind(ParameterKind parameterKind) {
6206 assert(_unlinkedParam == null); 6234 assert(_unlinkedParam == null);
6207 _parameterKind = parameterKind; 6235 _parameterKind = parameterKind;
6208 } 6236 }
6209 6237
6210 @override 6238 @override
6211 List<ParameterElement> get parameters => _parameters; 6239 List<ParameterElement> get parameters {
6240 if (_unlinkedParam != null) {
6241 type; // _parameters is set during computing 'type'
Paul Berry 2016/05/27 21:51:20 Even with the comment, this code looks very strang
scheglov 2016/05/27 21:57:04 Done.
6242 }
6243 return _parameters;
6244 }
6212 6245
6213 /** 6246 /**
6214 * Set the parameters defined by this executable element to the given 6247 * Set the parameters defined by this executable element to the given
6215 * [parameters]. 6248 * [parameters].
6216 */ 6249 */
6217 void set parameters(List<ParameterElement> parameters) { 6250 void set parameters(List<ParameterElement> parameters) {
6218 for (ParameterElement parameter in parameters) { 6251 for (ParameterElement parameter in parameters) {
6219 (parameter as ParameterElementImpl).enclosingElement = this; 6252 (parameter as ParameterElementImpl).enclosingElement = this;
6220 } 6253 }
6221 this._parameters = parameters; 6254 this._parameters = parameters;
6222 } 6255 }
6223 6256
6224 @override 6257 @override
6225 DartType get type { 6258 DartType get type {
6226 if (_unlinkedParam != null && _type == null) { 6259 if (_unlinkedParam != null && _type == null) {
6227 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( 6260 if (_unlinkedParam.isFunctionTyped) {
6228 _unlinkedParam.inferredTypeSlot, typeParameterContext) ?? 6261 CompilationUnitElementImpl enclosingUnit = this.enclosingUnit;
6229 enclosingUnit.resynthesizerContext 6262 FunctionElementImpl parameterTypeElement =
6230 .resolveTypeRef(_unlinkedParam.type, typeParameterContext); 6263 new FunctionElementImpl_forFunctionTypedParameter(
6264 enclosingUnit, this);
6265 if (!isSynthetic) {
6266 parameterTypeElement.enclosingElement = this;
6267 }
6268 List<ParameterElement> subParameters = _unlinkedParam.parameters
6269 .map((UnlinkedParam p) =>
6270 new ParameterElementImpl.forSerializedFactory(p, this,
6271 synthetic: isSynthetic))
6272 .toList(growable: false);
6273 if (isSynthetic) {
6274 parameterTypeElement.parameters = subParameters;
6275 } else {
6276 _parameters = subParameters;
6277 parameterTypeElement.shareParameters(subParameters);
6278 }
6279 parameterTypeElement.returnType = enclosingUnit.resynthesizerContext
6280 .resolveTypeRef(_unlinkedParam.type, typeParameterContext);
6281 FunctionTypeImpl parameterType =
6282 new FunctionTypeImpl.elementWithNameAndArgs(parameterTypeElement,
6283 null, typeParameterContext.allTypeParameterTypes, false);
6284 parameterTypeElement.type = parameterType;
6285 _type = parameterType;
6286 } else {
6287 _type = enclosingUnit.resynthesizerContext.resolveLinkedType(
6288 _unlinkedParam.inferredTypeSlot, typeParameterContext) ??
6289 enclosingUnit.resynthesizerContext
6290 .resolveTypeRef(_unlinkedParam.type, typeParameterContext);
6291 }
6231 } 6292 }
6232 return super.type; 6293 return super.type;
6233 } 6294 }
6234 6295
6235 @override 6296 @override
6236 List<TypeParameterElement> get typeParameters => _typeParameters; 6297 List<TypeParameterElement> get typeParameters => _typeParameters;
6237 6298
6238 /** 6299 /**
6239 * Set the type parameters defined by this parameter element to the given 6300 * Set the type parameters defined by this parameter element to the given
6240 * [typeParameters]. 6301 * [typeParameters].
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
7473 7534
7474 @override 7535 @override
7475 void visitElement(Element element) { 7536 void visitElement(Element element) {
7476 int offset = element.nameOffset; 7537 int offset = element.nameOffset;
7477 if (offset != -1) { 7538 if (offset != -1) {
7478 map[offset] = element; 7539 map[offset] = element;
7479 } 7540 }
7480 super.visitElement(element); 7541 super.visitElement(element);
7481 } 7542 }
7482 } 7543 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698