mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Stop using Element.unit directly.
R=brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org/2541873002 .
This commit is contained in:
parent
9a9e037e61
commit
2537784f92
|
@ -403,8 +403,8 @@ class EditDomainHandler implements RequestHandler {
|
|||
if (element != null) {
|
||||
// try CONVERT_METHOD_TO_GETTER
|
||||
if (element is ExecutableElement) {
|
||||
Refactoring refactoring =
|
||||
new ConvertMethodToGetterRefactoring(searchEngine, element);
|
||||
Refactoring refactoring = new ConvertMethodToGetterRefactoring(
|
||||
searchEngine, _getResolvedUnit, element);
|
||||
RefactoringStatus status = await refactoring.checkInitialConditions();
|
||||
if (!status.hasFatalError) {
|
||||
kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER);
|
||||
|
@ -437,11 +437,17 @@ class EditDomainHandler implements RequestHandler {
|
|||
return Response.DELAYED_RESPONSE;
|
||||
}
|
||||
|
||||
Future<CompilationUnit> _getResolvedUnit(Element element) {
|
||||
String path = element.source.fullName;
|
||||
return server.getResolvedCompilationUnit(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes [refactoringManager] with a new instance.
|
||||
*/
|
||||
void _newRefactoringManager() {
|
||||
refactoringManager = new _RefactoringManager(server, searchEngine);
|
||||
refactoringManager =
|
||||
new _RefactoringManager(server, _getResolvedUnit, searchEngine);
|
||||
}
|
||||
|
||||
static int _getNumberOfScanParseErrors(List<engine.AnalysisError> errors) {
|
||||
|
@ -515,6 +521,7 @@ class _RefactoringManager {
|
|||
const <RefactoringProblem>[];
|
||||
|
||||
final AnalysisServer server;
|
||||
final GetResolvedUnit getResolvedUnit;
|
||||
final SearchEngine searchEngine;
|
||||
StreamSubscription subscriptionToReset;
|
||||
|
||||
|
@ -531,7 +538,7 @@ class _RefactoringManager {
|
|||
Request request;
|
||||
EditGetRefactoringResult result;
|
||||
|
||||
_RefactoringManager(this.server, this.searchEngine) {
|
||||
_RefactoringManager(this.server, this.getResolvedUnit, this.searchEngine) {
|
||||
_reset();
|
||||
}
|
||||
|
||||
|
@ -723,8 +730,8 @@ class _RefactoringManager {
|
|||
if (element != null) {
|
||||
if (element is ExecutableElement) {
|
||||
_resetOnAnalysisStarted();
|
||||
refactoring =
|
||||
new ConvertMethodToGetterRefactoring(searchEngine, element);
|
||||
refactoring = new ConvertMethodToGetterRefactoring(
|
||||
searchEngine, getResolvedUnit, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -760,11 +767,8 @@ class _RefactoringManager {
|
|||
CompilationUnit unit = await server.getResolvedCompilationUnit(file);
|
||||
if (unit != null) {
|
||||
_resetOnAnalysisStarted();
|
||||
refactoring =
|
||||
new InlineMethodRefactoring(searchEngine, (Element element) async {
|
||||
String elementPath = element.source.fullName;
|
||||
return await server.getResolvedCompilationUnit(elementPath);
|
||||
}, unit, offset);
|
||||
refactoring = new InlineMethodRefactoring(
|
||||
searchEngine, getResolvedUnit, unit, offset);
|
||||
}
|
||||
}
|
||||
if (kind == RefactoringKind.MOVE_FILE) {
|
||||
|
|
|
@ -24,11 +24,13 @@ import 'package:analyzer/src/generated/source.dart';
|
|||
class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
|
||||
implements ConvertMethodToGetterRefactoring {
|
||||
final SearchEngine searchEngine;
|
||||
final GetResolvedUnit getResolvedUnit;
|
||||
final ExecutableElement element;
|
||||
|
||||
SourceChange change;
|
||||
|
||||
ConvertMethodToGetterRefactoringImpl(this.searchEngine, this.element);
|
||||
ConvertMethodToGetterRefactoringImpl(
|
||||
this.searchEngine, this.getResolvedUnit, this.element);
|
||||
|
||||
@override
|
||||
String get refactoringName => 'Convert Method To Getter';
|
||||
|
@ -114,7 +116,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
|
|||
}
|
||||
}
|
||||
|
||||
Future _updateElementReferences(Element element) async {
|
||||
Future<Null> _updateElementReferences(Element element) async {
|
||||
List<SearchMatch> matches = await searchEngine.searchReferences(element);
|
||||
List<SourceReference> references = getSourceReferences(matches);
|
||||
for (SourceReference reference in references) {
|
||||
|
@ -123,7 +125,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
|
|||
// prepare invocation
|
||||
MethodInvocation invocation;
|
||||
{
|
||||
CompilationUnit refUnit = refElement.unit;
|
||||
CompilationUnit refUnit = await getResolvedUnit(refElement);
|
||||
AstNode refNode =
|
||||
new NodeLocator(refRange.offset).searchWithin(refUnit);
|
||||
invocation = refNode.getAncestor((node) => node is MethodInvocation);
|
||||
|
|
|
@ -190,19 +190,13 @@ Set<String> _getNamesConflictingAt(AstNode node) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes with the resolved [CompilationUnit] that contains the [element].
|
||||
*/
|
||||
typedef Future<CompilationUnit> GetResolvedUnitContainingElement(
|
||||
Element element);
|
||||
|
||||
/**
|
||||
* [InlineMethodRefactoring] implementation.
|
||||
*/
|
||||
class InlineMethodRefactoringImpl extends RefactoringImpl
|
||||
implements InlineMethodRefactoring {
|
||||
final SearchEngine searchEngine;
|
||||
final GetResolvedUnitContainingElement getResolvedUnit;
|
||||
final GetResolvedUnit getResolvedUnit;
|
||||
final CompilationUnit unit;
|
||||
final int offset;
|
||||
CorrectionUtils utils;
|
||||
|
|
|
@ -30,6 +30,11 @@ import 'package:analyzer/file_system/file_system.dart';
|
|||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
|
||||
/**
|
||||
* Completes with the resolved [CompilationUnit] that contains the [element].
|
||||
*/
|
||||
typedef Future<CompilationUnit> GetResolvedUnit(Element element);
|
||||
|
||||
/**
|
||||
* [Refactoring] to convert getters into normal [MethodDeclaration]s.
|
||||
*/
|
||||
|
@ -52,9 +57,10 @@ abstract class ConvertMethodToGetterRefactoring implements Refactoring {
|
|||
* Returns a new [ConvertMethodToGetterRefactoring] instance for converting
|
||||
* [element] and all the corresponding hierarchy elements.
|
||||
*/
|
||||
factory ConvertMethodToGetterRefactoring(
|
||||
SearchEngine searchEngine, ExecutableElement element) {
|
||||
return new ConvertMethodToGetterRefactoringImpl(searchEngine, element);
|
||||
factory ConvertMethodToGetterRefactoring(SearchEngine searchEngine,
|
||||
GetResolvedUnit getResolvedUnit, ExecutableElement element) {
|
||||
return new ConvertMethodToGetterRefactoringImpl(
|
||||
searchEngine, getResolvedUnit, element);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,11 +254,8 @@ abstract class InlineMethodRefactoring implements Refactoring {
|
|||
/**
|
||||
* Returns a new [InlineMethodRefactoring] instance.
|
||||
*/
|
||||
factory InlineMethodRefactoring(
|
||||
SearchEngine searchEngine,
|
||||
GetResolvedUnitContainingElement getResolvedUnit,
|
||||
CompilationUnit unit,
|
||||
int offset) {
|
||||
factory InlineMethodRefactoring(SearchEngine searchEngine,
|
||||
GetResolvedUnit getResolvedUnit, CompilationUnit unit, int offset) {
|
||||
return new InlineMethodRefactoringImpl(
|
||||
searchEngine, getResolvedUnit, unit, offset);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,19 @@ library test.services.refactoring;
|
|||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/plugin/protocol/protocol.dart';
|
||||
import 'package:analysis_server/plugin/protocol/protocol.dart'
|
||||
show
|
||||
RefactoringProblem,
|
||||
RefactoringProblemSeverity,
|
||||
SourceChange,
|
||||
SourceEdit,
|
||||
SourceFileEdit;
|
||||
import 'package:analysis_server/src/services/correction/status.dart';
|
||||
import 'package:analysis_server/src/services/index/index.dart';
|
||||
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
|
||||
import 'package:analysis_server/src/services/search/search_engine_internal.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart' show Element;
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
@ -145,6 +152,14 @@ abstract class RefactoringTest extends AbstractSingleUnitTest {
|
|||
expect(actualCode, expectedCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes with a fully resolved unit that contains the [element].
|
||||
*/
|
||||
Future<CompilationUnit> getResolvedUnitWithElement(Element element) async {
|
||||
return element.context
|
||||
.resolveCompilationUnit(element.source, element.library);
|
||||
}
|
||||
|
||||
void indexTestUnit(String code) {
|
||||
resolveTestUnit(code);
|
||||
index.indexUnit(testUnit);
|
||||
|
|
|
@ -6,7 +6,8 @@ library test.services.refactoring.convert_method_to_getter;
|
|||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/plugin/protocol/protocol.dart' hide ElementKind;
|
||||
import 'package:analysis_server/plugin/protocol/protocol.dart'
|
||||
show RefactoringProblemSeverity, SourceChange;
|
||||
import 'package:analysis_server/src/services/correction/status.dart';
|
||||
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
|
@ -205,7 +206,8 @@ void test() {}
|
|||
}
|
||||
|
||||
void _createRefactoringForElement(ExecutableElement element) {
|
||||
refactoring = new ConvertMethodToGetterRefactoring(searchEngine, element);
|
||||
refactoring = new ConvertMethodToGetterRefactoring(
|
||||
searchEngine, getResolvedUnitWithElement, element);
|
||||
}
|
||||
|
||||
void _createRefactoringForString(String search) {
|
||||
|
|
|
@ -1713,6 +1713,6 @@ main(bool p, bool p2, bool p3) {
|
|||
void _createRefactoring(String search) {
|
||||
int offset = findOffset(search);
|
||||
refactoring = new InlineMethodRefactoring(
|
||||
searchEngine, (element) async => element.unit, testUnit, offset);
|
||||
searchEngine, getResolvedUnitWithElement, testUnit, offset);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue