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

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.dart

Issue 1925173002: Add a (public) utility method to clean-up code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/analysis_server/lib/src/services/correction/util.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
index ca385798a9fae63ebda48e655f4025acbdeffc09..551964a7f249534dbed011042d0b2eabbb64a250 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -1284,18 +1284,15 @@ class CorrectionUtils {
*/
_InvertedCondition _invertCondition0(Expression expression) {
if (expression is BooleanLiteral) {
- BooleanLiteral literal = expression;
- if (literal.value) {
+ if (expression.value) {
return _InvertedCondition._simple("false");
} else {
return _InvertedCondition._simple("true");
}
- }
- if (expression is BinaryExpression) {
- BinaryExpression binary = expression;
- TokenType operator = binary.operator.type;
- Expression le = binary.leftOperand;
- Expression re = binary.rightOperand;
+ } else if (expression is BinaryExpression) {
+ TokenType operator = expression.operator.type;
+ Expression le = expression.leftOperand;
+ Expression re = expression.rightOperand;
_InvertedCondition ls = _invertCondition0(le);
_InvertedCondition rs = _invertCondition0(re);
if (operator == TokenType.LT) {
@@ -1324,37 +1321,22 @@ class CorrectionUtils {
return _InvertedCondition._binary(
TokenType.AMPERSAND_AMPERSAND.precedence, ls, " && ", rs);
}
- }
- if (expression is IsExpression) {
- IsExpression isExpression = expression;
- String expressionSource = getNodeText(isExpression.expression);
- String typeSource = getNodeText(isExpression.type);
- if (isExpression.notOperator == null) {
+ } else if (expression is IsExpression) {
+ String expressionSource = getNodeText(expression.expression);
+ String typeSource = getNodeText(expression.type);
+ if (expression.notOperator == null) {
return _InvertedCondition._simple("$expressionSource is! $typeSource");
} else {
return _InvertedCondition._simple("$expressionSource is $typeSource");
}
- }
- if (expression is PrefixExpression) {
- PrefixExpression prefixExpression = expression;
- TokenType operator = prefixExpression.operator.type;
+ } else if (expression is PrefixExpression) {
+ TokenType operator = expression.operator.type;
if (operator == TokenType.BANG) {
- Expression operand = prefixExpression.operand;
- while (operand is ParenthesizedExpression) {
- ParenthesizedExpression pe = operand as ParenthesizedExpression;
- operand = pe.expression;
- }
+ Expression operand = expression.operand.unParenthesized;
return _InvertedCondition._simple(getNodeText(operand));
}
- }
- if (expression is ParenthesizedExpression) {
- ParenthesizedExpression pe = expression;
- Expression innerExpression = pe.expression;
- while (innerExpression is ParenthesizedExpression) {
- innerExpression =
- (innerExpression as ParenthesizedExpression).expression;
- }
- return _invertCondition0(innerExpression);
+ } else if (expression is ParenthesizedExpression) {
+ return _invertCondition0(expression.unParenthesized);
}
DartType type = expression.bestType;
if (type.displayName == "bool") {
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | pkg/analyzer/lib/dart/ast/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698