Remove ChangeSet from engine.dart

Change-Id: I289c5edd0c3e52a873013f8c52d8202bf29cf3be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2019-10-14 17:45:56 +00:00 committed by commit-bot@chromium.org
parent aeacf565ab
commit dc0db066e6
7 changed files with 59 additions and 274 deletions

View file

@ -914,14 +914,14 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
nd.AnalysisDriver analysisDriver = analysisServer.driverMap[contextFolder];
if (analysisDriver != null) {
changeSet.addedSources.forEach((source) {
analysisDriver.addFile(source.fullName);
changeSet.addedFiles.forEach((path) {
analysisDriver.addFile(path);
});
changeSet.changedSources.forEach((source) {
analysisDriver.changeFile(source.fullName);
changeSet.changedFiles.forEach((path) {
analysisDriver.changeFile(path);
});
changeSet.removedSources.forEach((source) {
analysisDriver.removeFile(source.fullName);
changeSet.removedFiles.forEach((path) {
analysisDriver.removeFile(path);
});
}
}

View file

@ -42,6 +42,41 @@ import 'package:path/path.dart' as pathos;
import 'package:watcher/watcher.dart';
import 'package:yaml/yaml.dart';
/// An indication of which files have been added, changed, removed, or deleted.
///
/// No file should be added to the change set more than once, either with the
/// same or a different kind of change. It does not make sense, for example,
/// for a file to be both added and removed.
class ChangeSet {
/// A list containing paths of added files.
final List<String> addedFiles = [];
/// A list containing paths of changed files.
final List<String> changedFiles = [];
/// A list containing paths of removed files.
final List<String> removedFiles = [];
/// Return `true` if this change set does not contain any changes.
bool get isEmpty =>
addedFiles.isEmpty && changedFiles.isEmpty && removedFiles.isEmpty;
/// Record that the file with the specified [path] has been added.
void addedSource(String path) {
addedFiles.add(path);
}
/// Record that the file with the specified [path] has been changed.
void changedSource(String path) {
changedFiles.add(path);
}
/// Record that the file with the specified [path] has been removed.
void removedSource(String path) {
removedFiles.add(path);
}
}
/**
* Information tracked by the [ContextManager] for each context.
*/
@ -770,7 +805,7 @@ class ContextManagerImpl implements ContextManager {
ChangeSet changeSet = new ChangeSet();
excludedSources.forEach((String path, Source source) {
info.sources.remove(path);
changeSet.removedSource(source);
changeSet.removedSource(path);
});
callbacks.applyChangesToContext(info.folder, changeSet);
}
@ -819,7 +854,7 @@ class ContextManagerImpl implements ContextManager {
}
// do add the file
Source source = createSourceInContext(info.analysisDriver, child);
changeSet.addedSource(source);
changeSet.addedSource(child.path);
info.sources[path] = source;
} else if (child is Folder) {
_addPreviouslyExcludedSources(info, changeSet, child, oldExcludedPaths);
@ -854,7 +889,7 @@ class ContextManagerImpl implements ContextManager {
if (child is File) {
if (_shouldFileBeAnalyzed(child)) {
Source source = createSourceInContext(info.analysisDriver, child);
changeSet.addedSource(source);
changeSet.addedSource(child.path);
info.sources[path] = source;
}
} else if (child is Folder) {
@ -1277,7 +1312,7 @@ class ContextManagerImpl implements ContextManager {
ChangeSet changeSet = new ChangeSet();
extractedSources.forEach((path, source) {
newInfo.sources[path] = source;
changeSet.addedSource(source);
changeSet.addedSource(path);
});
callbacks.applyChangesToContext(newFolder, changeSet);
}
@ -1286,7 +1321,7 @@ class ContextManagerImpl implements ContextManager {
ChangeSet changeSet = new ChangeSet();
extractedSources.forEach((path, source) {
oldInfo.sources.remove(path);
changeSet.removedSource(source);
changeSet.removedSource(path);
});
callbacks.applyChangesToContext(oldInfo.folder, changeSet);
}
@ -1568,7 +1603,7 @@ class ContextManagerImpl implements ContextManager {
ChangeSet changeSet = new ChangeSet();
info.sources.forEach((path, source) {
parentInfo.sources[path] = source;
changeSet.addedSource(source);
changeSet.addedSource(path);
});
callbacks.applyChangesToContext(parentInfo.folder, changeSet);
}

View file

@ -645,14 +645,14 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
nd.AnalysisDriver analysisDriver = analysisServer.driverMap[contextFolder];
if (analysisDriver != null) {
changeSet.addedSources.forEach((source) {
analysisDriver.addFile(source.fullName);
changeSet.addedFiles.forEach((path) {
analysisDriver.addFile(path);
});
changeSet.changedSources.forEach((source) {
analysisDriver.changeFile(source.fullName);
changeSet.changedFiles.forEach((path) {
analysisDriver.changeFile(path);
});
changeSet.removedSources.forEach((source) {
analysisDriver.removeFile(source.fullName);
changeSet.removedFiles.forEach((path) {
analysisDriver.removeFile(path);
});
}
}

View file

@ -2525,14 +2525,14 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
AnalysisDriver driver = driverMap[contextFolder.path];
if (driver != null) {
changeSet.addedSources.forEach((source) {
driver.addFile(source.fullName);
changeSet.addedFiles.forEach((source) {
driver.addFile(source);
});
changeSet.changedSources.forEach((source) {
driver.changeFile(source.fullName);
changeSet.changedFiles.forEach((source) {
driver.changeFile(source);
});
changeSet.removedSources.forEach((source) {
driver.removeFile(source.fullName);
changeSet.removedFiles.forEach((source) {
driver.removeFile(source);
});
}
}

View file

@ -88,11 +88,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
return _typeSystem ??= Dart2TypeSystem(typeProvider);
}
@override
void applyChanges(ChangeSet changeSet) {
throw UnimplementedError();
}
/**
* Create an analysis cache based on the given source [factory].
*/

View file

@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:collection';
import 'dart:typed_data';
import 'package:analyzer/dart/analysis/features.dart';
@ -96,12 +95,6 @@ abstract class AnalysisContext {
/// Return a type system for this context.
TypeSystem get typeSystem;
/// Apply the changes specified by the given [changeSet] to this context. Any
/// analysis results that have been invalidated by these changes will be
/// removed.
/// TODO(scheglov) This method is referenced by the internal indexer tool.
void applyChanges(ChangeSet changeSet);
}
/// The entry point for the functionality provided by the analysis engine. There
@ -875,193 +868,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
static bool _analyzeNoFunctionBodies(Source _) => false;
}
/// An indication of which sources have been added, changed, removed, or deleted.
/// In the case of a changed source, there are multiple ways of indicating the
/// nature of the change.
///
/// No source should be added to the change set more than once, either with the
/// same or a different kind of change. It does not make sense, for example, for
/// a source to be both added and removed, and it is redundant for a source to be
/// marked as changed in its entirety and changed in some specific range.
class ChangeSet {
/// A list containing the sources that have been added.
final List<Source> addedSources = new List<Source>();
/// A list containing the sources that have been changed.
final List<Source> changedSources = new List<Source>();
/// A table mapping the sources whose content has been changed to the current
/// content of those sources.
Map<Source, String> _changedContent = new HashMap<Source, String>();
/// A table mapping the sources whose content has been changed within a single
/// range to the current content of those sources and information about the
/// affected range.
final HashMap<Source, ChangeSet_ContentChange> changedRanges =
new HashMap<Source, ChangeSet_ContentChange>();
/// A list containing the sources that have been removed.
final List<Source> removedSources = new List<Source>();
/// A list containing the source containers specifying additional sources that
/// have been removed.
final List<SourceContainer> removedContainers = new List<SourceContainer>();
/// Return a table mapping the sources whose content has been changed to the
/// current content of those sources.
Map<Source, String> get changedContents => _changedContent;
/// Return `true` if this change set does not contain any changes.
bool get isEmpty =>
addedSources.isEmpty &&
changedSources.isEmpty &&
_changedContent.isEmpty &&
changedRanges.isEmpty &&
removedSources.isEmpty &&
removedContainers.isEmpty;
/// Record that the specified [source] has been added and that its content is
/// the default contents of the source.
void addedSource(Source source) {
addedSources.add(source);
}
/// Record that the specified [source] has been changed and that its content is
/// the given [contents].
void changedContent(Source source, String contents) {
_changedContent[source] = contents;
}
/// Record that the specified [source] has been changed and that its content is
/// the given [contents]. The [offset] is the offset into the current contents.
/// The [oldLength] is the number of characters in the original contents that
/// were replaced. The [newLength] is the number of characters in the
/// replacement text.
void changedRange(Source source, String contents, int offset, int oldLength,
int newLength) {
changedRanges[source] =
new ChangeSet_ContentChange(contents, offset, oldLength, newLength);
}
/// Record that the specified [source] has been changed. If the content of the
/// source was previously overridden, this has no effect (the content remains
/// overridden). To cancel (or change) the override, use [changedContent]
/// instead.
void changedSource(Source source) {
changedSources.add(source);
}
/// Record that the specified source [container] has been removed.
void removedContainer(SourceContainer container) {
if (container != null) {
removedContainers.add(container);
}
}
/// Record that the specified [source] has been removed.
void removedSource(Source source) {
if (source != null) {
removedSources.add(source);
}
}
@override
String toString() {
StringBuffer buffer = new StringBuffer();
bool needsSeparator =
_appendSources(buffer, addedSources, false, "addedSources");
needsSeparator = _appendSources(
buffer, changedSources, needsSeparator, "changedSources");
needsSeparator = _appendSources2(
buffer, _changedContent, needsSeparator, "changedContent");
needsSeparator =
_appendSources2(buffer, changedRanges, needsSeparator, "changedRanges");
needsSeparator = _appendSources(
buffer, removedSources, needsSeparator, "removedSources");
int count = removedContainers.length;
if (count > 0) {
if (removedSources.isEmpty) {
if (needsSeparator) {
buffer.write("; ");
}
buffer.write("removed: from ");
buffer.write(count);
buffer.write(" containers");
} else {
buffer.write(", and more from ");
buffer.write(count);
buffer.write(" containers");
}
}
return buffer.toString();
}
/// Append the given [sources] to the given [buffer], prefixed with the given
/// [label] and a separator if [needsSeparator] is `true`. Return `true` if
/// future lists of sources will need a separator.
bool _appendSources(StringBuffer buffer, List<Source> sources,
bool needsSeparator, String label) {
if (sources.isEmpty) {
return needsSeparator;
}
if (needsSeparator) {
buffer.write("; ");
}
buffer.write(label);
String prefix = " ";
for (Source source in sources) {
buffer.write(prefix);
buffer.write(source.fullName);
prefix = ", ";
}
return true;
}
/// Append the given [sources] to the given [builder], prefixed with the given
/// [label] and a separator if [needsSeparator] is `true`. Return `true` if
/// future lists of sources will need a separator.
bool _appendSources2(StringBuffer buffer, Map<Source, dynamic> sources,
bool needsSeparator, String label) {
if (sources.isEmpty) {
return needsSeparator;
}
if (needsSeparator) {
buffer.write("; ");
}
buffer.write(label);
String prefix = " ";
for (Source source in sources.keys.toSet()) {
buffer.write(prefix);
buffer.write(source.fullName);
prefix = ", ";
}
return true;
}
}
/// A change to the content of a source.
class ChangeSet_ContentChange {
/// The new contents of the source.
final String contents;
/// The offset into the current contents.
final int offset;
/// The number of characters in the original contents that were replaced
final int oldLength;
/// The number of characters in the replacement text.
final int newLength;
/// Initialize a newly created change object to represent a change to the
/// content of a source. The [contents] is the new contents of the source. The
/// [offset] is the offset into the current contents. The [oldLength] is the
/// number of characters in the original contents that were replaced. The
/// [newLength] is the number of characters in the replacement text.
ChangeSet_ContentChange(
this.contents, this.offset, this.oldLength, this.newLength);
}
/// Additional behavior for an analysis context that is required by internal
/// users of the context.
abstract class InternalAnalysisContext implements AnalysisContext {

View file

@ -37,7 +37,6 @@ import 'test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ChangeSetTest);
defineReflectiveTests(EnclosedScopeTest);
defineReflectiveTests(ErrorResolverTest);
defineReflectiveTests(LibraryImportScopeTest);
@ -59,56 +58,6 @@ void _fail(String message) {
fail(message);
}
@reflectiveTest
class ChangeSetTest {
void test_changedContent() {
TestSource source = new TestSource();
String content = "";
ChangeSet changeSet = new ChangeSet();
changeSet.changedContent(source, content);
expect(changeSet.addedSources, hasLength(0));
expect(changeSet.changedSources, hasLength(0));
Map<Source, String> map = changeSet.changedContents;
expect(map, hasLength(1));
expect(map[source], same(content));
expect(changeSet.changedRanges, hasLength(0));
expect(changeSet.removedSources, hasLength(0));
expect(changeSet.removedContainers, hasLength(0));
}
void test_changedRange() {
TestSource source = new TestSource();
String content = "";
ChangeSet changeSet = new ChangeSet();
changeSet.changedRange(source, content, 1, 2, 3);
expect(changeSet.addedSources, hasLength(0));
expect(changeSet.changedSources, hasLength(0));
expect(changeSet.changedContents, hasLength(0));
Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges;
expect(map, hasLength(1));
ChangeSet_ContentChange change = map[source];
expect(change, isNotNull);
expect(change.contents, content);
expect(change.offset, 1);
expect(change.oldLength, 2);
expect(change.newLength, 3);
expect(changeSet.removedSources, hasLength(0));
expect(changeSet.removedContainers, hasLength(0));
}
void test_toString() {
ChangeSet changeSet = new ChangeSet();
changeSet.addedSource(new TestSource());
changeSet.changedSource(new TestSource());
changeSet.changedContent(new TestSource(), "");
changeSet.changedRange(new TestSource(), "", 0, 0, 0);
changeSet.removedSource(new TestSource());
changeSet
.removedContainer(new SourceContainer_ChangeSetTest_test_toString());
expect(changeSet.toString(), isNotNull);
}
}
@reflectiveTest
class EnclosedScopeTest extends DriverResolutionTest {
test_define_duplicate() async {