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;
}
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);
}
}
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);
}
Aggregations