Search in sources :

Example 1 with AnalysisError

use of org.dartlang.analysis.server.protocol.AnalysisError in project intellij-plugins by JetBrains.

the class DartProblemsTableModel method addErrorsAndReturnReplacementForSelection.

@Nullable
private DartProblem addErrorsAndReturnReplacementForSelection(@NotNull final Map<String, List<AnalysisError>> filePathToErrors, @Nullable final DartProblem oldSelectedProblem) {
    DartProblem newSelectedProblem = null;
    final List<DartProblem> problemsToAdd = new ArrayList<>();
    for (Map.Entry<String, List<AnalysisError>> entry : filePathToErrors.entrySet()) {
        final String filePath = entry.getKey();
        final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(filePath);
        final List<AnalysisError> errors = vFile != null && ProjectFileIndex.getInstance(myProject).isInContent(vFile) ? entry.getValue() : AnalysisError.EMPTY_LIST;
        for (AnalysisError analysisError : errors) {
            if (DartAnnotator.shouldIgnoreMessageFromDartAnalyzer(filePath, analysisError.getLocation().getFile())) {
                continue;
            }
            final DartProblem problem = new DartProblem(myProject, analysisError);
            problemsToAdd.add(problem);
            if (oldSelectedProblem != null && lookSimilar(problem, oldSelectedProblem) && (newSelectedProblem == null || // check if current problem is closer to oldSelectedProblem
            (Math.abs(oldSelectedProblem.getLineNumber() - newSelectedProblem.getLineNumber()) >= Math.abs(oldSelectedProblem.getLineNumber() - problem.getLineNumber())))) {
                newSelectedProblem = problem;
            }
            if (AnalysisErrorSeverity.ERROR.equals(problem.getSeverity()))
                myErrorCount++;
            if (AnalysisErrorSeverity.WARNING.equals(problem.getSeverity()))
                myWarningCount++;
            if (AnalysisErrorSeverity.INFO.equals(problem.getSeverity()))
                myHintCount++;
            updateProblemsCountAfterFilter(problem, true);
        }
    }
    if (!problemsToAdd.isEmpty()) {
        addRows(problemsToAdd);
    }
    return newSelectedProblem;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnalysisError(org.dartlang.analysis.server.protocol.AnalysisError) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AnalysisError

use of org.dartlang.analysis.server.protocol.AnalysisError in project intellij-plugins by JetBrains.

the class AnalysisErrorsProcessor method process.

public void process(JsonObject resultObject, RequestError requestError) {
    if (resultObject != null) {
        try {
            ArrayList<AnalysisError> errors = new ArrayList<AnalysisError>();
            Iterator<JsonElement> iter = resultObject.get("errors").getAsJsonArray().iterator();
            while (iter.hasNext()) {
                JsonObject errorJsonObject = iter.next().getAsJsonObject();
                errors.add(AnalysisError.fromJson(errorJsonObject));
            }
            consumer.computedErrors(errors.toArray(new AnalysisError[errors.size()]));
        } catch (Exception exception) {
            // catch any exceptions in the formatting of this response
            requestError = generateRequestError(exception);
        }
    }
    if (requestError != null) {
        consumer.onError(requestError);
    }
}
Also used : AnalysisError(org.dartlang.analysis.server.protocol.AnalysisError) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 3 with AnalysisError

use of org.dartlang.analysis.server.protocol.AnalysisError in project intellij-plugins by JetBrains.

the class RequestUtilities method buildJsonElement.

@VisibleForTesting
public static JsonElement buildJsonElement(Object object) {
    if (object instanceof Boolean) {
        return new JsonPrimitive((Boolean) object);
    } else if (object instanceof Number) {
        return new JsonPrimitive((Number) object);
    } else if (object instanceof String) {
        return new JsonPrimitive((String) object);
    } else if (object instanceof List<?>) {
        List<?> list = (List<?>) object;
        JsonArray jsonArray = new JsonArray();
        for (Object item : list) {
            JsonElement jsonItem = buildJsonElement(item);
            jsonArray.add(jsonItem);
        }
        return jsonArray;
    } else if (object instanceof Map<?, ?>) {
        Map<?, ?> map = (Map<?, ?>) object;
        JsonObject jsonObject = new JsonObject();
        for (Entry<?, ?> entry : map.entrySet()) {
            Object key = entry.getKey();
            // prepare string key
            String keyString;
            if (key instanceof String) {
                keyString = (String) key;
            } else {
                throw new IllegalArgumentException("Unable to convert to string: " + getClassName(key));
            }
            // prepare JsonElement value
            Object value = entry.getValue();
            JsonElement valueJson = buildJsonElement(value);
            // put a property into the JSON object
            if (keyString != null && valueJson != null) {
                jsonObject.add(keyString, valueJson);
            }
        }
        return jsonObject;
    } else if (object instanceof AnalysisError) {
        return buildJsonObjectAnalysisError((AnalysisError) object);
    } else if (object instanceof AddContentOverlay) {
        return ((AddContentOverlay) object).toJson();
    } else if (object instanceof ChangeContentOverlay) {
        return ((ChangeContentOverlay) object).toJson();
    } else if (object instanceof RemoveContentOverlay) {
        return ((RemoveContentOverlay) object).toJson();
    } else if (object instanceof AnalysisOptions) {
        return ((AnalysisOptions) object).toJson();
    } else if (object instanceof Location) {
        return buildJsonObjectLocation((Location) object);
    }
    throw new IllegalArgumentException("Unable to convert to JSON: " + object);
}
Also used : AddContentOverlay(org.dartlang.analysis.server.protocol.AddContentOverlay) JsonPrimitive(com.google.gson.JsonPrimitive) AnalysisOptions(org.dartlang.analysis.server.protocol.AnalysisOptions) AnalysisError(org.dartlang.analysis.server.protocol.AnalysisError) ChangeContentOverlay(org.dartlang.analysis.server.protocol.ChangeContentOverlay) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) RemoveContentOverlay(org.dartlang.analysis.server.protocol.RemoveContentOverlay) JsonElement(com.google.gson.JsonElement) List(java.util.List) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) Location(org.dartlang.analysis.server.protocol.Location) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

AnalysisError (org.dartlang.analysis.server.protocol.AnalysisError)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AddContentOverlay (org.dartlang.analysis.server.protocol.AddContentOverlay)1 AnalysisOptions (org.dartlang.analysis.server.protocol.AnalysisOptions)1 ChangeContentOverlay (org.dartlang.analysis.server.protocol.ChangeContentOverlay)1 Location (org.dartlang.analysis.server.protocol.Location)1 RemoveContentOverlay (org.dartlang.analysis.server.protocol.RemoveContentOverlay)1 Nullable (org.jetbrains.annotations.Nullable)1