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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.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
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';
(...skipping 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 UnlinkedExecutable serializedExecutable) { 2093 UnlinkedExecutable serializedExecutable) {
2094 executableElement.typeParameters = 2094 executableElement.typeParameters =
2095 buildTypeParameters(serializedExecutable.typeParameters); 2095 buildTypeParameters(serializedExecutable.typeParameters);
2096 { 2096 {
2097 List<UnlinkedParam> unlinkedParameters = serializedExecutable.parameters; 2097 List<UnlinkedParam> unlinkedParameters = serializedExecutable.parameters;
2098 int length = unlinkedParameters.length; 2098 int length = unlinkedParameters.length;
2099 if (length != 0) { 2099 if (length != 0) {
2100 List<ParameterElementImpl> parameters = 2100 List<ParameterElementImpl> parameters =
2101 new List<ParameterElementImpl>(length); 2101 new List<ParameterElementImpl>(length);
2102 for (int i = 0; i < length; i++) { 2102 for (int i = 0; i < length; i++) {
2103 parameters[i] = 2103 parameters[i] = new ParameterElementImpl.forSerializedFactory(
2104 buildParameter(unlinkedParameters[i], executableElement); 2104 unlinkedParameters[i], executableElement);
2105 } 2105 }
2106 executableElement.parameters = parameters; 2106 executableElement.parameters = parameters;
2107 } 2107 }
2108 } 2108 }
2109 { 2109 {
2110 List<UnlinkedExecutable> unlinkedFunctions = 2110 List<UnlinkedExecutable> unlinkedFunctions =
2111 serializedExecutable.localFunctions; 2111 serializedExecutable.localFunctions;
2112 int length = unlinkedFunctions.length; 2112 int length = unlinkedFunctions.length;
2113 if (length != 0) { 2113 if (length != 0) {
2114 List<FunctionElementImpl> localFunctions = 2114 List<FunctionElementImpl> localFunctions =
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 * Resynthesize a [LabelElement]. 2231 * Resynthesize a [LabelElement].
2232 */ 2232 */
2233 LabelElement buildLocalLabel(UnlinkedLabel serializedLabel) { 2233 LabelElement buildLocalLabel(UnlinkedLabel serializedLabel) {
2234 return new LabelElementImpl( 2234 return new LabelElementImpl(
2235 serializedLabel.name, 2235 serializedLabel.name,
2236 serializedLabel.nameOffset, 2236 serializedLabel.nameOffset,
2237 serializedLabel.isOnSwitchStatement, 2237 serializedLabel.isOnSwitchStatement,
2238 serializedLabel.isOnSwitchMember); 2238 serializedLabel.isOnSwitchMember);
2239 } 2239 }
2240 2240
2241 /**
2242 * Resynthesize a [ParameterElement].
2243 */
2244 ParameterElement buildParameter(
2245 UnlinkedParam serializedParameter, ElementImpl enclosingElement,
2246 {bool synthetic: false}) {
2247 ParameterElementImpl parameterElement;
2248 if (serializedParameter.isInitializingFormal) {
2249 if (serializedParameter.kind == UnlinkedParamKind.required) {
2250 parameterElement = new FieldFormalParameterElementImpl.forSerialized(
2251 serializedParameter, enclosingElement);
2252 } else {
2253 parameterElement =
2254 new DefaultFieldFormalParameterElementImpl.forSerialized(
2255 serializedParameter, enclosingElement);
2256 }
2257 } else {
2258 if (serializedParameter.kind == UnlinkedParamKind.required) {
2259 parameterElement = new ParameterElementImpl.forSerialized(
2260 serializedParameter, enclosingElement);
2261 } else {
2262 parameterElement = new DefaultParameterElementImpl.forSerialized(
2263 serializedParameter, enclosingElement);
2264 }
2265 }
2266 parameterElement.synthetic = synthetic;
2267 if (serializedParameter.isFunctionTyped) {
2268 FunctionElementImpl parameterTypeElement =
2269 new FunctionElementImpl_forFunctionTypedParameter(
2270 unit, parameterElement);
2271 if (!synthetic) {
2272 parameterTypeElement.enclosingElement = parameterElement;
2273 }
2274 List<ParameterElement> subParameters = serializedParameter.parameters
2275 .map((UnlinkedParam p) =>
2276 buildParameter(p, parameterTypeElement, synthetic: synthetic))
2277 .toList();
2278 if (synthetic) {
2279 parameterTypeElement.parameters = subParameters;
2280 } else {
2281 parameterElement.parameters = subParameters;
2282 parameterTypeElement.shareParameters(subParameters);
2283 }
2284 parameterTypeElement.returnType =
2285 buildType(serializedParameter.type, _currentTypeParameterizedElement);
2286 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
2287 parameterTypeElement, null, getCurrentTypeArguments(), false);
2288 parameterTypeElement.type = parameterElement.type;
2289 }
2290 return parameterElement;
2291 }
2292
2293 List<FunctionElementImpl> buildTopLevelFunctions() { 2241 List<FunctionElementImpl> buildTopLevelFunctions() {
2294 List<FunctionElementImpl> functions = <FunctionElementImpl>[]; 2242 List<FunctionElementImpl> functions = <FunctionElementImpl>[];
2295 List<UnlinkedExecutable> executables = unlinkedUnit.executables; 2243 List<UnlinkedExecutable> executables = unlinkedUnit.executables;
2296 for (UnlinkedExecutable unlinkedExecutable in executables) { 2244 for (UnlinkedExecutable unlinkedExecutable in executables) {
2297 if (unlinkedExecutable.kind == UnlinkedExecutableKind.functionOrMethod) { 2245 if (unlinkedExecutable.kind == UnlinkedExecutableKind.functionOrMethod) {
2298 FunctionElementImpl function = 2246 FunctionElementImpl function =
2299 new FunctionElementImpl.forSerialized(unlinkedExecutable, unit); 2247 new FunctionElementImpl.forSerialized(unlinkedExecutable, unit);
2300 buildExecutableCommonParts(function, unlinkedExecutable); 2248 buildExecutableCommonParts(function, unlinkedExecutable);
2301 functions.add(function); 2249 functions.add(function);
2302 } 2250 }
(...skipping 17 matching lines...) Expand all
2320 return DynamicTypeImpl.instance; 2268 return DynamicTypeImpl.instance;
2321 } 2269 }
2322 } 2270 }
2323 if (type.paramReference != 0) { 2271 if (type.paramReference != 0) {
2324 return typeParameterContext.getTypeParameterType(type.paramReference); 2272 return typeParameterContext.getTypeParameterType(type.paramReference);
2325 } else if (type.syntheticReturnType != null) { 2273 } else if (type.syntheticReturnType != null) {
2326 FunctionElementImpl element = 2274 FunctionElementImpl element =
2327 new FunctionElementImpl_forLUB(unit, typeParameterContext); 2275 new FunctionElementImpl_forLUB(unit, typeParameterContext);
2328 element.parameters = type.syntheticParams 2276 element.parameters = type.syntheticParams
2329 .map((UnlinkedParam param) => 2277 .map((UnlinkedParam param) =>
2330 buildParameter(param, element, synthetic: true)) 2278 new ParameterElementImpl.forSerializedFactory(param, element,
2279 synthetic: true))
2331 .toList(); 2280 .toList();
2332 element.returnType = 2281 element.returnType =
2333 buildType(type.syntheticReturnType, typeParameterContext); 2282 buildType(type.syntheticReturnType, typeParameterContext);
2334 FunctionTypeImpl result = new FunctionTypeImpl.elementWithNameAndArgs( 2283 FunctionTypeImpl result = new FunctionTypeImpl.elementWithNameAndArgs(
2335 element, null, null, false); 2284 element, null, null, false);
2336 element.type = result; 2285 element.type = result;
2337 return result; 2286 return result;
2338 } else { 2287 } else {
2339 DartType getTypeArgument(int i) { 2288 DartType getTypeArgument(int i) {
2340 if (i < type.typeArguments.length) { 2289 if (i < type.typeArguments.length) {
(...skipping 14 matching lines...) Expand all
2355 /** 2304 /**
2356 * Resynthesize a [FunctionTypeAliasElement] and place it in the 2305 * Resynthesize a [FunctionTypeAliasElement] and place it in the
2357 * [unitHolder]. 2306 * [unitHolder].
2358 */ 2307 */
2359 void buildTypedef(UnlinkedTypedef serializedTypedef) { 2308 void buildTypedef(UnlinkedTypedef serializedTypedef) {
2360 FunctionTypeAliasElementImpl functionTypeAliasElement = 2309 FunctionTypeAliasElementImpl functionTypeAliasElement =
2361 new FunctionTypeAliasElementImpl.forSerialized(serializedTypedef, unit); 2310 new FunctionTypeAliasElementImpl.forSerialized(serializedTypedef, unit);
2362 // TODO(scheglov) remove this after delaying parameters and their types 2311 // TODO(scheglov) remove this after delaying parameters and their types
2363 currentTypeParameters.add(functionTypeAliasElement.typeParameters); 2312 currentTypeParameters.add(functionTypeAliasElement.typeParameters);
2364 functionTypeAliasElement.parameters = serializedTypedef.parameters 2313 functionTypeAliasElement.parameters = serializedTypedef.parameters
2365 .map((p) => buildParameter(p, functionTypeAliasElement)) 2314 .map((p) => new ParameterElementImpl.forSerializedFactory(
2315 p, functionTypeAliasElement))
2366 .toList(); 2316 .toList();
2367 unitHolder.addTypeAlias(functionTypeAliasElement); 2317 unitHolder.addTypeAlias(functionTypeAliasElement);
2368 // TODO(scheglov) remove this after delaying parameters and their types 2318 // TODO(scheglov) remove this after delaying parameters and their types
2369 currentTypeParameters.removeLast(); 2319 currentTypeParameters.removeLast();
2370 assert(currentTypeParameters.isEmpty); 2320 assert(currentTypeParameters.isEmpty);
2371 } 2321 }
2372 2322
2373 /** 2323 /**
2374 * Resynthesize a [TypeParameterElement], handling all parts of its except 2324 * Resynthesize a [TypeParameterElement], handling all parts of its except
2375 * its bound. 2325 * its bound.
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 static String _getElementIdentifier(String name, ReferenceKind kind) { 2748 static String _getElementIdentifier(String name, ReferenceKind kind) {
2799 if (kind == ReferenceKind.topLevelPropertyAccessor || 2749 if (kind == ReferenceKind.topLevelPropertyAccessor ||
2800 kind == ReferenceKind.propertyAccessor) { 2750 kind == ReferenceKind.propertyAccessor) {
2801 if (!name.endsWith('=')) { 2751 if (!name.endsWith('=')) {
2802 return name + '?'; 2752 return name + '?';
2803 } 2753 }
2804 } 2754 }
2805 return name; 2755 return name;
2806 } 2756 }
2807 } 2757 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698