KT-2524: Standalone compiler prints diagnostics in random order.
#KT-2524 Fixed
This commit is contained in:
+30
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.cli.common.messages;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -34,6 +36,9 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -111,12 +116,36 @@ public final class AnalyzerWithCompilerReport {
|
||||
|
||||
public static boolean reportDiagnostics(@NotNull BindingContext bindingContext, @NotNull MessageCollector messageCollector) {
|
||||
boolean hasErrors = false;
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
List<Diagnostic> diagnostics = Lists.newArrayList(bindingContext.getDiagnostics());
|
||||
sortDiagnostics(diagnostics);
|
||||
for (Diagnostic diagnostic : diagnostics) {
|
||||
hasErrors |= reportDiagnostic(diagnostic, messageCollector);
|
||||
}
|
||||
return hasErrors;
|
||||
}
|
||||
|
||||
private static void sortDiagnostics(@NotNull List<Diagnostic> diagnostics) {
|
||||
Comparator<Diagnostic> diagnosticComparator = new Comparator<Diagnostic>() {
|
||||
@Override
|
||||
public int compare(Diagnostic d1, Diagnostic d2) {
|
||||
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||
|
||||
TextRange range1 = d1.getTextRanges().iterator().next();
|
||||
TextRange range2 = d2.getTextRanges().iterator().next();
|
||||
int startOffsetDiff = range1.getStartOffset() - range2.getStartOffset();
|
||||
if (startOffsetDiff != 0) return startOffsetDiff;
|
||||
|
||||
int endOffsetDiff = range1.getEndOffset() - range2.getEndOffset();
|
||||
if (endOffsetDiff != 0) return endOffsetDiff;
|
||||
|
||||
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||
}
|
||||
};
|
||||
Collections.sort(diagnostics, diagnosticComparator);
|
||||
}
|
||||
|
||||
private void reportSyntaxErrors(@NotNull Collection<JetFile> files) {
|
||||
for (JetFile file : files) {
|
||||
reportSyntaxErrors(file, messageCollectorWrapper);
|
||||
|
||||
Reference in New Issue
Block a user