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

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

Issue 300313002: Switch to using remote analysis server instead of local. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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/NotificationErrorsProcessor.java
diff --git a/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/NotificationErrorsProcessor.java b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/NotificationErrorsProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..59e6cab52dab3f5c8a0f3b17491916146b492775
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/internal/remote/processor/NotificationErrorsProcessor.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2014, 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.server.internal.remote.processor;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
+import com.google.dart.engine.error.AngularCode;
+import com.google.dart.engine.error.CompileTimeErrorCode;
+import com.google.dart.engine.error.ErrorCode;
+import com.google.dart.engine.error.HintCode;
+import com.google.dart.engine.error.HtmlWarningCode;
+import com.google.dart.engine.error.PolymerCode;
+import com.google.dart.engine.error.PubSuggestionCode;
+import com.google.dart.engine.error.StaticTypeWarningCode;
+import com.google.dart.engine.error.StaticWarningCode;
+import com.google.dart.engine.error.TodoCode;
+import com.google.dart.engine.parser.ParserErrorCode;
+import com.google.dart.engine.resolver.ResolverErrorCode;
+import com.google.dart.engine.scanner.ScannerErrorCode;
+import com.google.dart.server.AnalysisError;
+import com.google.dart.server.AnalysisServerListener;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Processor for "analysis.errors" notification.
+ *
+ * @coverage dart.server.remote
+ */
+public class NotificationErrorsProcessor {
+ /**
+ * Return the {@link ErrorCode} code for the given name, {@code null} if cannot be parsed.
+ */
+ @VisibleForTesting
+ public static ErrorCode getErrorCode(String errorName) {
+ String errorCodeClassName = StringUtils.substringBefore(errorName, ".");
+ String errorCodeName = StringUtils.substringAfter(errorName, ".");
+ if (errorCodeClassName.equals("AngularCode")) {
+ return AngularCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("CompileTimeErrorCode")) {
+ return CompileTimeErrorCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("HintCode")) {
+ return HintCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("HtmlWarningCode")) {
+ return HtmlWarningCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("ParserErrorCode")) {
+ return ParserErrorCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("PolymerCode")) {
+ return PolymerCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("PubSuggestionCode")) {
+ return PubSuggestionCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("ResolverErrorCode")) {
+ return ResolverErrorCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("ScannerErrorCode")) {
+ return ScannerErrorCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("StaticTypeWarningCode")) {
+ return StaticTypeWarningCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("StaticWarningCode")) {
+ return StaticWarningCode.valueOf(errorCodeName);
+ }
+ if (errorCodeClassName.equals("TodoCode")) {
+ return TodoCode.valueOf(errorCodeName);
+ }
+ return null;
+ }
+
+ private final AnalysisServerListener listener;
+
+ public NotificationErrorsProcessor(AnalysisServerListener listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Process the given {@link JsonObject} notification and notify {@link #listener}.
+ */
+ public void process(JsonObject response) throws Exception {
+ JsonObject paramsObject = response.get("params").getAsJsonObject();
Brian Wilkerson 2014/05/28 17:36:39 These strings should be constants.
+ String file = paramsObject.get("file").getAsString();
+ // prepare error objects iterator
+ JsonElement errorsElement = paramsObject.get("errors");
+ Iterator<JsonElement> errorElementIterator = errorsElement.getAsJsonArray().iterator();
+ // convert errors
+ List<AnalysisError> analysisErrors = Lists.newArrayList();
+ for (; errorElementIterator.hasNext();) {
Brian Wilkerson 2014/05/28 17:36:39 Consider using a while loop when there's nothing b
+ JsonObject errorObject = errorElementIterator.next().getAsJsonObject();
+ ErrorCode errorCode = getErrorCode(errorObject.get("errorCode"));
+ if (errorCode != null) {
+ int offset = errorObject.get("offset").getAsInt();
+ int length = errorObject.get("length").getAsInt();
+ String message = errorObject.get("message").getAsString();
+ JsonElement correctionElement = errorObject.get("correction");
+ String correction = correctionElement != null ? correctionElement.getAsString() : null;
+ analysisErrors.add(new AnalysisErrorImpl(
+ file,
+ errorCode,
+ offset,
+ length,
+ message,
+ correction));
+ }
+ }
+ // notify listener
+ listener.computedErrors(file, analysisErrors.toArray(new AnalysisError[analysisErrors.size()]));
+ }
+
+ /**
+ * Attempt to convert the given {@link JsonElement} into an {@link ErrorCode}.
+ *
+ * @return the {@link ErrorCode} or {@code null}
+ */
+ private ErrorCode getErrorCode(JsonElement element) {
+ String errorName = element.getAsString();
+ return getErrorCode(errorName);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698