Use first text range for diagnostics with multiple ranges.
Move TEXT_RANGE_COMPARATOR to DiagnosticUtils.
This commit is contained in:
+3
-14
@@ -45,17 +45,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class AnalyzerWithCompilerReport {
|
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
|
@NotNull
|
||||||
private static CompilerMessageSeverity convertSeverity(@NotNull Severity severity) {
|
private static CompilerMessageSeverity convertSeverity(@NotNull Severity severity) {
|
||||||
switch (severity) {
|
switch (severity) {
|
||||||
@@ -143,11 +132,11 @@ public final class AnalyzerWithCompilerReport {
|
|||||||
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||||
if (!path1.equals(path2)) return path1.compareTo(path2);
|
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||||
|
|
||||||
TextRange range1 = d1.getTextRanges().iterator().next();
|
TextRange range1 = DiagnosticUtils.firstRange(d1.getTextRanges());
|
||||||
TextRange range2 = d2.getTextRanges().iterator().next();
|
TextRange range2 = DiagnosticUtils.firstRange(d2.getTextRanges());
|
||||||
|
|
||||||
if (!range1.equals(range2)) {
|
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());
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
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.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class DiagnosticUtils {
|
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() {
|
private DiagnosticUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +118,7 @@ public class DiagnosticUtils {
|
|||||||
PsiFile file = diagnostic.getPsiFile();
|
PsiFile file = diagnostic.getPsiFile();
|
||||||
List<TextRange> textRanges = diagnostic.getTextRanges();
|
List<TextRange> textRanges = diagnostic.getTextRanges();
|
||||||
if (textRanges.isEmpty()) return LineAndColumn.NONE;
|
if (textRanges.isEmpty()) return LineAndColumn.NONE;
|
||||||
TextRange firstRange = textRanges.iterator().next();
|
TextRange firstRange = firstRange(textRanges);
|
||||||
return getLineAndColumnInPsiFile(file, firstRange);
|
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 class LineAndColumn {
|
||||||
|
|
||||||
public static final LineAndColumn NONE = new LineAndColumn(-1, -1);
|
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);
|
executeCompilerCompareOutput(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multipleTextRangesInDiagnosticsOrder() throws Exception {
|
||||||
|
String[] args = {
|
||||||
|
"-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt",
|
||||||
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
|
executeCompilerCompareOutput(args);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void help() throws Exception {
|
public void help() throws Exception {
|
||||||
executeCompilerCompareOutput(new String[] {"-help"});
|
executeCompilerCompareOutput(new String[] {"-help"});
|
||||||
|
|||||||
Reference in New Issue
Block a user