diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java index dc315a99b47..2a9617f927a 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java @@ -45,17 +45,6 @@ import java.util.List; */ public final class AnalyzerWithCompilerReport { - @NotNull - private static final Comparator TEXT_RANGE_COMPARATOR = new Comparator() { - @Override - public int compare(TextRange o1, TextRange o2) { - if (o1.getStartOffset() != o2.getStartOffset()) { - return o1.getStartOffset() - o2.getStartOffset(); - } - return o1.getEndOffset() - o2.getEndOffset(); - } - }; - @NotNull private static CompilerMessageSeverity convertSeverity(@NotNull Severity severity) { switch (severity) { @@ -143,11 +132,11 @@ public final class AnalyzerWithCompilerReport { 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(); + TextRange range1 = DiagnosticUtils.firstRange(d1.getTextRanges()); + TextRange range2 = DiagnosticUtils.firstRange(d2.getTextRanges()); if (!range1.equals(range2)) { - return TEXT_RANGE_COMPARATOR.compare(range1, range2); + return DiagnosticUtils.TEXT_RANGE_COMPARATOR.compare(range1, range2); } return d1.getFactory().getName().compareTo(d2.getFactory().getName()); 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 1d36e603c22..14f1e144554 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java @@ -26,17 +26,29 @@ import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; +import java.util.Collections; +import java.util.Comparator; import java.util.List; /** * @author abreslav */ public class DiagnosticUtils { + @NotNull + public static final Comparator TEXT_RANGE_COMPARATOR = new Comparator() { + @Override + public int compare(TextRange o1, TextRange o2) { + if (o1.getStartOffset() != o2.getStartOffset()) { + return o1.getStartOffset() - o2.getStartOffset(); + } + return o1.getEndOffset() - o2.getEndOffset(); + } + }; + private DiagnosticUtils() { } @@ -106,7 +118,7 @@ public class DiagnosticUtils { PsiFile file = diagnostic.getPsiFile(); List textRanges = diagnostic.getTextRanges(); if (textRanges.isEmpty()) return LineAndColumn.NONE; - TextRange firstRange = textRanges.iterator().next(); + TextRange firstRange = firstRange(textRanges); return getLineAndColumnInPsiFile(file, firstRange); } @@ -142,6 +154,11 @@ public class DiagnosticUtils { } } + @NotNull + public static TextRange firstRange(@NotNull List ranges) { + return Collections.min(ranges, TEXT_RANGE_COMPARATOR); + } + public static final class LineAndColumn { public static final LineAndColumn NONE = new LineAndColumn(-1, -1); diff --git a/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt b/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt new file mode 100644 index 00000000000..7340ff8a25d --- /dev/null +++ b/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt @@ -0,0 +1,7 @@ +trait A { + public val c: Int +} + +trait B: A { + override protected private val c: Int +} diff --git a/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.out b/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.out new file mode 100644 index 00000000000..f59519a0ecf --- /dev/null +++ b/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.out @@ -0,0 +1,4 @@ +ERROR: $TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt: (6, 14) Cannot weaken access privilege 'public' for 'c' in 'A' +ERROR: $TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt: (6, 14) Incompatible modifiers: 'private protected' +ERROR: $TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt: (6, 24) Incompatible modifiers: 'private protected' +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java index 6294f927d74..9525ba8d139 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java @@ -116,6 +116,14 @@ public class CliTest { executeCompilerCompareOutput(args); } + @Test + public void multipleTextRangesInDiagnosticsOrder() throws Exception { + String[] args = { + "-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt", + "-output", tmpdir.getTmpDir().getPath()}; + executeCompilerCompareOutput(args); + } + @Test public void help() throws Exception { executeCompilerCompareOutput(new String[] {"-help"});