From 0bc5f94330d9049e23d9582f866a3e3efb8aa23b Mon Sep 17 00:00:00 2001 From: Benedek Halasi Date: Sat, 7 Dec 2024 08:20:03 +0100 Subject: [PATCH] fixup! Merge fixes of inner type decls, enable sorting nested types in one-go --- .../bugpatterns/TypeMemberOrder.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/error-prone-experimental/src/main/java/tech/picnic/errorprone/experimental/bugpatterns/TypeMemberOrder.java b/error-prone-experimental/src/main/java/tech/picnic/errorprone/experimental/bugpatterns/TypeMemberOrder.java index 84f69e74e7..76e4f722ba 100644 --- a/error-prone-experimental/src/main/java/tech/picnic/errorprone/experimental/bugpatterns/TypeMemberOrder.java +++ b/error-prone-experimental/src/main/java/tech/picnic/errorprone/experimental/bugpatterns/TypeMemberOrder.java @@ -89,15 +89,7 @@ public Description matchCompilationUnit( return describeMatch(compilationUnitTree, suggestedFix); } - /** - * Matches a class. - * - * @param tree xxx - * @param state xxx - * @param compilationUnit xxx - * @return xxx - */ - public SuggestedFix matchClass( + private SuggestedFix matchClass( ClassTree tree, VisitorState state, JCTree.JCCompilationUnit compilationUnit) { Kind treeKind = tree.getKind(); if (treeKind != Kind.CLASS && treeKind != Kind.INTERFACE && treeKind != Kind.ENUM) { @@ -267,9 +259,7 @@ private static SuggestedFix sortTypeMembers( return original.equals(replacement) ? SuggestedFix.emptyFix() : SuggestedFix.replace( - original.startPosition(), - original.endPosition(), - replacementSource.toString()); + original.startPosition(), original.endPosition(), replacementSource); }) .reduce(SuggestedFix.builder(), SuggestedFix.Builder::merge, SuggestedFix.Builder::merge) .build(); @@ -296,11 +286,11 @@ abstract static class TypeMember implements Comparable { abstract int endPosition(); - abstract Integer preferredOrdinal(); + abstract int preferredOrdinal(); @Override public int compareTo(TypeMemberOrder.TypeMember o) { - return preferredOrdinal().compareTo(o.preferredOrdinal()); + return Integer.compare(preferredOrdinal(), o.preferredOrdinal()); } } }