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

Unified Diff: pkg/analysis_services/lib/src/correction/source_buffer.dart

Issue 405483007: More fixes in the Fixes service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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_services/lib/src/correction/source_buffer.dart
diff --git a/pkg/analysis_services/lib/src/correction/source_buffer.dart b/pkg/analysis_services/lib/src/correction/source_buffer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..07393261bd8bb281c74ea5e7f6b4d4590f60da3a
--- /dev/null
+++ b/pkg/analysis_services/lib/src/correction/source_buffer.dart
@@ -0,0 +1,84 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+// This code was auto-generated, is not intended to be edited, and is subject to
+// significant change. Please see the README file for more information.
+
+library services.src.correction.source_buffer;
+
+import 'package:analysis_services/correction/change.dart';
+import 'package:analyzer/src/generated/source.dart';
+
+
+/**
+ * Helper for building Dart source with linked positions.
+ */
+class SourceBuilder {
+ final String file;
+ final int offset;
+ final StringBuffer _buffer = new StringBuffer();
+
+ final List<PositionGroup> positionGroups = <PositionGroup>[];
+ PositionGroup _currentPositionGroup;
+ int _currentPositionStart;
+
+ SourceBuilder(this.file, this.offset);
+
+ void addProposal(String proposal) {
+ // TODO(scheglov) implement
+// _currentPositionGroup.addProposal();
+ }
+
+ void addProposals(List<String> proposals) {
+ proposals.forEach((proposal) => addProposal(proposal));
+ }
+
+ /**
+ * Appends [s] to the buffer.
+ */
+ SourceBuilder append(String s) {
+ _buffer.write(s);
+ return this;
+ }
+
+ /**
+ * Ends position started using [startPosition].
+ */
+ void endPosition() {
+ assert(_currentPositionGroup != null);
+ _addPosition();
+ _currentPositionGroup = null;
+ }
+
+ /**
+ * Marks start of a new linked position for the group with the given ID.
+ */
+ void startPosition(String groupId) {
+ assert(_currentPositionGroup == null);
+ for (PositionGroup position in positionGroups) {
+ if (position.id == groupId) {
+ _currentPositionGroup = position;
+ break;
+ }
+ }
+ if (_currentPositionGroup == null) {
+ _currentPositionGroup = new PositionGroup(groupId);
+ positionGroups.add(_currentPositionGroup);
+ }
+ _currentPositionStart = _buffer.length;
+ }
+
+ @override
+ String toString() => _buffer.toString();
+
+ /**
+ * Adds position location [SourceRange] using current fields.
+ */
+ void _addPosition() {
+ int start = offset + _currentPositionStart;
+ int end = offset + _buffer.length;
+ Position position = new Position(file, start, end - start);
+ _currentPositionGroup.add(position);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698