Use first text range for diagnostics with multiple ranges.

Move TEXT_RANGE_COMPARATOR to DiagnosticUtils.
This commit is contained in:
Pavel V. Talanov
2012-08-01 16:13:58 +04:00
parent f58ba37d4f
commit d45145b3a7
5 changed files with 41 additions and 16 deletions
@@ -45,17 +45,6 @@ import java.util.List;
*/
public final class AnalyzerWithCompilerReport {
@NotNull
private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR = new Comparator<TextRange>() {
@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());
@@ -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<TextRange> TEXT_RANGE_COMPARATOR = new Comparator<TextRange>() {
@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<TextRange> 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<TextRange> ranges) {
return Collections.min(ranges, TEXT_RANGE_COMPARATOR);
}
public static final class LineAndColumn {
public static final LineAndColumn NONE = new LineAndColumn(-1, -1);
@@ -0,0 +1,7 @@
trait A {
public val c: Int
}
trait B: A {
override protected private val c: Int
}
@@ -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
@@ -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"});