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

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.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 unified diff | Download patch
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.error_verifier; 5 library analyzer.src.generated.error_verifier;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
11 import 'package:analyzer/dart/ast/resolution_accessors.dart';
11 import 'package:analyzer/dart/ast/token.dart'; 12 import 'package:analyzer/dart/ast/token.dart';
12 import 'package:analyzer/dart/ast/visitor.dart'; 13 import 'package:analyzer/dart/ast/visitor.dart';
13 import 'package:analyzer/dart/element/element.dart'; 14 import 'package:analyzer/dart/element/element.dart';
14 import 'package:analyzer/dart/element/type.dart'; 15 import 'package:analyzer/dart/element/type.dart';
15 import 'package:analyzer/dart/element/visitor.dart'; 16 import 'package:analyzer/dart/element/visitor.dart';
16 import 'package:analyzer/error/error.dart'; 17 import 'package:analyzer/error/error.dart';
17 import 'package:analyzer/error/listener.dart'; 18 import 'package:analyzer/error/listener.dart';
18 import 'package:analyzer/src/dart/element/element.dart'; 19 import 'package:analyzer/src/dart/element/element.dart';
19 import 'package:analyzer/src/dart/element/member.dart'; 20 import 'package:analyzer/src/dart/element/member.dart';
20 import 'package:analyzer/src/dart/element/type.dart'; 21 import 'package:analyzer/src/dart/element/type.dart';
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 851 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
851 bool old = _isInFunctionTypedFormalParameter; 852 bool old = _isInFunctionTypedFormalParameter;
852 _isInFunctionTypedFormalParameter = true; 853 _isInFunctionTypedFormalParameter = true;
853 try { 854 try {
854 _checkForTypeAnnotationDeferredClass(node.returnType); 855 _checkForTypeAnnotationDeferredClass(node.returnType);
855 856
856 // TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and 857 // TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and
857 // we can get the function element via `node?.element?.type?.element` but 858 // we can get the function element via `node?.element?.type?.element` but
858 // it doesn't have hasImplicitReturnType set correctly. 859 // it doesn't have hasImplicitReturnType set correctly.
859 if (!_options.implicitDynamic && node.returnType == null) { 860 if (!_options.implicitDynamic && node.returnType == null) {
860 DartType parameterType = node.element.type; 861 DartType parameterType = elementForFormalParameter(node).type;
861 if (parameterType is FunctionType && 862 if (parameterType is FunctionType &&
862 parameterType.returnType.isDynamic) { 863 parameterType.returnType.isDynamic) {
863 _errorReporter.reportErrorForNode( 864 _errorReporter.reportErrorForNode(
864 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [node.identifier]); 865 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [node.identifier]);
865 } 866 }
866 } 867 }
867 return super.visitFunctionTypedFormalParameter(node); 868 return super.visitFunctionTypedFormalParameter(node);
868 } finally { 869 } finally {
869 _isInFunctionTypedFormalParameter = old; 870 _isInFunctionTypedFormalParameter = old;
870 } 871 }
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); 2232 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR);
2232 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, 2233 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor,
2233 [constructorStrName, redirectedType.displayName]); 2234 [constructorStrName, redirectedType.displayName]);
2234 } 2235 }
2235 return; 2236 return;
2236 } 2237 }
2237 FunctionType redirectedType = redirectedElement.type; 2238 FunctionType redirectedType = redirectedElement.type;
2238 DartType redirectedReturnType = redirectedType.returnType; 2239 DartType redirectedReturnType = redirectedType.returnType;
2239 2240
2240 // Report specific problem when return type is incompatible 2241 // Report specific problem when return type is incompatible
2241 FunctionType constructorType = declaration.element.type; 2242 FunctionType constructorType =
2243 elementForConstructorDeclaration(declaration).type;
2242 DartType constructorReturnType = constructorType.returnType; 2244 DartType constructorReturnType = constructorType.returnType;
2243 if (!_typeSystem.isAssignableTo( 2245 if (!_typeSystem.isAssignableTo(
2244 redirectedReturnType, constructorReturnType)) { 2246 redirectedReturnType, constructorReturnType)) {
2245 _errorReporter.reportErrorForNode( 2247 _errorReporter.reportErrorForNode(
2246 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, 2248 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE,
2247 redirectedConstructor, 2249 redirectedConstructor,
2248 [redirectedReturnType, constructorReturnType]); 2250 [redirectedReturnType, constructorReturnType]);
2249 return; 2251 return;
2250 } else if (!_typeSystem.isSubtypeOf(redirectedType, constructorType)) { 2252 } else if (!_typeSystem.isSubtypeOf(redirectedType, constructorType)) {
2251 // Check parameters. 2253 // Check parameters.
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 bool isMethod = !isGetter && !isSetter && !isOperator; 2888 bool isMethod = !isGetter && !isSetter && !isOperator;
2887 // Do lookups in the enclosing class (and the inherited member) if the 2889 // Do lookups in the enclosing class (and the inherited member) if the
2888 // member is a method or a setter for 2890 // member is a method or a setter for
2889 // StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER warning. 2891 // StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER warning.
2890 if (isMethod) { 2892 if (isMethod) {
2891 String setterName = "${name.name}="; 2893 String setterName = "${name.name}=";
2892 Element enclosingElementOfSetter = null; 2894 Element enclosingElementOfSetter = null;
2893 ClassMember conflictingSetter = memberHashMap[setterName]; 2895 ClassMember conflictingSetter = memberHashMap[setterName];
2894 if (conflictingSetter != null) { 2896 if (conflictingSetter != null) {
2895 enclosingElementOfSetter = 2897 enclosingElementOfSetter =
2896 conflictingSetter.element.enclosingElement; 2898 elementForDeclaration(conflictingSetter).enclosingElement;
2897 } else { 2899 } else {
2898 ExecutableElement elementFromInheritance = _inheritanceManager 2900 ExecutableElement elementFromInheritance = _inheritanceManager
2899 .lookupInheritance(_enclosingClass, setterName); 2901 .lookupInheritance(_enclosingClass, setterName);
2900 if (elementFromInheritance != null) { 2902 if (elementFromInheritance != null) {
2901 enclosingElementOfSetter = 2903 enclosingElementOfSetter =
2902 elementFromInheritance.enclosingElement; 2904 elementFromInheritance.enclosingElement;
2903 } 2905 }
2904 } 2906 }
2905 if (enclosingElementOfSetter != null) { 2907 if (enclosingElementOfSetter != null) {
2906 _errorReporter.reportErrorForNode( 2908 _errorReporter.reportErrorForNode(
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
4726 _errorReporter.reportErrorForOffset( 4728 _errorReporter.reportErrorForOffset(
4727 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH, 4729 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
4728 offset, 4730 offset,
4729 end - offset, 4731 end - offset,
4730 [constantNames[i]]); 4732 [constantNames[i]]);
4731 } 4733 }
4732 } 4734 }
4733 } 4735 }
4734 4736
4735 void _checkForMissingJSLibAnnotation(Annotation node) { 4737 void _checkForMissingJSLibAnnotation(Annotation node) {
4736 if (node.elementAnnotation?.isJS ?? false) { 4738 if (elementAnnotationForAnnotation(node)?.isJS ?? false) {
4737 if (_currentLibrary.isJS != true) { 4739 if (_currentLibrary.isJS != true) {
4738 _errorReporter.reportErrorForNode( 4740 _errorReporter.reportErrorForNode(
4739 HintCode.MISSING_JS_LIB_ANNOTATION, node); 4741 HintCode.MISSING_JS_LIB_ANNOTATION, node);
4740 } 4742 }
4741 } 4743 }
4742 } 4744 }
4743 4745
4744 /** 4746 /**
4745 * Verify that the given function [body] does not contain return statements 4747 * Verify that the given function [body] does not contain return statements
4746 * that both have and do not have return values. 4748 * that both have and do not have return values.
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after
6891 _checkForMissingRequiredParam( 6893 _checkForMissingRequiredParam(
6892 node.staticInvokeType, node.argumentList, node); 6894 node.staticInvokeType, node.argumentList, node);
6893 return super.visitFunctionExpressionInvocation(node); 6895 return super.visitFunctionExpressionInvocation(node);
6894 } 6896 }
6895 6897
6896 @override 6898 @override
6897 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 6899 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
6898 DartType type = node.constructorName.type.type; 6900 DartType type = node.constructorName.type.type;
6899 if (type is InterfaceType) { 6901 if (type is InterfaceType) {
6900 _checkForMissingRequiredParam( 6902 _checkForMissingRequiredParam(
6901 node.staticElement?.type, node.argumentList, node.constructorName); 6903 staticElementForConstructorReference(node)?.type,
6904 node.argumentList,
6905 node.constructorName);
6902 } 6906 }
6903 return super.visitInstanceCreationExpression(node); 6907 return super.visitInstanceCreationExpression(node);
6904 } 6908 }
6905 6909
6906 @override 6910 @override
6907 Object visitMethodInvocation(MethodInvocation node) { 6911 Object visitMethodInvocation(MethodInvocation node) {
6908 _checkForMissingRequiredParam( 6912 _checkForMissingRequiredParam(
6909 node.staticInvokeType, node.argumentList, node.methodName); 6913 node.staticInvokeType, node.argumentList, node.methodName);
6910 return super.visitMethodInvocation(node); 6914 return super.visitMethodInvocation(node);
6911 } 6915 }
6912 6916
6913 @override 6917 @override
6914 Object visitRedirectingConstructorInvocation( 6918 Object visitRedirectingConstructorInvocation(
6915 RedirectingConstructorInvocation node) { 6919 RedirectingConstructorInvocation node) {
6916 DartType type = node.staticElement?.type; 6920 DartType type = staticElementForConstructorReference(node)?.type;
6917 if (type != null) { 6921 if (type != null) {
6918 _checkForMissingRequiredParam(type, node.argumentList, node); 6922 _checkForMissingRequiredParam(type, node.argumentList, node);
6919 } 6923 }
6920 return super.visitRedirectingConstructorInvocation(node); 6924 return super.visitRedirectingConstructorInvocation(node);
6921 } 6925 }
6922 6926
6923 @override 6927 @override
6924 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 6928 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
6925 DartType type = node.staticElement?.type; 6929 DartType type = staticElementForConstructorReference(node)?.type;
6926 if (type != null) { 6930 if (type != null) {
6927 _checkForMissingRequiredParam(type, node.argumentList, node); 6931 _checkForMissingRequiredParam(type, node.argumentList, node);
6928 } 6932 }
6929 return super.visitSuperConstructorInvocation(node); 6933 return super.visitSuperConstructorInvocation(node);
6930 } 6934 }
6931 6935
6932 void _checkForMissingRequiredParam( 6936 void _checkForMissingRequiredParam(
6933 DartType type, ArgumentList argumentList, AstNode node) { 6937 DartType type, ArgumentList argumentList, AstNode node) {
6934 if (type is FunctionType) { 6938 if (type is FunctionType) {
6935 for (ParameterElement parameter in type.parameters) { 6939 for (ParameterElement parameter in type.parameters) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6972 class _InvocationCollector extends RecursiveAstVisitor { 6976 class _InvocationCollector extends RecursiveAstVisitor {
6973 final List<String> superCalls = <String>[]; 6977 final List<String> superCalls = <String>[];
6974 6978
6975 @override 6979 @override
6976 visitMethodInvocation(MethodInvocation node) { 6980 visitMethodInvocation(MethodInvocation node) {
6977 if (node.target is SuperExpression) { 6981 if (node.target is SuperExpression) {
6978 superCalls.add(node.methodName.name); 6982 superCalls.add(node.methodName.name);
6979 } 6983 }
6980 } 6984 }
6981 } 6985 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698