Refactor AnalyzerWithCompilerReport: introduce TEXT_RANGE_COMPARATOR.
This commit is contained in:
+14
-4
@@ -45,6 +45,17 @@ 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) {
|
||||
@@ -134,11 +145,10 @@ public final class AnalyzerWithCompilerReport {
|
||||
|
||||
TextRange range1 = d1.getTextRanges().iterator().next();
|
||||
TextRange range2 = d2.getTextRanges().iterator().next();
|
||||
int startOffsetDiff = range1.getStartOffset() - range2.getStartOffset();
|
||||
if (startOffsetDiff != 0) return startOffsetDiff;
|
||||
|
||||
int endOffsetDiff = range1.getEndOffset() - range2.getEndOffset();
|
||||
if (endOffsetDiff != 0) return endOffsetDiff;
|
||||
if (!range1.equals(range2)) {
|
||||
return TEXT_RANGE_COMPARATOR.compare(range1, range2);
|
||||
}
|
||||
|
||||
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user