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

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

Issue 2969833002: Convert DartChangeBuilder to use AnalysisSession (Closed)
Patch Set: Created 3 years, 6 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/fix_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index 1c0d97953c6b259c4c29847df19edbca9219e88b..c2dfd1b7e23ed19bf6f355a9a6f0c61fd7fe79d3 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -16,6 +16,7 @@ import 'package:analysis_server/src/services/correction/namespace.dart';
import 'package:analysis_server/src/services/correction/strings.dart';
import 'package:analysis_server/src/services/correction/util.dart';
import 'package:analysis_server/src/services/search/hierarchy.dart';
+import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/standard_resolution_map.dart';
import 'package:analyzer/dart/ast/token.dart';
@@ -152,6 +153,11 @@ class FixProcessor {
*/
String get eol => utils.endOfLine;
+ /**
+ * Return the analysis session to be used to create the change builder.
+ */
+ AnalysisSession get session => driver.currentSession;
+
TypeProvider get typeProvider {
if (_typeProvider == null) {
_typeProvider = unitElement.context.typeProvider;
@@ -446,7 +452,7 @@ class FixProcessor {
FunctionBody body = node.getAncestor((n) => n is FunctionBody);
if (body != null && body.keyword == null) {
TypeProvider typeProvider = await this.typeProvider;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.convertFunctionFromSyncToAsync(body, typeProvider);
});
@@ -460,7 +466,7 @@ class FixProcessor {
// prepare environment
String prefix = utils.getIndent(1);
String prefix2 = utils.getIndent(2);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(insertOffset, (DartEditBuilder builder) {
builder.selectHere();
@@ -533,7 +539,7 @@ class FixProcessor {
}
Source targetSource = targetElement.source;
String targetFile = targetSource.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile,
(DartFileEditBuilder builder) {
builder.addInsertion(targetOffset, (DartEditBuilder builder) {
@@ -550,7 +556,7 @@ class FixProcessor {
_addFixFromBuilder(
changeBuilder, DartFixKind.ADD_MISSING_PARAMETER_REQUIRED);
if (optionalParameters.isEmpty) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile,
(DartFileEditBuilder builder) {
builder.addInsertion(targetOffset, (DartEditBuilder builder) {
@@ -601,7 +607,7 @@ class FixProcessor {
final List<Expression> args = argumentList.arguments;
int offset =
args.isEmpty ? argumentList.leftParenthesis.end : args.last.end;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(offset, (DartEditBuilder builder) {
if (args.isNotEmpty) {
@@ -642,7 +648,7 @@ class FixProcessor {
Position exitPosition = new Position(file, token.offset - 1);
String indent = utils.getIndent(1);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(
range.startLength(token, 0), '@override$eol$indent');
@@ -652,7 +658,7 @@ class FixProcessor {
}
Future<Null> _addFix_boolInsteadOfBoolean() async {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.error(error), 'bool');
});
@@ -662,7 +668,7 @@ class FixProcessor {
Future<Null> _addFix_canBeNullAfterNullAware() async {
AstNode node = coveredNode;
if (node is Expression) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
AstNode parent = node.parent;
while (parent != null) {
@@ -693,7 +699,7 @@ class FixProcessor {
Expression initializer = coveredNode;
DartType newType = initializer.bestType;
if (newType is InterfaceType || newType is FunctionType) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file,
(DartFileEditBuilder builder) {
builder.addReplacement(range.node(typeNode),
@@ -719,7 +725,7 @@ class FixProcessor {
}
InstanceCreationExpression childArg = getChildWidget(namedExp, false);
if (childArg != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
convertFlutterChildToChildren2(
builder,
@@ -737,7 +743,7 @@ class FixProcessor {
}
ListLiteral listArg = getChildList(namedExp);
if (listArg != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleInsertion(namedExp.offset + 'child'.length, 'ren');
if (listArg.typeArguments == null) {
@@ -812,7 +818,7 @@ class FixProcessor {
if (offset < 0) {
return;
}
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(filePath, (DartFileEditBuilder builder) {
builder.addInsertion(offset, (DartEditBuilder builder) {
builder.write(prefix);
@@ -854,7 +860,7 @@ class FixProcessor {
// prepare location for a new constructor
ClassMemberLocation targetLocation =
utils.prepareNewConstructorLocation(classDeclaration);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
builder.write(targetLocation.prefix);
@@ -897,7 +903,7 @@ class FixProcessor {
utils.prepareNewConstructorLocation(targetTypeNode);
Source targetSource = targetElement.source;
String targetFile = targetSource.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile, (DartFileEditBuilder builder) {
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
builder.write(targetLocation.prefix);
@@ -950,7 +956,7 @@ class FixProcessor {
ClassMemberLocation targetLocation =
utils.prepareNewConstructorLocation(targetTypeNode);
String targetFile = targetElement.source.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
builder.write(targetLocation.prefix);
@@ -1000,7 +1006,7 @@ class FixProcessor {
prefix = ', ';
}
String proposalName = _getConstructorProposalName(superConstructor);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(insertOffset, (DartEditBuilder builder) {
builder.write(prefix);
@@ -1058,7 +1064,7 @@ class FixProcessor {
ClassMemberLocation targetLocation =
utils.prepareNewConstructorLocation(targetClassNode);
String proposalName = _getConstructorProposalName(superConstructor);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
void writeParameters(bool includeType) {
@@ -1162,7 +1168,7 @@ class FixProcessor {
// build field source
Source targetSource = targetClassElement.source;
String targetFile = targetSource.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile, (DartFileEditBuilder builder) {
Expression fieldTypeNode = climbPropertyAccess(nameNode);
DartType fieldType = _inferUndefinedExpressionType(fieldTypeNode);
@@ -1200,7 +1206,7 @@ class FixProcessor {
//
// Add proposal.
//
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
DartType fieldType = parameter.type?.type;
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
@@ -1319,7 +1325,7 @@ class FixProcessor {
// build method source
Source targetSource = targetClassElement.source;
String targetFile = targetSource.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile, (DartFileEditBuilder builder) {
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
Expression fieldTypeNode = climbPropertyAccess(nameNode);
@@ -1346,7 +1352,7 @@ class FixProcessor {
String file = source.fullName;
if (isAbsolute(file) && AnalysisEngine.isDartFileName(file)) {
String libName = _computeLibraryName(file);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(source.fullName,
(DartFileEditBuilder builder) {
builder.addSimpleInsertion(0, 'library $libName;$eol$eol');
@@ -1370,7 +1376,7 @@ class FixProcessor {
if (assignment.leftHandSide == node &&
assignment.operator.type == TokenType.EQ &&
assignment.parent is ExpressionStatement) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleInsertion(node.offset, 'var ');
});
@@ -1395,7 +1401,7 @@ class FixProcessor {
return;
}
// build variable declaration source
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(target.offset, (DartEditBuilder builder) {
builder.writeLocalVariableDeclaration(name,
@@ -1436,7 +1442,7 @@ class FixProcessor {
int numElements = elements.length;
int insertOffset = targetClass.end - 1;
String prefix = utils.getIndent(1);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(insertOffset, (DartEditBuilder builder) {
// TODO(brianwilkerson) Compare with builder.writeOverrideOfInheritedMember
@@ -1555,7 +1561,7 @@ class FixProcessor {
// prepare environment
String prefix = utils.getIndent(1);
int insertOffset = targetClass.end - 1;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(insertOffset, (DartEditBuilder builder) {
builder.selectHere();
@@ -1580,7 +1586,7 @@ class FixProcessor {
Source source = partDirective.uriSource;
if (source != null) {
String libName = unitLibraryElement.name;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(source.fullName,
(DartFileEditBuilder builder) {
// TODO(brianwilkerson) Consider using the URI rather than name
@@ -1596,7 +1602,7 @@ class FixProcessor {
// prepare the existing type
TypeAnnotation typeName = node.getAncestor((n) => n is TypeAnnotation);
TypeProvider typeProvider = this.typeProvider;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.replaceTypeWithFuture(typeName, typeProvider);
});
@@ -1605,7 +1611,7 @@ class FixProcessor {
Future<Null> _addFix_importLibrary(FixKind kind, Source library) async {
String libraryUri = getLibrarySourceUri(unitLibraryElement, library);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.importLibraries([library]);
});
@@ -1637,7 +1643,7 @@ class FixProcessor {
// may be apply prefix
PrefixElement prefix = imp.prefix;
if (prefix != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(
range.startLength(node, 0), '${prefix.displayName}.');
@@ -1667,7 +1673,7 @@ class FixProcessor {
int offset = showCombinator.offset;
int length = showCombinator.end - offset;
String libraryFile = unitLibraryElement.source.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(libraryFile,
(DartFileEditBuilder builder) {
builder.addSimpleReplacement(
@@ -1751,7 +1757,7 @@ class FixProcessor {
return;
}
int insertOffset = error.offset + error.length;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleInsertion(insertOffset, ';');
});
@@ -1762,7 +1768,7 @@ class FixProcessor {
Future<Null> _addFix_isNotNull() async {
if (coveredNode is IsExpression) {
IsExpression isExpression = coveredNode as IsExpression;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder
.addReplacement(range.endEnd(isExpression.expression, isExpression),
@@ -1777,7 +1783,7 @@ class FixProcessor {
Future<Null> _addFix_isNull() async {
if (coveredNode is IsExpression) {
IsExpression isExpression = coveredNode as IsExpression;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder
.addReplacement(range.endEnd(isExpression.expression, isExpression),
@@ -1796,7 +1802,7 @@ class FixProcessor {
return;
}
String className = enclosingClass.name.name;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleInsertion(
enclosingClass.classKeyword.offset, 'abstract ');
@@ -1825,7 +1831,7 @@ class FixProcessor {
Token keywordToken = declarationList.keyword;
if (declarationList.variables.length == 1 &&
keywordToken.keyword == Keyword.FINAL) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file,
(DartFileEditBuilder builder) {
if (declarationList.type != null) {
@@ -1849,7 +1855,7 @@ class FixProcessor {
}
Future<Null> _addFix_nonBoolCondition_addNotNull() async {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleInsertion(error.offset + error.length, ' != null');
});
@@ -1860,7 +1866,7 @@ class FixProcessor {
final awaitExpression = node;
if (awaitExpression is AwaitExpression) {
final awaitToken = awaitExpression.awaitKeyword;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.startStart(awaitToken, awaitToken.next));
});
@@ -1874,7 +1880,7 @@ class FixProcessor {
AstNode parent = coveredNode.parent;
if (parent is BinaryExpression) {
if (parent.rightOperand == coveredNode) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.endEnd(parent.leftOperand, coveredNode));
});
@@ -1892,7 +1898,7 @@ class FixProcessor {
if (statementsToRemove.isNotEmpty) {
SourceRange rangeToRemove =
utils.getLinesRangeStatements(statementsToRemove);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(rangeToRemove);
});
@@ -1901,7 +1907,7 @@ class FixProcessor {
} else if (coveringNode is Statement) {
SourceRange rangeToRemove =
utils.getLinesRangeStatements(<Statement>[coveringNode]);
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(rangeToRemove);
});
@@ -1912,13 +1918,13 @@ class FixProcessor {
Future<Null> _addFix_removeEmptyStatement() async {
EmptyStatement emptyStatement = node;
if (emptyStatement.parent is Block) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(utils.getLinesRange(range.node(emptyStatement)));
});
_addFixFromBuilder(changeBuilder, DartFixKind.REMOVE_EMPTY_STATEMENT);
} else {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(
range.endEnd(emptyStatement.beginToken.previous, emptyStatement),
@@ -1935,7 +1941,7 @@ class FixProcessor {
if (ancestor == null) {
return;
}
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.endEnd(ancestor.name, ancestor.initializer));
});
@@ -1947,7 +1953,7 @@ class FixProcessor {
if (node is InterpolationExpression) {
Token right = node.rightBracket;
if (node.expression != null && right != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(
range.startStart(node, node.expression), r'$');
@@ -1963,7 +1969,7 @@ class FixProcessor {
MethodDeclaration declaration =
node.getAncestor((node) => node is MethodDeclaration);
if (declaration != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(utils.getLinesRange(range.node(declaration)));
});
@@ -1977,7 +1983,7 @@ class FixProcessor {
SimpleIdentifier name = method.name;
FunctionBody body = method.body;
if (name != null && body != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.endStart(name, body), ' ');
});
@@ -1991,7 +1997,7 @@ class FixProcessor {
if (node is SimpleIdentifier && node.parent is MethodInvocation) {
MethodInvocation invocation = node.parent as MethodInvocation;
if (invocation.methodName == node && invocation.target != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.endEnd(node, invocation));
});
@@ -2007,13 +2013,13 @@ class FixProcessor {
: node.getAncestor((node) => node is ThisExpression);
final parent = thisExpression.parent;
if (parent is PropertyAccess) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.startEnd(parent, parent.operator));
});
_addFixFromBuilder(changeBuilder, DartFixKind.REMOVE_THIS_EXPRESSION);
} else if (parent is MethodInvocation) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.startEnd(parent, parent.operator));
});
@@ -2024,7 +2030,7 @@ class FixProcessor {
Future<Null> _addFix_removeTypeName() async {
final TypeName type = node.getAncestor((node) => node is TypeName);
if (type != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.startStart(type, type.endToken.next));
});
@@ -2040,7 +2046,7 @@ class FixProcessor {
Expression expression = asExpression.expression;
int expressionPrecedence = getExpressionPrecedence(expression);
// remove 'as T' from 'e as T'
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(range.endEnd(expression, asExpression));
_removeEnclosingParentheses(builder, asExpression, expressionPrecedence);
@@ -2053,7 +2059,7 @@ class FixProcessor {
AstNode catchClause = node.parent;
if (catchClause is CatchClause &&
catchClause.exceptionParameter == node) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(
range.startStart(catchClause.catchKeyword, catchClause.body));
@@ -2070,7 +2076,7 @@ class FixProcessor {
if (catchClause is CatchClause &&
catchClause.stackTraceParameter == node &&
catchClause.exceptionParameter != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder
.addDeletion(range.endEnd(catchClause.exceptionParameter, node));
@@ -2089,7 +2095,7 @@ class FixProcessor {
return;
}
// remove the whole line with import
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addDeletion(utils.getLinesRange(range.node(importDirective)));
});
@@ -2097,7 +2103,7 @@ class FixProcessor {
}
Future<Null> _addFix_replaceVarWithDynamic() async {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.error(error), 'dynamic');
});
@@ -2120,7 +2126,7 @@ class FixProcessor {
if (thenStatement is ExpressionStatement) {
final expression = thenStatement.expression.unParenthesized;
if (expression is AssignmentExpression) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addReplacement(range.node(ifStatement),
(DartEditBuilder builder) {
@@ -2139,7 +2145,7 @@ class FixProcessor {
Future<Null> _addFix_replaceWithConstInstanceCreation() async {
if (coveredNode is InstanceCreationExpression) {
var instanceCreation = coveredNode as InstanceCreationExpression;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(
range.token(instanceCreation.keyword), 'const');
@@ -2152,7 +2158,7 @@ class FixProcessor {
final FunctionTypedFormalParameter functionTyped =
node.getAncestor((node) => node is FunctionTypedFormalParameter);
if (functionTyped != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.node(functionTyped),
utils.getNodeText(functionTyped.identifier));
@@ -2168,7 +2174,7 @@ class FixProcessor {
node.getAncestor((node) => node is InstanceCreationExpression);
final InterfaceType type = instanceCreation.staticType;
final generics = instanceCreation.constructorName.type.typeArguments;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addReplacement(range.node(instanceCreation),
(DartEditBuilder builder) {
@@ -2192,7 +2198,7 @@ class FixProcessor {
return;
}
Future<Null> addFixOfExpression(InvocationExpression expression) async {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addReplacement(range.node(ancestor), (DartEditBuilder builder) {
if (expression is MethodInvocation && expression.target != null) {
@@ -2259,7 +2265,7 @@ class FixProcessor {
if (finder._element != null) {
String closestName = finder._element.name;
if (closestName != null) {
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.node(node), closestName);
});
@@ -2322,7 +2328,7 @@ class FixProcessor {
// if we have close enough element, suggest to use it
if (finder._element != null) {
String closestName = finder._element.name;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.node(node), closestName);
});
@@ -2353,7 +2359,7 @@ class FixProcessor {
sourcePrefix = '$eol$eol';
utils.targetClassElement = null;
// build method source
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addInsertion(insertOffset, (DartEditBuilder builder) {
builder.write(sourcePrefix);
@@ -2414,7 +2420,7 @@ class FixProcessor {
// If we have a close enough element, suggest to use it.
if (finder._element != null) {
String closestName = finder._element.name;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
builder.addSimpleReplacement(range.node(node), closestName);
});
@@ -2474,7 +2480,7 @@ class FixProcessor {
utils.prepareNewMethodLocation(targetClassNode);
String targetFile = targetElement.source.fullName;
// build method source
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile,
(DartFileEditBuilder builder) {
builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
@@ -2540,7 +2546,7 @@ class FixProcessor {
lastRequiredParameter = parameter;
}
}
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
// append new field formal initializers
if (lastRequiredParameter != null) {
@@ -2563,7 +2569,7 @@ class FixProcessor {
n.offset == errorOffset &&
n.length == errorLength) {
Expression target = (n as MethodInvocation).target.unParenthesized;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
// replace "/" with "~/"
BinaryExpression binary = target as BinaryExpression;
@@ -2588,7 +2594,7 @@ class FixProcessor {
Element declaringElement = element.enclosingElement;
if (declaringElement is ClassElement) {
DartType declaringType = declaringElement.type;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
// replace "target" with class name
builder.addReplacement(range.node(target), (DartEditBuilder builder) {
@@ -2648,7 +2654,7 @@ class FixProcessor {
Element target) async {
// build method source
String targetFile = targetSource.fullName;
- DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
await changeBuilder.addFileEdit(targetFile, (DartFileEditBuilder builder) {
builder.addInsertion(insertOffset, (DartEditBuilder builder) {
builder.write(sourcePrefix);

Powered by Google App Engine
This is Rietveld 408576698