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

Unified Diff: pkg/analyzer/lib/src/generated/element_resolver.dart

Issue 1595243003: Move AST implementation out of generated (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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/element_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index b018994ca3b91009c4640aad8d62f7cf5bb7644c..f1de6331de671e02f4e51fc667afc3660080b780 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -6,11 +6,14 @@ library analyzer.src.generated.element_resolver;
import 'dart:collection';
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
+import 'package:analyzer/src/dart/ast/ast.dart'
+ show ChildEntities, IdentifierImpl;
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type.dart';
-import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/resolver.dart';
@@ -1396,28 +1399,6 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
- * Given an element, computes the type of the invocation.
- *
- * For executable elements (like methods, functions) this is just their type.
- *
- * For variables it is their type taking into account any type promotion.
- *
- * For calls to getters in Dart, we invoke the function that is returned by
- * the getter, so the invoke type is the getter's returnType.
- */
- DartType _getInvokeType(Element element) {
- DartType invokeType;
- if (element is PropertyAccessorElement) {
- invokeType = element.returnType;
- } else if (element is ExecutableElement) {
- invokeType = element.type;
- } else if (element is VariableElement) {
- invokeType = _promoteManager.getStaticType(element);
- }
- return invokeType ?? DynamicTypeImpl.instance;
- }
-
- /**
* If the given [element] is a setter, return the getter associated with it.
* Otherwise, return the element unchanged.
*/
@@ -1494,6 +1475,28 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
+ * Given an element, computes the type of the invocation.
+ *
+ * For executable elements (like methods, functions) this is just their type.
+ *
+ * For variables it is their type taking into account any type promotion.
+ *
+ * For calls to getters in Dart, we invoke the function that is returned by
+ * the getter, so the invoke type is the getter's returnType.
+ */
+ DartType _getInvokeType(Element element) {
+ DartType invokeType;
+ if (element is PropertyAccessorElement) {
+ invokeType = element.returnType;
+ } else if (element is ExecutableElement) {
+ invokeType = element.type;
+ } else if (element is VariableElement) {
+ invokeType = _promoteManager.getStaticType(element);
+ }
+ return invokeType ?? DynamicTypeImpl.instance;
+ }
+
+ /**
* Return the name of the method invoked by the given postfix [expression].
*/
String _getPostfixOperator(PostfixExpression expression) =>
@@ -1554,6 +1557,36 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
+ * Check for a generic method & apply type arguments if any were passed.
+ */
+ DartType _instantiateGenericMethod(
+ DartType invokeType, TypeArgumentList typeArguments, AstNode node) {
+ // TODO(jmesserly): support generic "call" methods on InterfaceType.
+ if (invokeType is FunctionType) {
+ FunctionType type = invokeType;
+ List<TypeParameterElement> parameters = type.typeFormals;
+
+ NodeList<TypeName> arguments = typeArguments?.arguments;
+ if (arguments != null && arguments.length != parameters.length) {
+ // Wrong number of type arguments. Ignore them
+ arguments = null;
+ _resolver.reportErrorForNode(
+ StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS,
+ node,
+ [type, parameters.length, arguments?.length ?? 0]);
+ }
+ if (parameters.isNotEmpty) {
+ if (arguments == null) {
+ invokeType = _resolver.typeSystem.instantiateToBounds(type);
+ } else {
+ invokeType = type.instantiate(arguments.map((n) => n.type).toList());
+ }
+ }
+ }
+ return invokeType;
+ }
+
+ /**
* Return `true` if the given [expression] is a prefix for a deferred import.
*/
bool _isDeferredPrefix(Expression expression) {
@@ -2138,36 +2171,6 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
- * Check for a generic method & apply type arguments if any were passed.
- */
- DartType _instantiateGenericMethod(
- DartType invokeType, TypeArgumentList typeArguments, AstNode node) {
- // TODO(jmesserly): support generic "call" methods on InterfaceType.
- if (invokeType is FunctionType) {
- FunctionType type = invokeType;
- List<TypeParameterElement> parameters = type.typeFormals;
-
- NodeList<TypeName> arguments = typeArguments?.arguments;
- if (arguments != null && arguments.length != parameters.length) {
- // Wrong number of type arguments. Ignore them
- arguments = null;
- _resolver.reportErrorForNode(
- StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS,
- node,
- [type, parameters.length, arguments?.length ?? 0]);
- }
- if (parameters.isNotEmpty) {
- if (arguments == null) {
- invokeType = _resolver.typeSystem.instantiateToBounds(type);
- } else {
- invokeType = type.instantiate(arguments.map((n) => n.type).toList());
- }
- }
- }
- return invokeType;
- }
-
- /**
* Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the
* element being invoked. If the returned element is a method, then the method
* will be invoked. If the returned element is a getter, the getter will be

Powered by Google App Engine
This is Rietveld 408576698