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