Skip to content

Commit

Permalink
sort issues according to files and line numbers, for better reporting…
Browse files Browse the repository at this point in the history
… to user
  • Loading branch information
brice-morin committed Jun 1, 2018
1 parent 2526bad commit f0337cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ public boolean compile(Configuration cfg, Logger log, String... options) {
return true;
}
} else {
String location = "";
for (Issue error : checker.getErrors()) {
// TODO: Some line information as well!
log.error("Error [l" + error.getLineNumber() + " in " + error.getUriToProblem().toFileString() + "]: " + error.getMessage());
if (!location.equals(error.getUriToProblem().toFileString())) {
log.error("Error(s) in " + error.getUriToProblem().toFileString());
location = error.getUriToProblem().toFileString();
}
log.error("\t[line " + error.getLineNumber() + "]: " + error.getMessage());
}
}
// Failed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
ThingMLConsole.getInstance().printDebug("Configuration " + cfg.getName() + " compiled successfully [" + new Date() + "]. Took " + (System.currentTimeMillis() - start) + " ms.\n");
} else {
ThingMLConsole.getInstance().printError("Configuration " + cfg.getName() + " could not be compiled because of errors [" + new Date() + "].\n");
String location = "";
for (Issue error : checker.getErrors()) {
// TODO: Some line information as well!
ThingMLConsole.getInstance().printError("\tError [l" + error.getLineNumber() + " in " + error.getUriToProblem().toFileString() + "]: " + error.getMessage() + "\n");
if (!location.equals(error.getUriToProblem().toFileString())) {
ThingMLConsole.getInstance().printError("Error(s) in " + error.getUriToProblem().toFileString() + "\n");
location = error.getUriToProblem().toFileString();
}
ThingMLConsole.getInstance().printError("\t[line " + error.getLineNumber() + "]: " + error.getMessage() + "\n");
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions language/thingml/src/org/thingml/xtext/validation/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.thingml.xtext.validation;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

Expand All @@ -34,6 +35,11 @@
public class Checker {
private List<Issue> issues;

private final Comparator<Issue> issueComparator = Comparator
.comparing(Issue::getUriToProblem, (uri1, uri2) -> {
return uri1.toFileString().compareTo(uri2.toFileString());
}).thenComparing(Issue::getLineNumber);

public Checker() {
issues = new LinkedList<Issue>();
// TODO: Add a constructor that accepts compiler-specific validators as well
Expand Down Expand Up @@ -72,15 +78,21 @@ private List<Issue> getIssueBySeverity(Severity severity) {
}

public List<Issue> getErrors() {
return getIssueBySeverity(Severity.ERROR);
final List<Issue> sorted = getIssueBySeverity(Severity.ERROR);
sorted.sort(issueComparator);
return sorted;
}

public List<Issue> getWarnings() {
return getIssueBySeverity(Severity.WARNING);
final List<Issue> sorted = getIssueBySeverity(Severity.WARNING);
sorted.sort(issueComparator);
return sorted;
}

public List<Issue> getInfos() {
return getIssueBySeverity(Severity.INFO);
final List<Issue> sorted = getIssueBySeverity(Severity.INFO);
sorted.sort(issueComparator);
return sorted;
}

public boolean hasErrors() {
Expand Down

0 comments on commit f0337cb

Please sign in to comment.