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

Unified Diff: pkg/analyzer/lib/dart/ast/resolution_accessors.dart

Issue 2551023005: Prepare for decoupling analyzer ASTs from element model. (Closed)
Patch Set: Created 4 years 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/dart/ast/resolution_accessors.dart
diff --git a/pkg/analyzer/lib/dart/ast/resolution_accessors.dart b/pkg/analyzer/lib/dart/ast/resolution_accessors.dart
new file mode 100644
index 0000000000000000000000000000000000000000..76a37b8903e3b8b9f5765a40bde3950dc894a77c
--- /dev/null
+++ b/pkg/analyzer/lib/dart/ast/resolution_accessors.dart
@@ -0,0 +1,300 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
+
+/**
+ * Return the best element available for the function being invoked at [node].
+ * If resolution was able to find a better element based on type propagation,
+ * that element will be returned. Otherwise, the element found using the
+ * result of static analysis will be returned. If resolution has not been
+ * performed, then `null` will be returned.
+ */
+ExecutableElement bestElementForFunctionExpressionInvocation(
Brian Wilkerson 2016/12/05 18:22:11 I am concerned about the use of top-level function
Paul Berry 2016/12/07 18:06:16 Fair enough. I reworked to use a similar model to
+ FunctionExpressionInvocation node) =>
+ node.bestElement;
+
+/**
+ * Return the best element available for the identifier [node]. If resolution
+ * was able to find a better element based on type propagation, that element
+ * will be returned. Otherwise, the element found using the result of static
+ * analysis will be returned. If resolution has not been performed, then `null`
+ * will be returned.
+ */
+Element bestElementForIdentifier(Identifier node) => node.bestElement;
+
+/**
+ * Return the best element available for the expression [node]. If resolution
+ * was able to find a better element based on type propagation, that element
+ * will be returned. Otherwise, the element found using the result of static
+ * analysis will be returned. If resolution has not been performed, then
+ * `null` will be returned.
+ */
+MethodElement bestElementForMethodReference(MethodReferenceExpression node) =>
+ node.bestElement;
+
+/**
+ * Return the best parameter element information available for the expression
+ * [node]. If type propagation was able to find a better parameter element
+ * than static analysis, that type will be returned. Otherwise, the result of
+ * static analysis will be returned.
+ */
+ParameterElement bestParameterElementForExpression(Expression node) =>
+ node.bestParameterElement;
+
+/**
+ * Return the best type information available for the expression [node]. If type
+ * propagation was able to find a better type than static analysis, that type
+ * will be returned. Otherwise, the result of static analysis will be
+ * returned. If no type analysis has been performed, then the type 'dynamic'
+ * will be returned.
+ */
+DartType bestTypeForExpression(Expression node) => node.bestType;
+
+/**
+ * Return the element annotation representing the annotation [node] in the
+ * element model.
+ */
+ElementAnnotation elementAnnotationForAnnotation(Annotation node) =>
+ node.elementAnnotation;
+
+/**
+ * Return the element associated with the annotation [node], or `null` if the
+ * AST structure has not been resolved or if this annotation could not be
+ * resolved.
+ */
+Element elementForAnnotation(Annotation node) => node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+ClassElement elementForClassDeclaration(ClassDeclaration node) => node.element;
Brian Wilkerson 2016/12/05 18:22:11 Consider renaming functions like this to something
Paul Berry 2016/12/07 18:06:16 Done.
+
+/**
+ * Return the element associated with the compilation unit [node], or `null` if
+ * the AST structure has not been resolved.
+ */
+CompilationUnitElement elementForCompilationUnit(CompilationUnit node) =>
+ node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+ConstructorElement elementForConstructorDeclaration(
+ ConstructorDeclaration node) =>
+ node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+Element elementForDeclaration(Declaration node) => node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+LocalVariableElement elementForDeclaredIdentifier(DeclaredIdentifier node) =>
+ node.element;
+
+/**
+ * Return the element associated with the directive [node], or `null` if the AST
+ * structure has not been resolved or if this directive could not be resolved.
+ */
+Element elementForDirective(Directive node) => node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+ClassElement elementForEnumDeclaration(EnumDeclaration node) => node.element;
+
+/**
+ * Return the element representing the parameter [node], or `null` if this
+ * parameter has not been resolved.
+ */
+ParameterElement elementForFormalParameter(FormalParameter node) =>
+ node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+ExecutableElement elementForFunctionDeclaration(FunctionDeclaration node) =>
+ node.element;
+
+/**
+ * Return the element associated with the function expression [node], or `null`
+ * if the AST structure has not been resolved.
+ */
+ExecutableElement elementForFunctionExpression(FunctionExpression node) =>
+ node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+ExecutableElement elementForMethodDeclaration(MethodDeclaration node) =>
+ node.element;
+
+/**
+ * Return the element representing the parameter being named by the
+ * expression [node], or `null` if the AST structure has not been resolved or if
+ * there is no parameter with the same name as this expression.
+ */
+ParameterElement elementForNamedExpression(NamedExpression node) =>
+ node.element;
+
+/**
+ * Return the element associated with the declaration [node], or `null` if
+ * either this node corresponds to a list of declarations or if the AST
+ * structure has not been resolved.
+ */
+VariableElement elementForVariableDeclaration(VariableDeclaration node) =>
+ node.element;
+
+/**
+ * Return a list containing the elements representing the parameters in the
+ * list [node]. The list will contain `null`s if the parameters in this list
+ * have not been resolved.
+ */
+List<ParameterElement> parameterElementsForFormalParameterList(
+ FormalParameterList node) =>
+ node.parameterElements;
+
+/**
+ * Return the element associated with the function being invoked at [node] based
+ * on propagated type information, or `null` if the AST structure has not been
+ * resolved or the function could not be resolved.
+ */
+ExecutableElement propagatedElementForFunctionExpressionInvocation(
+ FunctionExpressionInvocation node) =>
+ node.propagatedElement;
+
+/**
+ * Return the element associated with the identifier [node] based on propagated
+ * type information, or `null` if the AST structure has not been resolved or if
+ * this identifier could not be resolved. One example of the latter case is an
+ * identifier that is not defined within the scope in which it appears.
+ */
+Element propagatedElementForIdentifier(Identifier node) =>
+ node.propagatedElement;
+
+/**
+ * Return the element associated with the expression [node] based on propagated
+ * types, or `null` if the AST structure has not been resolved, or there is
+ * no meaningful propagated element to return (e.g. because this is a
+ * non-compound assignment expression, or because the method referred to could
+ * not be resolved).
+ */
+MethodElement propagatedElementForMethodReference(
+ MethodReferenceExpression node) =>
+ node.propagatedElement;
+
+/**
+ * If the expression [node] is an argument to an invocation, and the AST
+ * structure has been resolved, and the function being invoked is known based on
+ * propagated type information, and [node] corresponds to one of the
+ * parameters of the function being invoked, then return the parameter element
+ * representing the parameter to which the value of [node] will be
+ * bound. Otherwise, return `null`.
+ */
+ParameterElement propagatedParameterElementForExpression(Expression node) =>
+ node.propagatedParameterElement;
+
+/**
+ * Return the propagated type of the expression [node], or `null` if type
+ * propagation has not been performed on the AST structure.
+ */
+DartType propagatedTypeForExpression(Expression node) => node.propagatedType;
+
+/**
+ * Return the element associated with the constructor referenced by [node] based
+ * on static type information, or `null` if the AST structure has not been
+ * resolved or if the constructor could not be resolved.
+ */
+ConstructorElement staticElementForConstructorReference(
+ ConstructorReferenceNode node) =>
+ node.staticElement;
+
+/**
+ * Return the element associated with the function being invoked at [node] based
+ * on static type information, or `null` if the AST structure has not been
+ * resolved or the function could not be resolved.
+ */
+ExecutableElement staticElementForFunctionExpressionInvocation(
+ FunctionExpressionInvocation node) =>
+ node.staticElement;
+
+/**
+ * Return the element associated with the identifier [node] based on static type
+ * information, or `null` if the AST structure has not been resolved or if
+ * this identifier could not be resolved. One example of the latter case is an
+ * identifier that is not defined within the scope in which it appears
+ */
+Element staticElementForIdentifier(Identifier node) => node.staticElement;
+
+/**
+ * Return the element associated with the expression [node] based on the static
+ * types, or `null` if the AST structure has not been resolved, or there is no
+ * meaningful static element to return (e.g. because this is a non-compound
+ * assignment expression, or because the method referred to could not be
+ * resolved).
+ */
+MethodElement staticElementForMethodReference(MethodReferenceExpression node) =>
+ node.staticElement;
+
+/**
+ * Return the function type of the invocation [node] based on the static type
+ * information, or `null` if the AST structure has not been resolved, or if
+ * the invoke could not be resolved.
+ *
+ * This will usually be a [FunctionType], but it can also be an
+ * [InterfaceType] with a `call` method, `dynamic`, `Function`, or a `@proxy`
+ * interface type that implements `Function`.
+ */
+DartType staticInvokeTypeForInvocationExpression(InvocationExpression node) =>
+ node.staticInvokeType;
+
+/**
+ * If the expression [node] is an argument to an invocation, and the AST
+ * structure has been resolved, and the function being invoked is known based on
+ * static type information, and [node] corresponds to one of the parameters
+ * of the function being invoked, then return the parameter element
+ * representing the parameter to which the value of [node] will be
+ * bound. Otherwise, return `null`.
+ */
+ParameterElement staticParameterElementForExpression(Expression node) =>
+ node.staticParameterElement;
+
+/**
+ * Return the static type of the expression [node], or `null` if the AST
+ * structure has not been resolved.
+ */
+DartType staticTypeForExpression(Expression node) => node.staticType;
+
+/**
+ * Return the type being named by [node], or `null` if the AST structure has not
+ * been resolved.
+ */
+DartType typeForTypeName(TypeName node) => node.type;
+
+/**
+ * Return the element associated with the uri of the directive [node], or `null`
+ * if the AST structure has not been resolved or if the URI could not be
+ * resolved. Examples of the latter case include a directive that contains an
+ * invalid URL or a URL that does not exist.
+ */
+Element uriElementForDirective(UriBasedDirective node) => node.uriElement;

Powered by Google App Engine
This is Rietveld 408576698