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

Unified Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2342733002: Break up another large file (Closed)
Patch Set: fixed floating comment Created 4 years, 3 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
« no previous file with comments | « pkg/analyzer/lib/src/task/options_work_manager.dart ('k') | pkg/analyzer/lib/src/task/yaml.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/strong/checker.dart
diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart
index ac2f6ef780b889b883f68d6231aaee6cd4c62a88..0fd6f26590745d1b76e8192ede98376a7a3e9e42 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -14,21 +14,13 @@ 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/element/type.dart';
+import 'package:analyzer/src/error/codes.dart' show StrongModeCode;
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
-import 'package:analyzer/src/generated/error.dart' show StrongModeCode;
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
import 'package:analyzer/src/generated/type_system.dart';
import 'ast_properties.dart';
-bool isKnownFunction(Expression expression) {
- var element = _getKnownElement(expression);
- // First class functions and static methods, where we know the original
- // declaration, will have an exact type, so we know a downcast will fail.
- return element is FunctionElement ||
- element is MethodElement && element.isStatic;
-}
-
/// Given an [expression] and a corresponding [typeSystem] and [typeProvider],
/// gets the known static type of the expression.
///
@@ -50,9 +42,20 @@ DartType getDefiniteType(
return type;
}
-bool _hasStrictArrow(Expression expression) {
+bool isKnownFunction(Expression expression) {
var element = _getKnownElement(expression);
- return element is FunctionElement || element is MethodElement;
+ // First class functions and static methods, where we know the original
+ // declaration, will have an exact type, so we know a downcast will fail.
+ return element is FunctionElement ||
+ element is MethodElement && element.isStatic;
+}
+
+DartType _elementType(Element e) {
+ if (e == null) {
+ // Malformed code - just return dynamic.
+ return DynamicTypeImpl.instance;
+ }
+ return (e as dynamic).type;
}
Element _getKnownElement(Expression expression) {
@@ -69,16 +72,8 @@ Element _getKnownElement(Expression expression) {
return null;
}
-DartType _elementType(Element e) {
- if (e == null) {
- // Malformed code - just return dynamic.
- return DynamicTypeImpl.instance;
- }
- return (e as dynamic).type;
-}
-
-// Return the field on type corresponding to member, or null if none
-// exists or the "field" is actually a getter/setter.
+/// Return the field on type corresponding to member, or null if none
+/// exists or the "field" is actually a getter/setter.
PropertyInducingElement _getMemberField(
InterfaceType type, PropertyAccessorElement member) {
String memberName = member.name;
@@ -109,6 +104,11 @@ PropertyInducingElement _getMemberField(
FunctionType _getMemberType(InterfaceType type, ExecutableElement member) =>
_memberTypeGetter(member)(type);
+bool _hasStrictArrow(Expression expression) {
+ var element = _getKnownElement(expression);
+ return element is FunctionElement || element is MethodElement;
+}
+
_MemberTypeGetter _memberTypeGetter(ExecutableElement member) {
String memberName = member.name;
final isGetter = member is PropertyAccessorElement && member.isGetter;
@@ -640,6 +640,20 @@ class CodeChecker extends RecursiveAstVisitor {
}
@override
+ Object visitVariableDeclaration(VariableDeclaration node) {
+ if (!node.isConst &&
+ !node.isFinal &&
+ node.initializer == null &&
+ rules.isNonNullableType(node?.element?.type)) {
+ _recordMessage(
+ node,
+ StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED,
+ [node.name, node?.element?.type]);
+ }
+ return super.visitVariableDeclaration(node);
+ }
+
+ @override
void visitVariableDeclarationList(VariableDeclarationList node) {
TypeName type = node.type;
if (type == null) {
@@ -658,20 +672,6 @@ class CodeChecker extends RecursiveAstVisitor {
}
@override
- Object visitVariableDeclaration(VariableDeclaration node) {
- if (!node.isConst &&
- !node.isFinal &&
- node.initializer == null &&
- rules.isNonNullableType(node?.element?.type)) {
- _recordMessage(
- node,
- StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED,
- [node.name, node?.element?.type]);
- }
- return super.visitVariableDeclaration(node);
- }
-
- @override
void visitWhileStatement(WhileStatement node) {
checkBoolean(node.condition);
node.visitChildren(this);
@@ -877,10 +877,11 @@ class CodeChecker extends RecursiveAstVisitor {
/// Checks if the assignment is valid with respect to non-nullable types.
/// Returns `false` if a nullable expression is assigned to a variable of
/// non-nullable type and `true` otherwise.
- bool _checkNonNullAssignment(Expression expression, DartType to, DartType from) {
+ bool _checkNonNullAssignment(
+ Expression expression, DartType to, DartType from) {
if (rules.isNonNullableType(to) && rules.isNullableType(from)) {
- _recordMessage(expression, StaticTypeWarningCode.INVALID_ASSIGNMENT,
- [from, to]);
+ _recordMessage(
+ expression, StaticTypeWarningCode.INVALID_ASSIGNMENT, [from, to]);
return false;
}
return true;
@@ -923,6 +924,9 @@ class CodeChecker extends RecursiveAstVisitor {
}
}
+ DartType _getDefiniteType(Expression expr) =>
+ getDefiniteType(expr, rules, typeProvider);
+
/// Gets the expected return type of the given function [body], either from
/// a normal return/yield, or from a yield*.
DartType _getExpectedReturnType(FunctionBody body, {bool yieldStar: false}) {
@@ -977,9 +981,6 @@ class CodeChecker extends RecursiveAstVisitor {
}
}
- DartType _getDefiniteType(Expression expr) =>
- getDefiniteType(expr, rules, typeProvider);
-
/// Given an expression, return its type assuming it is
/// in the caller position of a call (that is, accounting
/// for the possibility of a call method). Returns null
« no previous file with comments | « pkg/analyzer/lib/src/task/options_work_manager.dart ('k') | pkg/analyzer/lib/src/task/yaml.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698