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

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/extract_method.dart

Issue 3007493002: Remove most of the remaining references to AnalysisContext (Closed)
Patch Set: Created 3 years, 4 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/refactoring/extract_method.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
index 032924c039a313d60366084c55403fe10ddfd9db..55e8c10b503884a1a7a889ccb6b647f96bd2c54b 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
@@ -16,6 +16,7 @@ import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
import 'package:analysis_server/src/services/refactoring/rename_class_member.dart';
import 'package:analysis_server/src/services/refactoring/rename_unit_member.dart';
import 'package:analysis_server/src/services/search/search_engine.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';
@@ -24,10 +25,10 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/element/ast_provider.dart';
-import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/resolver.dart' show ExitDetector;
import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/generated/type_system.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
const String _TOKEN_SEPARATOR = '\uFFFF';
@@ -76,7 +77,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
final CompilationUnit unit;
final int selectionOffset;
final int selectionLength;
- AnalysisContext context;
+ AnalysisSession session;
CompilationUnitElement unitElement;
LibraryElement libraryElement;
SourceRange selectionRange;
@@ -123,7 +124,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
this.selectionOffset, this.selectionLength) {
unitElement = unit.element;
libraryElement = unitElement.library;
- context = libraryElement.context;
+ session = astProvider.driver.currentSession;
selectionRange = new SourceRange(selectionOffset, selectionLength);
utils = new CorrectionUtils(unit);
}
@@ -195,17 +196,17 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
}
@override
- Future<RefactoringStatus> checkInitialConditions() {
+ Future<RefactoringStatus> checkInitialConditions() async {
RefactoringStatus result = new RefactoringStatus();
// selection
result.addStatus(_checkSelection());
if (result.hasFatalError) {
- return new Future.value(result);
+ return result;
}
// prepare parts
- result.addStatus(_initializeParameters());
+ result.addStatus(await _initializeParameters());
_initializeHasAwait();
- _initializeReturnType();
+ await _initializeReturnType();
// occurrences
_initializeOccurrences();
_prepareOffsetsLengths();
@@ -221,10 +222,9 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
String message = format(
'Cannot extract closure as method, it references {0} external variable(s).',
_parameters.length);
- RefactoringStatus result = new RefactoringStatus.fatal(message);
- return new Future.value(result);
+ return new RefactoringStatus.fatal(message);
}
- return new Future.value(result);
+ return result;
}
@override
@@ -667,7 +667,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
* Prepares information about used variables, which should be turned into
* parameters.
*/
- RefactoringStatus _initializeParameters() {
+ Future<RefactoringStatus> _initializeParameters() async {
_parameters.clear();
_parametersMap.clear();
_parameterReferencesMap.clear();
@@ -687,7 +687,8 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
}
// maybe ends with "return" statement
if (_selectionStatements != null) {
- _ReturnTypeComputer returnTypeComputer = new _ReturnTypeComputer(context);
+ _ReturnTypeComputer returnTypeComputer =
+ new _ReturnTypeComputer(await session.typeSystem);
_selectionStatements.forEach((statement) {
statement.accept(returnTypeComputer);
});
@@ -723,8 +724,8 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
return result;
}
- void _initializeReturnType() {
- InterfaceType futureType = context.typeProvider.futureType;
+ Future<Null> _initializeReturnType() async {
+ InterfaceType futureType = (await session.typeProvider).futureType;
if (_selectionFunctionExpression != null) {
variableType = '';
returnType = '';
@@ -1262,11 +1263,11 @@ class _Occurrence {
}
class _ReturnTypeComputer extends RecursiveAstVisitor {
- final AnalysisContext context;
+ final TypeSystem typeSystem;
DartType returnType;
- _ReturnTypeComputer(this.context);
+ _ReturnTypeComputer(this.typeSystem);
@override
visitBlockFunctionBody(BlockFunctionBody node) {}
@@ -1290,7 +1291,7 @@ class _ReturnTypeComputer extends RecursiveAstVisitor {
if (returnType is InterfaceType && type is InterfaceType) {
returnType = InterfaceType.getSmartLeastUpperBound(returnType, type);
} else {
- returnType = context.typeSystem.getLeastUpperBound(returnType, type);
+ returnType = typeSystem.getLeastUpperBound(returnType, type);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698