| OLD | NEW |
| 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 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2308 * | 2308 * |
| 2309 * For the special types `dynamic` and `void`, [specialType] should point to | 2309 * For the special types `dynamic` and `void`, [specialType] should point to |
| 2310 * the type itself. Otherwise, pass `null` and the type will be computed | 2310 * the type itself. Otherwise, pass `null` and the type will be computed |
| 2311 * when appropriate. | 2311 * when appropriate. |
| 2312 */ | 2312 */ |
| 2313 _ReferenceInfo(this.enclosing, this.name, this.element, DartType specialType, | 2313 _ReferenceInfo(this.enclosing, this.name, this.element, DartType specialType, |
| 2314 this.numTypeParameters) { | 2314 this.numTypeParameters) { |
| 2315 if (specialType != null) { | 2315 if (specialType != null) { |
| 2316 type = specialType; | 2316 type = specialType; |
| 2317 } else { | 2317 } else { |
| 2318 type = _buildType((_) => DynamicTypeImpl.instance, null); | 2318 type = _buildType((_) => DynamicTypeImpl.instance, const []); |
| 2319 } | 2319 } |
| 2320 } | 2320 } |
| 2321 | 2321 |
| 2322 /** | 2322 /** |
| 2323 * Build a [DartType] corresponding to the result of applying some type | 2323 * Build a [DartType] corresponding to the result of applying some type |
| 2324 * arguments to the entity referred to by this [_ReferenceInfo]. The type | 2324 * arguments to the entity referred to by this [_ReferenceInfo]. The type |
| 2325 * arguments are retrieved by calling [getTypeArgument]. | 2325 * arguments are retrieved by calling [getTypeArgument]. |
| 2326 * | 2326 * |
| 2327 * If [implicitFunctionTypeIndices] is not empty, a [DartType] should be | 2327 * If [implicitFunctionTypeIndices] is not empty, a [DartType] should be |
| 2328 * created which refers to a function type implicitly defined by one of the | 2328 * created which refers to a function type implicitly defined by one of the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2351 * it with type arguments returned by [getTypeArgument]. Otherwise return | 2351 * it with type arguments returned by [getTypeArgument]. Otherwise return |
| 2352 * `null`. | 2352 * `null`. |
| 2353 * | 2353 * |
| 2354 * If [implicitFunctionTypeIndices] is not null, a [DartType] should be | 2354 * If [implicitFunctionTypeIndices] is not null, a [DartType] should be |
| 2355 * created which refers to a function type implicitly defined by one of the | 2355 * created which refers to a function type implicitly defined by one of the |
| 2356 * element's parameters. [implicitFunctionTypeIndices] is interpreted as in | 2356 * element's parameters. [implicitFunctionTypeIndices] is interpreted as in |
| 2357 * [EntityRef.implicitFunctionTypeIndices]. | 2357 * [EntityRef.implicitFunctionTypeIndices]. |
| 2358 */ | 2358 */ |
| 2359 DartType _buildType( | 2359 DartType _buildType( |
| 2360 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { | 2360 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { |
| 2361 List<DartType> typeArguments = const <DartType>[]; | |
| 2362 if (numTypeParameters != 0) { | |
| 2363 typeArguments = <DartType>[]; | |
| 2364 for (int i = 0; i < numTypeParameters; i++) { | |
| 2365 typeArguments.add(getTypeArgument(i)); | |
| 2366 } | |
| 2367 } | |
| 2368 ElementHandle element = this.element; // To allow type promotion | 2361 ElementHandle element = this.element; // To allow type promotion |
| 2369 if (element is ClassElementHandle) { | 2362 if (element is ClassElementHandle) { |
| 2370 return new InterfaceTypeImpl.elementWithNameAndArgs( | 2363 return new InterfaceTypeImpl.elementWithNameAndArgs(element, name, |
| 2371 element, name, typeArguments); | 2364 _buildTypeArguments(numTypeParameters, getTypeArgument)); |
| 2372 } else if (element is FunctionTypeAliasElementHandle) { | 2365 } else if (element is FunctionTypeAliasElementHandle) { |
| 2373 return new FunctionTypeImpl.elementWithNameAndArgs( | 2366 return new FunctionTypeImpl.elementWithNameAndArgs( |
| 2374 element, name, typeArguments, typeArguments.isNotEmpty); | 2367 element, |
| 2368 name, |
| 2369 _buildTypeArguments(numTypeParameters, getTypeArgument), |
| 2370 numTypeParameters != 0); |
| 2375 } else if (element is FunctionTypedElement) { | 2371 } else if (element is FunctionTypedElement) { |
| 2376 FunctionTypedElementComputer computer = | 2372 int numTypeArguments; |
| 2377 implicitFunctionTypeIndices != null | 2373 FunctionTypedElementComputer computer; |
| 2378 ? () { | 2374 if (implicitFunctionTypeIndices.isNotEmpty) { |
| 2379 FunctionTypedElement element = this.element; | 2375 numTypeArguments = numTypeParameters; |
| 2380 for (int index in implicitFunctionTypeIndices) { | 2376 computer = () { |
| 2381 element = element.parameters[index].type.element; | 2377 FunctionTypedElement element = this.element; |
| 2382 } | 2378 for (int index in implicitFunctionTypeIndices) { |
| 2383 return element; | 2379 element = element.parameters[index].type.element; |
| 2384 } | 2380 } |
| 2385 : () => this.element; | 2381 return element; |
| 2382 }; |
| 2383 } else { |
| 2384 // For a type that refers to a generic executable, the type arguments ar
e |
| 2385 // not supposed to include the arguments to the executable itself. |
| 2386 numTypeArguments = enclosing == null ? 0 : enclosing.numTypeParameters; |
| 2387 computer = () => this.element; |
| 2388 } |
| 2386 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2389 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2387 // isInstantiated? | 2390 // isInstantiated? |
| 2388 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2391 return new DeferredFunctionTypeImpl(computer, null, |
| 2392 _buildTypeArguments(numTypeArguments, getTypeArgument), false); |
| 2389 } else { | 2393 } else { |
| 2390 return null; | 2394 return null; |
| 2391 } | 2395 } |
| 2392 } | 2396 } |
| 2397 |
| 2398 /** |
| 2399 * Build a list of type arguments having length [numTypeArguments] where each |
| 2400 * type argument is obtained by calling [getTypeArgument]. |
| 2401 */ |
| 2402 List<DartType> _buildTypeArguments( |
| 2403 int numTypeArguments, DartType getTypeArgument(int i)) { |
| 2404 List<DartType> typeArguments = const <DartType>[]; |
| 2405 if (numTypeArguments != 0) { |
| 2406 typeArguments = <DartType>[]; |
| 2407 for (int i = 0; i < numTypeArguments; i++) { |
| 2408 typeArguments.add(getTypeArgument(i)); |
| 2409 } |
| 2410 } |
| 2411 return typeArguments; |
| 2412 } |
| 2393 } | 2413 } |
| OLD | NEW |