Permalink
Browse files

ExternalUtils.java: Process all sections

Fixes the bug where only the ``Default`` section of
the returned result was processed.
  • Loading branch information...
arafsheikh committed Jun 21, 2016
1 parent 1da1c83 commit 9774379bd82bf4b18bd9417ec628b48c3ea79980
Showing with 41 additions and 23 deletions.
  1. +41 −23 com.coala.core/src/com/coala/core/utils/ExternalUtils.java
@@ -20,6 +20,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
public class ExternalUtils {
@@ -134,17 +135,26 @@ public void onProcessFailed(ExecuteException executeException) {
*/
public static void processJsonAndMark(String json, IFile file) throws IOException {
JSONObject jsonObject = new JSONObject(json);
JSONArray result = jsonObject.getJSONObject("results").getJSONArray("default");
for (int i = 0; i < result.length(); i++) {
String message = result.getJSONObject(i).getString("message");
String origin = result.getJSONObject(i).getString("origin");
int severity = result.getJSONObject(i).getInt("severity");
JSONArray affectedCodeArray = result.getJSONObject(i).getJSONArray("affected_code");
for (int j = 0; j < affectedCodeArray.length(); j++) {
int endLine = affectedCodeArray.getJSONObject(j).getJSONObject("end").getInt("line");
createCoolMarker(file, endLine, 3 - severity, message);
JSONObject results = jsonObject.getJSONObject("results");
Iterator<?> keys = results.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
JSONArray result = results.getJSONArray(key);
if (result instanceof JSONArray) {
for (int i = 0; i < result.length(); i++) {
String message = result.getJSONObject(i).getString("message");
String origin = result.getJSONObject(i).getString("origin");
int severity = result.getJSONObject(i).getInt("severity");
JSONArray affectedCodeArray = result.getJSONObject(i).getJSONArray("affected_code");
for (int j = 0; j < affectedCodeArray.length(); j++) {
int endLine = affectedCodeArray.getJSONObject(j).getJSONObject("end").getInt("line");
createCoolMarker(file, endLine, 3 - severity, message);
}
}
}
}
}
/**
@@ -159,20 +169,28 @@ public static void processJsonAndMark(String json, IFile file) throws IOExceptio
*/
public static void processJsonAndMark(String json, IProject project) throws IOException {
JSONObject jsonObject = new JSONObject(json);
JSONArray result = jsonObject.getJSONObject("results").getJSONArray("default");
for (int i = 0; i < result.length(); i++) {
String projectPath = project.getLocation().toOSString();
String filePath = result.getJSONObject(i).getJSONArray("affected_code").getJSONObject(0)
.getString("file");
IPath path = new Path(filePath.substring(projectPath.length()));
IFile file = project.getFile(path);
String message = result.getJSONObject(i).getString("message");
String origin = result.getJSONObject(i).getString("origin");
int severity = result.getJSONObject(i).getInt("severity");
JSONArray affectedCodeArray = result.getJSONObject(i).getJSONArray("affected_code");
for (int j = 0; j < affectedCodeArray.length(); j++) {
int endLine = affectedCodeArray.getJSONObject(j).getJSONObject("end").getInt("line");
createCoolMarker(file, endLine, 3 - severity, message);
JSONObject results = jsonObject.getJSONObject("results");
Iterator<?> keys = results.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
JSONArray result = results.getJSONArray(key);
if (result instanceof JSONArray) {
for (int i = 0; i < result.length(); i++) {
String projectPath = project.getLocation().toOSString();
String filePath = result.getJSONObject(i).getJSONArray("affected_code").getJSONObject(0)
.getString("file");
IPath path = new Path(filePath.substring(projectPath.length()));
IFile file = project.getFile(path);
String message = result.getJSONObject(i).getString("message");
String origin = result.getJSONObject(i).getString("origin");
int severity = result.getJSONObject(i).getInt("severity");
JSONArray affectedCodeArray = result.getJSONObject(i).getJSONArray("affected_code");
for (int j = 0; j < affectedCodeArray.length(); j++) {
int endLine = affectedCodeArray.getJSONObject(j).getJSONObject("end").getInt("line");
createCoolMarker(file, endLine, 3 - severity, message);
}
}
}
}
}

0 comments on commit 9774379

Please sign in to comment.