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

Unified Diff: editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FormatProcessor.java

Issue 809213003: Add format API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add handler hook and missed classes Created 5 years, 11 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.server/src/com/google/dart/server/internal/remote/processor/FormatProcessor.java
diff --git a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FixesProcessor.java b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FormatProcessor.java
similarity index 60%
copy from editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FixesProcessor.java
copy to editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FormatProcessor.java
index d7545a048be63648a992ae90e02c24753d28af9d..49174e7e6976fe68ef4ad1670e2e1c312a5a3829 100644
--- a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FixesProcessor.java
+++ b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/FormatProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, the Dart project authors.
+ * Copyright (c) 2015, 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
@@ -14,9 +14,9 @@
package com.google.dart.server.internal.remote.processor;
import com.google.dart.server.ExtendedRequestErrorCode;
-import com.google.dart.server.GetFixesConsumer;
-import com.google.dart.server.generated.types.AnalysisErrorFixes;
+import com.google.dart.server.FormatConsumer;
import com.google.dart.server.generated.types.RequestError;
+import com.google.dart.server.generated.types.SourceEdit;
import com.google.gson.JsonObject;
import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -24,31 +24,31 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import java.util.List;
/**
- * Instances of {@code FixesProcessor} translate JSON result objects for a given
- * {@link GetFixesConsumer}.
+ * Instances of {@code FormatProcessor} translate JSON result objects for a given
+ * {@link FormatConsumer}.
*
* @coverage dart.server.remote
*/
-public class FixesProcessor extends ResultProcessor {
+public class FormatProcessor extends ResultProcessor {
+ private final FormatConsumer consumer;
- private final GetFixesConsumer consumer;
-
- public FixesProcessor(GetFixesConsumer consumer) {
+ public FormatProcessor(FormatConsumer consumer) {
this.consumer = consumer;
}
public void process(JsonObject resultObject, RequestError requestError) {
if (resultObject != null) {
try {
- List<AnalysisErrorFixes> errorFixesArray = AnalysisErrorFixes.fromJsonArray(resultObject.get(
- "fixes").getAsJsonArray());
- consumer.computedFixes(errorFixesArray);
- } catch (Exception e) {
+ List<SourceEdit> edits = SourceEdit.fromJsonArray(resultObject.get("edits").getAsJsonArray());
+ int selectionOffset = resultObject.get("selectionOffset").getAsInt();
+ int selectionLength = resultObject.get("selectionLength").getAsInt();
+ consumer.computedFormat(edits, selectionOffset, selectionLength);
+ } catch (Exception exception) {
// catch any exceptions in the formatting of this response
- String message = e.getMessage();
+ String message = exception.getMessage();
String stackTrace = null;
- if (e.getStackTrace() != null) {
- stackTrace = ExceptionUtils.getStackTrace(e);
+ if (exception.getStackTrace() != null) {
+ stackTrace = ExceptionUtils.getStackTrace(exception);
}
requestError = new RequestError(
ExtendedRequestErrorCode.INVALID_SERVER_RESPONSE,

Powered by Google App Engine
This is Rietveld 408576698