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

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/SourceBuilder.java

Issue 10834222: Initial implementation of 'Create Method' quick fix (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use resolveUnit() in ASTProvider Created 8 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: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/SourceBuilder.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/SourceBuilder.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/SourceBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..f613ebe917a3c05c2907ca7bf336b7dc94c544a8
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/SourceBuilder.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2012, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.dart.tools.ui.internal.text.correction.proposals;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.dart.tools.core.dom.rewrite.TrackedNodePosition;
+import com.google.dart.tools.core.model.SourceRange;
+
+import org.eclipse.core.runtime.Assert;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Helper for building Dart source with tracked positions.
+ */
+public class SourceBuilder {
+ private final int base;
+ private final StringBuilder buffer = new StringBuilder();
+ private final Map<String, List<TrackedNodePosition>> trackedPositions = Maps.newHashMap();
+ private String currentPositionGroupId;
+ private int currentPositionStart;
+
+ public SourceBuilder(int base) {
+ this.base = base;
+ }
+
+ public SourceBuilder(SourceRange base) {
+ this(base.getOffset());
+ }
+
+ public SourceBuilder append(CharSequence s) {
+ buffer.append(s);
+ return this;
+ }
+
+ public void endPosition() {
+ Assert.isNotNull(currentPositionGroupId);
+ addPosition();
+ currentPositionGroupId = null;
+ }
+
+ public Map<String, List<TrackedNodePosition>> getTrackedPositions() {
+ return trackedPositions;
+ }
+
+ public void startPosition(String groupId) {
+ Assert.isTrue(currentPositionGroupId == null);
+ currentPositionGroupId = groupId;
+ currentPositionStart = buffer.length();
+ }
+
+ @Override
+ public String toString() {
+ return buffer.toString();
+ }
+
+ /**
+ * Adds {@link TrackedNodePosition} using current fields.
+ */
+ private void addPosition() {
+ List<TrackedNodePosition> positions = trackedPositions.get(currentPositionGroupId);
+ if (positions == null) {
+ positions = Lists.newArrayList();
+ trackedPositions.put(currentPositionGroupId, positions);
+ }
+ int start = base + currentPositionStart;
+ int end = base + buffer.length();
+ positions.add(TrackedPositions.forStartEnd(start, end));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698