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

Side by Side Diff: pkg/analyzer/lib/src/dart/constant/evaluation.dart

Issue 1933763002: Use null-aware operators to clean up the code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Additional clean-up Created 4 years, 7 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
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.dart.constant.evaluation; 5 library analyzer.src.dart.constant.evaluation;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/context/declared_variables.dart'; 9 import 'package:analyzer/context/declared_variables.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 /** 79 /**
80 * Initialize a newly created [ConstantEvaluationEngine]. The [typeProvider] 80 * Initialize a newly created [ConstantEvaluationEngine]. The [typeProvider]
81 * is used to access known types. [_declaredVariables] is the set of 81 * is used to access known types. [_declaredVariables] is the set of
82 * variables declared on the command line using '-D'. The [validator], if 82 * variables declared on the command line using '-D'. The [validator], if
83 * given, is used to verify correct dependency analysis when running unit 83 * given, is used to verify correct dependency analysis when running unit
84 * tests. 84 * tests.
85 */ 85 */
86 ConstantEvaluationEngine(this.typeProvider, this._declaredVariables, 86 ConstantEvaluationEngine(this.typeProvider, this._declaredVariables,
87 {ConstantEvaluationValidator validator, TypeSystem typeSystem}) 87 {ConstantEvaluationValidator validator, TypeSystem typeSystem})
88 : validator = validator != null 88 : validator =
89 ? validator 89 validator ?? new ConstantEvaluationValidator_ForProduction(),
90 : new ConstantEvaluationValidator_ForProduction(), 90 typeSystem = typeSystem ?? new TypeSystemImpl();
91 typeSystem = typeSystem != null ? typeSystem : new TypeSystemImpl();
92 91
93 /** 92 /**
94 * Check that the arguments to a call to fromEnvironment() are correct. The 93 * Check that the arguments to a call to fromEnvironment() are correct. The
95 * [arguments] are the AST nodes of the arguments. The [argumentValues] are 94 * [arguments] are the AST nodes of the arguments. The [argumentValues] are
96 * the values of the unnamed arguments. The [namedArgumentValues] are the 95 * the values of the unnamed arguments. The [namedArgumentValues] are the
97 * values of the named arguments. The [expectedDefaultValueType] is the 96 * values of the named arguments. The [expectedDefaultValueType] is the
98 * allowed type of the "defaultValue" parameter (if present). Note: 97 * allowed type of the "defaultValue" parameter (if present). Note:
99 * "defaultValue" is always allowed to be null. Return `true` if the arguments 98 * "defaultValue" is always allowed to be null. Return `true` if the arguments
100 * are correct, `false` if there is an error. 99 * are correct, `false` if there is an error.
101 */ 100 */
(...skipping 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 return new DartObjectImpl( 1468 return new DartObjectImpl(
1470 _typeProvider.symbolType, new SymbolState(buffer.toString())); 1469 _typeProvider.symbolType, new SymbolState(buffer.toString()));
1471 } 1470 }
1472 1471
1473 /** 1472 /**
1474 * Create an error associated with the given [node]. The error will have the 1473 * Create an error associated with the given [node]. The error will have the
1475 * given error [code]. 1474 * given error [code].
1476 */ 1475 */
1477 void _error(AstNode node, ErrorCode code) { 1476 void _error(AstNode node, ErrorCode code) {
1478 _errorReporter.reportErrorForNode( 1477 _errorReporter.reportErrorForNode(
1479 code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code, node); 1478 code ?? CompileTimeErrorCode.INVALID_CONSTANT, node);
1480 } 1479 }
1481 1480
1482 /** 1481 /**
1483 * Return the constant value of the static constant represented by the given 1482 * Return the constant value of the static constant represented by the given
1484 * [element]. The [node] is the node to be used if an error needs to be 1483 * [element]. The [node] is the node to be used if an error needs to be
1485 * reported. 1484 * reported.
1486 */ 1485 */
1487 DartObjectImpl _getConstantValue(AstNode node, Element element) { 1486 DartObjectImpl _getConstantValue(AstNode node, Element element) {
1488 Element variableElement = 1487 Element variableElement =
1489 element is PropertyAccessorElement ? element.variable : element; 1488 element is PropertyAccessorElement ? element.variable : element;
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 */ 1921 */
1923 EvaluationResult(this.value, this._errors); 1922 EvaluationResult(this.value, this._errors);
1924 1923
1925 /** 1924 /**
1926 * Return a list containing the errors that should be reported for the 1925 * Return a list containing the errors that should be reported for the
1927 * expression(s) that were evaluated. If there are no such errors, the list 1926 * expression(s) that were evaluated. If there are no such errors, the list
1928 * will be empty. The list can be empty even if the expression is not a valid 1927 * will be empty. The list can be empty even if the expression is not a valid
1929 * compile time constant if the errors would have been reported by other parts 1928 * compile time constant if the errors would have been reported by other parts
1930 * of the analysis engine. 1929 * of the analysis engine.
1931 */ 1930 */
1932 List<AnalysisError> get errors => 1931 List<AnalysisError> get errors => _errors ?? AnalysisError.NO_ERRORS;
1933 _errors == null ? AnalysisError.NO_ERRORS : _errors;
1934 1932
1935 /** 1933 /**
1936 * Return `true` if the expression is a compile-time constant expression that 1934 * Return `true` if the expression is a compile-time constant expression that
1937 * would not throw an exception when evaluated. 1935 * would not throw an exception when evaluated.
1938 */ 1936 */
1939 bool get isValid => _errors == null; 1937 bool get isValid => _errors == null;
1940 1938
1941 /** 1939 /**
1942 * Return an evaluation result representing the result of evaluating an 1940 * Return an evaluation result representing the result of evaluating an
1943 * expression that is not a compile-time constant because of the given 1941 * expression that is not a compile-time constant because of the given
(...skipping 22 matching lines...) Expand all
1966 */ 1964 */
1967 List<AnalysisError> _errors; 1965 List<AnalysisError> _errors;
1968 1966
1969 /** 1967 /**
1970 * The value of the expression, or `null` if the value couldn't be computed 1968 * The value of the expression, or `null` if the value couldn't be computed
1971 * due to errors. 1969 * due to errors.
1972 */ 1970 */
1973 final DartObjectImpl value; 1971 final DartObjectImpl value;
1974 1972
1975 EvaluationResultImpl(this.value, [List<AnalysisError> errors]) { 1973 EvaluationResultImpl(this.value, [List<AnalysisError> errors]) {
1976 this._errors = errors == null ? <AnalysisError>[] : errors; 1974 this._errors = errors ?? <AnalysisError>[];
1977 } 1975 }
1978 1976
1979 List<AnalysisError> get errors => _errors; 1977 List<AnalysisError> get errors => _errors;
1980 1978
1981 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) { 1979 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) {
1982 if (this.value != null) { 1980 if (this.value != null) {
1983 if (result.value == null) { 1981 if (result.value == null) {
1984 return false; 1982 return false;
1985 } 1983 }
1986 return value == result.value; 1984 return value == result.value;
1987 } else { 1985 } else {
1988 return false; 1986 return false;
1989 } 1987 }
1990 } 1988 }
1991 1989
1992 @override 1990 @override
1993 String toString() { 1991 String toString() {
1994 if (value == null) { 1992 if (value == null) {
1995 return "error"; 1993 return "error";
1996 } 1994 }
1997 return value.toString(); 1995 return value.toString();
1998 } 1996 }
1999 } 1997 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698