From 2ff896cc5a903b2d9ae5ba738f0159d95cf417f0 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 21 Feb 2012 12:52:59 +0400 Subject: [PATCH] Cleaned up Kompiler's error reporting --- .../jet/compiler/CompileSession.java | 6 ++--- .../jet/compiler/ErrorCollector.java | 26 ++++++++----------- .../jet/lang/diagnostics/DiagnosticUtils.java | 15 +++++------ 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java b/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java index 12ec52dbd6f..9c2c15aa12c 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java @@ -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; } /** diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/ErrorCollector.java b/compiler/cli/src/org/jetbrains/jet/compiler/ErrorCollector.java index c2c9a84a334..b91b23bc484 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/ErrorCollector.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/ErrorCollector.java @@ -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 maps = LinkedHashMultimap.create(); + private final Multimap 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 diagnosticWithTextRanges = maps.get(psiFile); - for (DiagnosticWithTextRange diagnosticWithTextRange : diagnosticWithTextRanges) { - String position = DiagnosticUtils.formatPosition(diagnosticWithTextRange); - out.println(diagnosticWithTextRange.getSeverity().toString() + ": " + path + ":" + position + " " + diagnosticWithTextRange.getMessage()); + Collection 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; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java index 00bfdeab073..d91b8481b50 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java @@ -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) {