Cleaned up Kompiler's error reporting
This commit is contained in:
@@ -80,11 +80,11 @@ public class CompileSession {
|
||||
|
||||
VirtualFile vFile = myEnvironment.getLocalFileSystem().findFileByPath(path);
|
||||
if (vFile == null) {
|
||||
myErrors.add("File/directory not found: " + path);
|
||||
myErrors.add("ERROR: File/directory not found: " + path);
|
||||
return;
|
||||
}
|
||||
if (!vFile.isDirectory() && vFile.getFileType() != JetFileType.INSTANCE) {
|
||||
myErrors.add("Not a Kotlin file: " + path);
|
||||
myErrors.add("ERROR: Not a Kotlin file: " + path);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class CompileSession {
|
||||
}
|
||||
|
||||
errorCollector.flushTo(out);
|
||||
return !errorCollector.hasErrors && !hasIncompleteHierarchyErrors;
|
||||
return !errorCollector.hasErrors() && !hasIncompleteHierarchyErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.common.collect.Multimap;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithTextRange;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
|
||||
import java.io.PrintStream;
|
||||
@@ -31,35 +30,32 @@ import java.util.Collection;
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
class ErrorCollector {
|
||||
Multimap<PsiFile,DiagnosticWithTextRange> maps = LinkedHashMultimap.<PsiFile, DiagnosticWithTextRange>create();
|
||||
private final Multimap<PsiFile, Diagnostic> maps = LinkedHashMultimap.create();
|
||||
|
||||
boolean hasErrors;
|
||||
private boolean hasErrors;
|
||||
|
||||
public ErrorCollector() {
|
||||
}
|
||||
|
||||
public void report(Diagnostic diagnostic) {
|
||||
hasErrors |= diagnostic.getSeverity() == Severity.ERROR;
|
||||
if(diagnostic instanceof DiagnosticWithTextRange) {
|
||||
DiagnosticWithTextRange diagnosticWithTextRange = (DiagnosticWithTextRange) diagnostic;
|
||||
maps.put(diagnosticWithTextRange.getPsiFile(), diagnosticWithTextRange);
|
||||
}
|
||||
else {
|
||||
System.out.println(diagnostic.getSeverity().toString() + ": " + diagnostic.getMessage());
|
||||
}
|
||||
maps.put(diagnostic.getFactory().getPsiFile(diagnostic), diagnostic);
|
||||
}
|
||||
|
||||
void flushTo(final PrintStream out) {
|
||||
public void flushTo(final PrintStream out) {
|
||||
if(!maps.isEmpty()) {
|
||||
for (PsiFile psiFile : maps.keySet()) {
|
||||
String path = psiFile.getVirtualFile().getPath();
|
||||
Collection<DiagnosticWithTextRange> diagnosticWithTextRanges = maps.get(psiFile);
|
||||
for (DiagnosticWithTextRange diagnosticWithTextRange : diagnosticWithTextRanges) {
|
||||
String position = DiagnosticUtils.formatPosition(diagnosticWithTextRange);
|
||||
out.println(diagnosticWithTextRange.getSeverity().toString() + ": " + path + ":" + position + " " + diagnosticWithTextRange.getMessage());
|
||||
Collection<Diagnostic> diagnostics = maps.get(psiFile);
|
||||
for (Diagnostic diagnostic : diagnostics) {
|
||||
String position = DiagnosticUtils.formatPosition(diagnostic);
|
||||
out.println(diagnostic.getSeverity().toString() + ": " + path + ":" + position + " " + diagnostic.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasErrors() {
|
||||
return hasErrors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,22 +84,19 @@ public class DiagnosticUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatPosition(DiagnosticWithTextRange diagnosticWithTextRange) {
|
||||
PsiFile file = diagnosticWithTextRange.getPsiFile();
|
||||
public static String formatPosition(Diagnostic diagnostic) {
|
||||
PsiFile file = diagnostic.getFactory().getPsiFile(diagnostic);
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
String position;
|
||||
int offset = diagnosticWithTextRange.getTextRange().getStartOffset();
|
||||
TextRange firstRange = diagnostic.getFactory().getTextRanges(diagnostic).iterator().next();
|
||||
int offset = firstRange.getStartOffset();
|
||||
if (document != null) {
|
||||
int lineNumber = document.getLineNumber(offset);
|
||||
int lineStartOffset = document.getLineStartOffset(lineNumber);
|
||||
int column = offset - lineStartOffset;
|
||||
|
||||
position = "(" + (lineNumber + 1) + "," + (column + 1) + ")";
|
||||
return "(" + (lineNumber + 1) + "," + (column + 1) + ")";
|
||||
}
|
||||
else {
|
||||
position = "(offset: " + offset + " line unknown)";
|
||||
}
|
||||
return position;
|
||||
return "(offset: " + offset + " line unknown)";
|
||||
}
|
||||
|
||||
public static void throwIfRunningOnServer(Throwable e) {
|
||||
|
||||
Reference in New Issue
Block a user