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

Side by Side Diff: pkg/analyzer/lib/src/generated/element_resolver.dart

Issue 1594313002: Create a public interface for AST nodes and rename the implementation classes (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « pkg/analyzer/lib/src/generated/ast.dart ('k') | 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.generated.element_resolver; 5 library analyzer.src.generated.element_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 if (callMethod != null) { 1345 if (callMethod != null) {
1346 return _resolveArgumentsToFunction(false, argumentList, callMethod); 1346 return _resolveArgumentsToFunction(false, argumentList, callMethod);
1347 } 1347 }
1348 } else if (type is FunctionType) { 1348 } else if (type is FunctionType) {
1349 return _resolveArgumentsToParameters( 1349 return _resolveArgumentsToParameters(
1350 false, argumentList, type.parameters); 1350 false, argumentList, type.parameters);
1351 } 1351 }
1352 return null; 1352 return null;
1353 } 1353 }
1354 1354
1355 DartType _computeMethodInvokeType(MethodInvocation node, Element element) {
1356 if (element == null) {
1357 return null;
1358 }
1359
1360 DartType invokeType;
1361 if (element is PropertyAccessorElement) {
1362 invokeType = element.returnType;
1363 } else if (element is ExecutableElement) {
1364 invokeType = element.type;
1365 } else if (element is VariableElement) {
1366 invokeType = _promoteManager.getStaticType(element);
1367 }
1368
1369 //
1370 // Check for a generic method & apply type arguments if any were passed.
1371 //
1372 // TODO(jmesserly): support generic "call" methods on InterfaceType.
1373 if (invokeType is FunctionType) {
1374 FunctionType type = invokeType;
1375 List<TypeParameterElement> parameters = type.typeFormals;
1376
1377 NodeList<TypeName> arguments = node.typeArguments?.arguments;
1378 if (arguments != null && arguments.length != parameters.length) {
1379 // Wrong number of type arguments. Ignore them
1380 arguments = null;
1381 _resolver.reportErrorForNode(
1382 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS,
1383 node.methodName,
1384 [type, parameters.length, arguments?.length ?? 0]);
1385 }
1386 if (parameters.isNotEmpty) {
1387 if (arguments == null) {
1388 invokeType = _resolver.typeSystem.instantiateToBounds(type);
1389 } else {
1390 invokeType = type.instantiate(arguments.map((n) => n.type).toList());
1391 }
1392 }
1393 }
1394
1395 return invokeType;
1396 }
1397
1355 /** 1398 /**
1356 * Given an element, computes the type of the invocation. 1399 * Given an element, computes the type of the invocation.
1357 * 1400 *
1358 * For executable elements (like methods, functions) this is just their type. 1401 * For executable elements (like methods, functions) this is just their type.
1359 * 1402 *
1360 * For variables it is their type taking into account any type promotion. 1403 * For variables it is their type taking into account any type promotion.
1361 * 1404 *
1362 * For calls to getters in Dart, we invoke the function that is returned by 1405 * For calls to getters in Dart, we invoke the function that is returned by
1363 * the getter, so the invoke type is the getter's returnType. 1406 * the getter, so the invoke type is the getter's returnType.
1364 */ 1407 */
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 return false; 2609 return false;
2567 } 2610 }
2568 } 2611 }
2569 2612
2570 /** 2613 /**
2571 * An identifier that can be used to look up names in the lexical scope when 2614 * An identifier that can be used to look up names in the lexical scope when
2572 * there is no identifier in the AST structure. There is no identifier in the 2615 * there is no identifier in the AST structure. There is no identifier in the
2573 * AST when the parser could not distinguish between a method invocation and an 2616 * AST when the parser could not distinguish between a method invocation and an
2574 * invocation of a top-level function imported with a prefix. 2617 * invocation of a top-level function imported with a prefix.
2575 */ 2618 */
2576 class SyntheticIdentifier extends Identifier { 2619 class SyntheticIdentifier extends IdentifierImpl {
2577 /** 2620 /**
2578 * The name of the synthetic identifier. 2621 * The name of the synthetic identifier.
2579 */ 2622 */
2580 final String name; 2623 final String name;
2581 2624
2582 /** 2625 /**
2583 * The identifier to be highlighted in case of an error 2626 * The identifier to be highlighted in case of an error
2584 */ 2627 */
2585 final Identifier targetIdentifier; 2628 final Identifier targetIdentifier;
2586 2629
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 2664
2622 @override 2665 @override
2623 Element get staticElement => null; 2666 Element get staticElement => null;
2624 2667
2625 @override 2668 @override
2626 accept(AstVisitor visitor) => null; 2669 accept(AstVisitor visitor) => null;
2627 2670
2628 @override 2671 @override
2629 void visitChildren(AstVisitor visitor) {} 2672 void visitChildren(AstVisitor visitor) {}
2630 } 2673 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698