From 6e622f2301402eebba20c4be26548d9c71e8c10a Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 11 Jun 2014 19:17:49 +0400 Subject: [PATCH] Highlight all text ranges for diagnostics in tests --- .../jet/checkers/CheckerTestUtil.java | 50 +++++++++---------- .../diagnostics/tests/LValueAssignment.kt | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java index 79db9004292..957f86ec3c7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java @@ -44,8 +44,8 @@ public class CheckerTestUtil { public int compare(@NotNull Diagnostic o1, @NotNull Diagnostic o2) { List ranges1 = o1.getTextRanges(); List ranges2 = o2.getTextRanges(); - if (ranges1.size() != ranges2.size()) return ranges1.size() - ranges2.size(); - for (int i = 0; i < ranges1.size(); i++) { + int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size(); + for (int i = 0; i < minNumberOfRanges; i++) { TextRange range1 = ranges1.get(i); TextRange range2 = ranges2.get(i); int startOffset1 = range1.getStartOffset(); @@ -61,7 +61,7 @@ public class CheckerTestUtil { return endOffset2 - endOffset1; } } - return 0; + return ranges1.size() - ranges2.size(); } }; private static final Pattern RANGE_START_OR_END_PATTERN = Pattern.compile("()|()"); @@ -439,41 +439,39 @@ public class CheckerTestUtil { } } - private static List getSortedDiagnosticDescriptors(Collection diagnostics) { - List list = Lists.newArrayList(diagnostics); - Collections.sort(list, DIAGNOSTIC_COMPARATOR); - - List diagnosticDescriptors = Lists.newArrayList(); - DiagnosticDescriptor currentDiagnosticDescriptor = null; - for (Diagnostic diagnostic : list) { - List textRanges = diagnostic.getTextRanges(); + @NotNull + private static List getSortedDiagnosticDescriptors(@NotNull Collection diagnostics) { + LinkedListMultimap diagnosticsGroupedByRanges = LinkedListMultimap.create(); + for (Diagnostic diagnostic : diagnostics) { if (!diagnostic.isValid()) continue; - - TextRange textRange = textRanges.get(0); - if (currentDiagnosticDescriptor != null && currentDiagnosticDescriptor.equalRange(textRange)) { - currentDiagnosticDescriptor.diagnostics.add(diagnostic); - } - else { - currentDiagnosticDescriptor = new DiagnosticDescriptor(textRange.getStartOffset(), textRange.getEndOffset(), diagnostic); - diagnosticDescriptors.add(currentDiagnosticDescriptor); + for (TextRange textRange : diagnostic.getTextRanges()) { + diagnosticsGroupedByRanges.put(textRange, diagnostic); } } + List diagnosticDescriptors = Lists.newArrayList(); + for (TextRange range : diagnosticsGroupedByRanges.keySet()) { + diagnosticDescriptors.add( + new DiagnosticDescriptor(range.getStartOffset(), range.getEndOffset(), diagnosticsGroupedByRanges.get(range))); + } + Collections.sort(diagnosticDescriptors, new Comparator() { + @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; } private static class DiagnosticDescriptor { private final int start; private final int end; - private final List diagnostics = Lists.newArrayList(); + private final List diagnostics; - DiagnosticDescriptor(int start, int end, Diagnostic diagnostic) { + DiagnosticDescriptor(int start, int end, List diagnostics) { this.start = start; this.end = end; - this.diagnostics.add(diagnostic); - } - - public boolean equalRange(TextRange textRange) { - return start == textRange.getStartOffset() && end == textRange.getEndOffset(); + this.diagnostics = diagnostics; } public Multiset getDiagnosticTypeStrings() { diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.kt b/compiler/testData/diagnostics/tests/LValueAssignment.kt index b048163c50c..dd41b22982e 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.kt @@ -134,7 +134,7 @@ class Test() { (a : Array)[4]++ (ab.getArray() : Array)[54] += 43 - this[54] = 34 + this[54] = 34 } }