| Index: pkg/analysis_services/lib/correction/change.dart
|
| diff --git a/pkg/analysis_services/lib/correction/change.dart b/pkg/analysis_services/lib/correction/change.dart
|
| index aead3627efa7ff591f40bcbcf58aabf7007dc6ae..086b1cf806469080ba48d51cb6506157d32cce0b 100644
|
| --- a/pkg/analysis_services/lib/correction/change.dart
|
| +++ b/pkg/analysis_services/lib/correction/change.dart
|
| @@ -24,17 +24,31 @@ class Change {
|
| */
|
| final List<FileEdit> edits = <FileEdit>[];
|
|
|
| + /**
|
| + * A list of the [PositionGroup]s in the change.
|
| + */
|
| + final List<PositionGroup> positionGroups = <PositionGroup>[];
|
| +
|
| Change(this.message);
|
|
|
| /**
|
| - * Adds the given [FileEdit] to the list.
|
| + * Adds the given [FileEdit].
|
| */
|
| void add(FileEdit edit) {
|
| edits.add(edit);
|
| }
|
|
|
| + /**
|
| + * Adds the given [PositionGroup].
|
| + */
|
| + void addPositionGroup(PositionGroup positionGroup) {
|
| + positionGroups.add(positionGroup);
|
| + }
|
| +
|
| @override
|
| - String toString() => "Change(message=$message, edits=${edits.join(' ')})";
|
| + String toString() =>
|
| + 'Change(message=$message, edits=${edits.join(' ')}, '
|
| + 'positionGroups=${positionGroups.join(', ')})';
|
| }
|
|
|
|
|
| @@ -101,3 +115,59 @@ class FileEdit {
|
| @override
|
| String toString() => "FileEdit(file=$file, edits=${edits.join(' ')})";
|
| }
|
| +
|
| +
|
| +/**
|
| + * A position in a file.
|
| + */
|
| +class Position {
|
| + final String file;
|
| + final int offset;
|
| + final int length;
|
| +
|
| + Position(this.file, this.offset, this.length);
|
| +
|
| + int get hashCode {
|
| + int hash = file.hashCode;
|
| + hash = hash * 31 + offset;
|
| + hash = hash * 31 + length;
|
| + return hash;
|
| + }
|
| +
|
| + bool operator ==(other) {
|
| + if (other is Position) {
|
| + return other.file == file &&
|
| + other.offset == offset &&
|
| + other.length == length;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + @override
|
| + String toString() => 'Position(file=$file, offset=$offset, length=$length)';
|
| +}
|
| +
|
| +
|
| +/**
|
| + * A group of linked [Position]s in multiple files that are simultaneously
|
| + * modified - if one gets edited, all other positions in a group are edited the
|
| + * same way. All linked positions in a group have the same content.
|
| + */
|
| +class PositionGroup {
|
| + final String id;
|
| + final List<Position> positions = <Position>[];
|
| +
|
| + PositionGroup(this.id);
|
| +
|
| + void add(Position position) {
|
| + if (positions.isNotEmpty && position.length != positions[0].length) {
|
| + throw new ArgumentError(
|
| + 'All positions should have the same length. '
|
| + 'Was: ${positions[0].length}. New: ${position.length}');
|
| + }
|
| + positions.add(position);
|
| + }
|
| +
|
| + @override
|
| + String toString() => 'PositionGroup(id=$id, positions=$positions)';
|
| +}
|
|
|