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 95fb59097c69bd8863a6f806b70d80ca10ddc764..f214c9fd26b792398af53a290f8088f0d58e704f 100644 |
--- a/pkg/analysis_server/lib/src/services/correction/util.dart |
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart |
@@ -6,10 +6,10 @@ library services.src.correction.util; |
import 'dart:math'; |
-import 'package:analysis_server/src/protocol.dart' show SourceChange, |
- SourceEdit; |
-import 'package:analysis_server/src/protocol_server.dart' show |
- doSourceChange_addElementEdit; |
+import 'package:analysis_server/src/protocol.dart' |
+ show SourceChange, SourceEdit; |
+import 'package:analysis_server/src/protocol_server.dart' |
+ show doSourceChange_addElementEdit; |
import 'package:analysis_server/src/services/correction/source_range.dart'; |
import 'package:analysis_server/src/services/correction/strings.dart'; |
import 'package:analyzer/src/generated/ast.dart'; |
@@ -20,7 +20,6 @@ import 'package:analyzer/src/generated/scanner.dart'; |
import 'package:analyzer/src/generated/source.dart'; |
import 'package:path/path.dart'; |
- |
/** |
* Adds edits to the given [change] that ensure that all the [libraries] are |
* imported into the given [targetLibrary]. |
@@ -59,13 +58,10 @@ void addLibraryImports(SourceChange change, LibraryElement targetLibrary, |
String importPath = getLibrarySourceUri(targetLibrary, library.source); |
String importCode = "${prefix}import '$importPath';$suffix"; |
doSourceChange_addElementEdit( |
- change, |
- targetLibrary, |
- new SourceEdit(offset, 0, importCode)); |
+ change, targetLibrary, new SourceEdit(offset, 0, importCode)); |
} |
} |
- |
/** |
* @return <code>true</code> if given [List]s are identical at given position. |
*/ |
@@ -79,7 +75,6 @@ bool allListsIdentical(List<List> lists, int position) { |
return true; |
} |
- |
/** |
* Climbs up [PrefixedIdentifier] and [ProperyAccess] nodes that include [node]. |
*/ |
@@ -98,7 +93,6 @@ Expression climbPropertyAccess(AstNode node) { |
} |
} |
- |
/** |
* Attempts to convert the given absolute path into an absolute URI, such as |
* "dart" or "package" URI. |
@@ -117,7 +111,6 @@ String findAbsoluteUri(AnalysisContext context, String path) { |
return uri.toString(); |
} |
- |
/** |
* TODO(scheglov) replace with nodes once there will be [CompilationUnit.getComments]. |
* |
@@ -137,8 +130,6 @@ List<SourceRange> getCommentRanges(CompilationUnit unit) { |
return ranges; |
} |
- |
- |
String getDefaultValueCode(DartType type) { |
if (type != null) { |
String typeName = type.displayName; |
@@ -166,7 +157,6 @@ String getElementKindName(Element element) { |
return element.kind.displayName; |
} |
- |
/** |
* Returns the name to display in the UI for the given [Element]. |
*/ |
@@ -179,7 +169,6 @@ String getElementQualifiedName(Element element) { |
} |
} |
- |
/** |
* If the given [AstNode] is in a [ClassDeclaration], returns the |
* [ClassElement]. Otherwise returns `null`. |
@@ -193,7 +182,6 @@ ClassElement getEnclosingClassElement(AstNode node) { |
return null; |
} |
- |
/** |
* Returns a class or an unit member enclosing the given [node]. |
*/ |
@@ -212,7 +200,6 @@ AstNode getEnclosingClassOrUnitMember(AstNode node) { |
return null; |
} |
- |
/** |
* @return the [ExecutableElement] of the enclosing executable [AstNode]. |
*/ |
@@ -232,8 +219,6 @@ ExecutableElement getEnclosingExecutableElement(AstNode node) { |
return null; |
} |
- |
- |
/** |
* @return the enclosing executable [AstNode]. |
*/ |
@@ -253,7 +238,6 @@ AstNode getEnclosingExecutableNode(AstNode node) { |
return null; |
} |
- |
/** |
* Returns [getExpressionPrecedence] for the parent of [node], |
* or `0` if the parent node is [ParenthesizedExpression]. |
@@ -268,7 +252,6 @@ int getExpressionParentPrecedence(AstNode node) { |
return getExpressionPrecedence(parent); |
} |
- |
/** |
* Returns the precedence of [node] it is an [Expression], negative otherwise. |
*/ |
@@ -279,7 +262,6 @@ int getExpressionPrecedence(AstNode node) { |
return -1000; |
} |
- |
/** |
* Returns the namespace of the given [ImportElement]. |
*/ |
@@ -322,7 +304,6 @@ String getLinePrefix(String line) { |
return line.substring(0, index); |
} |
- |
/** |
* @return the [LocalVariableElement] or [ParameterElement] if given |
* [SimpleIdentifier] is the reference to local variable or parameter, or |
@@ -339,7 +320,6 @@ VariableElement getLocalOrParameterVariableElement(SimpleIdentifier node) { |
return null; |
} |
- |
/** |
* @return the [LocalVariableElement] if given [SimpleIdentifier] is the reference to |
* local variable, or <code>null</code> in the other case. |
@@ -352,7 +332,6 @@ LocalVariableElement getLocalVariableElement(SimpleIdentifier node) { |
return null; |
} |
- |
/** |
* @return the nearest common ancestor [AstNode] of the given [AstNode]s. |
*/ |
@@ -373,7 +352,7 @@ AstNode getNearestCommonAncestor(List<AstNode> nodes) { |
} |
// find deepest parent |
int i = 0; |
- for ( ; i < minLength; i++) { |
+ for (; i < minLength; i++) { |
if (!allListsIdentical(parents, i)) { |
break; |
} |
@@ -381,7 +360,6 @@ AstNode getNearestCommonAncestor(List<AstNode> nodes) { |
return parents[0][i - 1]; |
} |
- |
/** |
* Returns the [Expression] qualifier if given node is the name part of a |
* [PropertyAccess] or a [PrefixedIdentifier]. Maybe `null`. |
@@ -403,7 +381,6 @@ Expression getNodeQualifier(SimpleIdentifier node) { |
return null; |
} |
- |
/** |
* Returns the [ParameterElement] if the given [SimpleIdentifier] is a reference |
* to a parameter, or `null` in the other case. |
@@ -416,7 +393,6 @@ ParameterElement getParameterElement(SimpleIdentifier node) { |
return null; |
} |
- |
/** |
* @return parent [AstNode]s from [CompilationUnit] (at index "0") to the given one. |
*/ |
@@ -441,7 +417,6 @@ List<AstNode> getParents(AstNode node) { |
return parents; |
} |
- |
/** |
* Returns a [PropertyAccessorElement] if the given [SimpleIdentifier] is a |
* reference to a property, or `null` in the other case. |
@@ -454,7 +429,6 @@ PropertyAccessorElement getPropertyAccessorElement(SimpleIdentifier node) { |
return null; |
} |
- |
/** |
* If given [AstNode] is name of qualified property extraction, returns target from which |
* this property is extracted. Otherwise `null`. |
@@ -491,7 +465,6 @@ Statement getSingleStatement(Statement statement) { |
return statement; |
} |
- |
/** |
* Returns the [String] content of the given [Source]. |
*/ |
@@ -499,7 +472,6 @@ String getSourceContent(AnalysisContext context, Source source) { |
return context.getContents(source).data; |
} |
- |
/** |
* Returns the given [Statement] if not a [Block], or all the children |
* [Statement]s if a [Block]. |
@@ -511,7 +483,6 @@ List<Statement> getStatements(Statement statement) { |
return [statement]; |
} |
- |
/** |
* Checks if the given [Element]'s display name equals to the given name. |
*/ |
@@ -522,7 +493,6 @@ bool hasDisplayName(Element element, String name) { |
return element.displayName == name; |
} |
- |
/** |
* Checks if the given [PropertyAccessorElement] is an accessor of a |
* [FieldElement]. |
@@ -531,7 +501,6 @@ bool isFieldAccessorElement(PropertyAccessorElement accessor) { |
return accessor != null && accessor.variable is FieldElement; |
} |
- |
/** |
* Checks if given [DartNode] is the left hand side of an assignment, or a |
* declaration of a variable. |
@@ -544,7 +513,6 @@ bool isLeftHandOfAssignment(SimpleIdentifier node) { |
(node.parent as VariableDeclaration).name == node; |
} |
- |
/** |
* @return `true` if the given [SimpleIdentifier] is the name of the |
* [NamedExpression]. |
@@ -563,7 +531,6 @@ bool isNamedExpressionName(SimpleIdentifier node) { |
return false; |
} |
- |
/** |
* If the given [expression] is the `expression` property of a [NamedExpression] |
* then returns this [NamedExpression]. Otherwise returns [expression]. |
@@ -578,7 +545,6 @@ Expression stepUpNamedExpression(Expression expression) { |
return expression; |
} |
- |
class CorrectionUtils { |
final CompilationUnit unit; |
@@ -617,8 +583,8 @@ class CorrectionUtils { |
* [SourceRange] from [oldIndent] to [newIndent], keeping indentation of lines |
* relative to each other. |
*/ |
- SourceEdit createIndentEdit(SourceRange range, String oldIndent, |
- String newIndent) { |
+ SourceEdit createIndentEdit( |
+ SourceRange range, String oldIndent, String newIndent) { |
String newSource = replaceSourceRangeIndent(range, oldIndent, newIndent); |
return new SourceEdit(range.offset, range.length, newSource); |
} |
@@ -633,8 +599,8 @@ class CorrectionUtils { |
* Returns the actual type source of the given [Expression], may be `null` |
* if can not be resolved, should be treated as the `dynamic` type. |
*/ |
- String getExpressionTypeSource(Expression expression, |
- Set<LibraryElement> librariesToImport) { |
+ String getExpressionTypeSource( |
+ Expression expression, Set<LibraryElement> librariesToImport) { |
if (expression == null) { |
return null; |
} |
@@ -918,8 +884,8 @@ class CorrectionUtils { |
/** |
* @return the source for the parameter with the given type and name. |
*/ |
- String getParameterSource(DartType type, String name, |
- Set<LibraryElement> librariesToImport) { |
+ String getParameterSource( |
+ DartType type, String name, Set<LibraryElement> librariesToImport) { |
// no type |
if (type == null || type.isDynamic) { |
return name; |
@@ -945,8 +911,8 @@ class CorrectionUtils { |
if (i != 0) { |
sb.write(", "); |
} |
- sb.write( |
- getParameterSource(fParameter.type, fParameter.name, librariesToImport)); |
+ sb.write(getParameterSource( |
+ fParameter.type, fParameter.name, librariesToImport)); |
} |
sb.write(')'); |
// done |
@@ -1098,8 +1064,8 @@ class CorrectionUtils { |
* Returns the source with indentation changed from [oldIndent] to |
* [newIndent], keeping indentation of lines relative to each other. |
*/ |
- String replaceSourceIndent(String source, String oldIndent, |
- String newIndent) { |
+ String replaceSourceIndent( |
+ String source, String oldIndent, String newIndent) { |
// prepare STRING token ranges |
List<SourceRange> lineRanges = []; |
{ |
@@ -1149,8 +1115,8 @@ class CorrectionUtils { |
* from [oldIndent] to [newIndent], keeping indentation of lines relative |
* to each other. |
*/ |
- String replaceSourceRangeIndent(SourceRange range, String oldIndent, |
- String newIndent) { |
+ String replaceSourceRangeIndent( |
+ SourceRange range, String oldIndent, String newIndent) { |
String oldSource = getRangeText(range); |
return replaceSourceIndent(oldSource, oldIndent, newIndent); |
} |
@@ -1159,18 +1125,17 @@ class CorrectionUtils { |
* @return <code>true</code> if "selection" covers "node" and there are any non-whitespace tokens |
* between "selection" and "node" start/end. |
*/ |
- bool selectionIncludesNonWhitespaceOutsideNode(SourceRange selection, |
- AstNode node) { |
+ bool selectionIncludesNonWhitespaceOutsideNode( |
+ SourceRange selection, AstNode node) { |
return _selectionIncludesNonWhitespaceOutsideRange( |
- selection, |
- rangeNode(node)); |
+ selection, rangeNode(node)); |
} |
/** |
* @return <code>true</code> if given range of [BinaryExpression] can be extracted. |
*/ |
- bool validateBinaryExpressionRange(BinaryExpression binaryExpression, |
- SourceRange range) { |
+ bool validateBinaryExpressionRange( |
+ BinaryExpression binaryExpression, SourceRange range) { |
// only parts of associative expression are safe to extract |
if (!binaryExpression.operator.type.isAssociativeOperator) { |
return false; |
@@ -1243,17 +1208,11 @@ class CorrectionUtils { |
} |
if (operator == TokenType.AMPERSAND_AMPERSAND) { |
return _InvertedCondition._binary( |
- TokenType.BAR_BAR.precedence, |
- ls, |
- " || ", |
- rs); |
+ TokenType.BAR_BAR.precedence, ls, " || ", rs); |
} |
if (operator == TokenType.BAR_BAR) { |
return _InvertedCondition._binary( |
- TokenType.AMPERSAND_AMPERSAND.precedence, |
- ls, |
- " && ", |
- rs); |
+ TokenType.AMPERSAND_AMPERSAND.precedence, ls, " && ", rs); |
} |
} |
if (expression is IsExpression) { |
@@ -1261,11 +1220,11 @@ class CorrectionUtils { |
String expressionSource = getNodeText(isExpression.expression); |
String typeSource = getNodeText(isExpression.type); |
if (isExpression.notOperator == null) { |
- return _InvertedCondition._simple( |
- "${expressionSource} is! ${typeSource}"); |
+ return _InvertedCondition |
+ ._simple("${expressionSource} is! ${typeSource}"); |
} else { |
- return _InvertedCondition._simple( |
- "${expressionSource} is ${typeSource}"); |
+ return _InvertedCondition |
+ ._simple("${expressionSource} is ${typeSource}"); |
} |
} |
if (expression is PrefixExpression) { |
@@ -1307,19 +1266,18 @@ class CorrectionUtils { |
return true; |
} |
- bool _selectionIncludesNonWhitespaceOutsideOperands(SourceRange selection, |
- List<Expression> operands) { |
+ bool _selectionIncludesNonWhitespaceOutsideOperands( |
+ SourceRange selection, List<Expression> operands) { |
return _selectionIncludesNonWhitespaceOutsideRange( |
- selection, |
- rangeNodes(operands)); |
+ selection, rangeNodes(operands)); |
} |
/** |
* @return <code>true</code> if "selection" covers "range" and there are any non-whitespace tokens |
* between "selection" and "range" start/end. |
*/ |
- bool _selectionIncludesNonWhitespaceOutsideRange(SourceRange selection, |
- SourceRange range) { |
+ bool _selectionIncludesNonWhitespaceOutsideRange( |
+ SourceRange selection, SourceRange range) { |
// selection should cover range |
if (!selection.covers(range)) { |
return false; |
@@ -1340,8 +1298,8 @@ class CorrectionUtils { |
* @return [Expression]s from <code>operands</code> which are completely covered by given |
* [SourceRange]. Range should start and end between given [Expression]s. |
*/ |
- static List<Expression> _getOperandsForSourceRange(List<Expression> operands, |
- SourceRange range) { |
+ static List<Expression> _getOperandsForSourceRange( |
+ List<Expression> operands, SourceRange range) { |
assert(!operands.isEmpty); |
List<Expression> subOperands = []; |
// track range enter/exit |
@@ -1397,7 +1355,6 @@ class CorrectionUtils { |
} |
} |
- |
/** |
* Describes where to insert new directive or top-level declaration. |
*/ |
@@ -1407,7 +1364,6 @@ class CorrectionUtils_InsertDesc { |
String suffix = ""; |
} |
- |
/** |
* Utilities to work with [Token]s. |
*/ |
@@ -1468,7 +1424,6 @@ class TokenUtils { |
tokens.length == 1 && tokens[0].type == type; |
} |
- |
/** |
* A container with a source and its precedence. |
*/ |
@@ -1481,27 +1436,25 @@ class _InvertedCondition { |
static _InvertedCondition _binary(int precedence, _InvertedCondition left, |
String operation, _InvertedCondition right) { |
- String src = |
- _parenthesizeIfRequired(left, precedence) + |
+ String src = _parenthesizeIfRequired(left, precedence) + |
operation + |
_parenthesizeIfRequired(right, precedence); |
return new _InvertedCondition(precedence, src); |
} |
- static _InvertedCondition _binary2(_InvertedCondition left, String operation, |
- _InvertedCondition right) { |
+ static _InvertedCondition _binary2( |
+ _InvertedCondition left, String operation, _InvertedCondition right) { |
// TODO(scheglov) conside merging with "_binary()" after testing |
return new _InvertedCondition( |
- 1 << 20, |
- "${left._source}${operation}${right._source}"); |
+ 1 << 20, "${left._source}${operation}${right._source}"); |
} |
/** |
* Adds enclosing parenthesis if the precedence of the [_InvertedCondition] if less than the |
* precedence of the expression we are going it to use in. |
*/ |
- static String _parenthesizeIfRequired(_InvertedCondition expr, |
- int newOperatorPrecedence) { |
+ static String _parenthesizeIfRequired( |
+ _InvertedCondition expr, int newOperatorPrecedence) { |
if (expr._precedence < newOperatorPrecedence) { |
return "(${expr._source})"; |
} |
@@ -1512,7 +1465,6 @@ class _InvertedCondition { |
new _InvertedCondition(2147483647, source); |
} |
- |
class _OrderedOperandsVisitor extends GeneralizingAstVisitor { |
final TokenType groupOperatorType; |
final List<Expression> operands; |