Highlight all text ranges for diagnostics in tests
This commit is contained in:
@@ -44,8 +44,8 @@ public class CheckerTestUtil {
|
|||||||
public int compare(@NotNull Diagnostic o1, @NotNull Diagnostic o2) {
|
public int compare(@NotNull Diagnostic o1, @NotNull Diagnostic o2) {
|
||||||
List<TextRange> ranges1 = o1.getTextRanges();
|
List<TextRange> ranges1 = o1.getTextRanges();
|
||||||
List<TextRange> ranges2 = o2.getTextRanges();
|
List<TextRange> ranges2 = o2.getTextRanges();
|
||||||
if (ranges1.size() != ranges2.size()) return ranges1.size() - ranges2.size();
|
int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size();
|
||||||
for (int i = 0; i < ranges1.size(); i++) {
|
for (int i = 0; i < minNumberOfRanges; i++) {
|
||||||
TextRange range1 = ranges1.get(i);
|
TextRange range1 = ranges1.get(i);
|
||||||
TextRange range2 = ranges2.get(i);
|
TextRange range2 = ranges2.get(i);
|
||||||
int startOffset1 = range1.getStartOffset();
|
int startOffset1 = range1.getStartOffset();
|
||||||
@@ -61,7 +61,7 @@ public class CheckerTestUtil {
|
|||||||
return endOffset2 - endOffset1;
|
return endOffset2 - endOffset1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return ranges1.size() - ranges2.size();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private static final Pattern RANGE_START_OR_END_PATTERN = Pattern.compile("(<!\\w+(,\\s*\\w+)*!>)|(<!>)");
|
private static final Pattern RANGE_START_OR_END_PATTERN = Pattern.compile("(<!\\w+(,\\s*\\w+)*!>)|(<!>)");
|
||||||
@@ -439,41 +439,39 @@ public class CheckerTestUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<DiagnosticDescriptor> getSortedDiagnosticDescriptors(Collection<Diagnostic> diagnostics) {
|
@NotNull
|
||||||
List<Diagnostic> list = Lists.newArrayList(diagnostics);
|
private static List<DiagnosticDescriptor> getSortedDiagnosticDescriptors(@NotNull Collection<Diagnostic> diagnostics) {
|
||||||
Collections.sort(list, DIAGNOSTIC_COMPARATOR);
|
LinkedListMultimap<TextRange, Diagnostic> diagnosticsGroupedByRanges = LinkedListMultimap.create();
|
||||||
|
for (Diagnostic diagnostic : diagnostics) {
|
||||||
List<DiagnosticDescriptor> diagnosticDescriptors = Lists.newArrayList();
|
|
||||||
DiagnosticDescriptor currentDiagnosticDescriptor = null;
|
|
||||||
for (Diagnostic diagnostic : list) {
|
|
||||||
List<TextRange> textRanges = diagnostic.getTextRanges();
|
|
||||||
if (!diagnostic.isValid()) continue;
|
if (!diagnostic.isValid()) continue;
|
||||||
|
for (TextRange textRange : diagnostic.getTextRanges()) {
|
||||||
TextRange textRange = textRanges.get(0);
|
diagnosticsGroupedByRanges.put(textRange, diagnostic);
|
||||||
if (currentDiagnosticDescriptor != null && currentDiagnosticDescriptor.equalRange(textRange)) {
|
|
||||||
currentDiagnosticDescriptor.diagnostics.add(diagnostic);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
currentDiagnosticDescriptor = new DiagnosticDescriptor(textRange.getStartOffset(), textRange.getEndOffset(), diagnostic);
|
|
||||||
diagnosticDescriptors.add(currentDiagnosticDescriptor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<DiagnosticDescriptor> diagnosticDescriptors = Lists.newArrayList();
|
||||||
|
for (TextRange range : diagnosticsGroupedByRanges.keySet()) {
|
||||||
|
diagnosticDescriptors.add(
|
||||||
|
new DiagnosticDescriptor(range.getStartOffset(), range.getEndOffset(), diagnosticsGroupedByRanges.get(range)));
|
||||||
|
}
|
||||||
|
Collections.sort(diagnosticDescriptors, new Comparator<DiagnosticDescriptor>() {
|
||||||
|
@Override
|
||||||
|
public int compare(DiagnosticDescriptor d1, DiagnosticDescriptor d2) {
|
||||||
|
// Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
|
||||||
|
return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
|
||||||
|
}
|
||||||
|
});
|
||||||
return diagnosticDescriptors;
|
return diagnosticDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DiagnosticDescriptor {
|
private static class DiagnosticDescriptor {
|
||||||
private final int start;
|
private final int start;
|
||||||
private final int end;
|
private final int end;
|
||||||
private final List<Diagnostic> diagnostics = Lists.newArrayList();
|
private final List<Diagnostic> diagnostics;
|
||||||
|
|
||||||
DiagnosticDescriptor(int start, int end, Diagnostic diagnostic) {
|
DiagnosticDescriptor(int start, int end, List<Diagnostic> diagnostics) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.diagnostics.add(diagnostic);
|
this.diagnostics = diagnostics;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equalRange(TextRange textRange) {
|
|
||||||
return start == textRange.getStartOffset() && end == textRange.getEndOffset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Multiset<String> getDiagnosticTypeStrings() {
|
public Multiset<String> getDiagnosticTypeStrings() {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class Test() {
|
|||||||
(a : Array<Int>)[4]++
|
(a : Array<Int>)[4]++
|
||||||
(<!VARIABLE_EXPECTED!>ab.getArray()<!> : Array<Int>)[54] += 43
|
(<!VARIABLE_EXPECTED!>ab.getArray()<!> : Array<Int>)[54] += 43
|
||||||
|
|
||||||
this<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>54]<!> = 34
|
this<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>54<!UNRESOLVED_REFERENCE!>]<!><!> = 34
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user