From 08501b9b1e1aa057cafa6212e3d6042bf1ba8ef7 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 29 Aug 2023 11:17:33 +0300 Subject: [PATCH] Rebase cleanup --- .../ImmutablesSortedSetComparator.java | 5 ++-- .../bugpatterns/NestedPublishers.java | 5 ++-- .../bugpatterns/PrimitiveComparison.java | 5 ++-- pom.xml | 6 ++-- .../matchers/IsLikelyTrivialComputation.java | 28 +++++++++---------- .../matchers/ThrowsCheckedException.java | 10 ++----- 6 files changed, 27 insertions(+), 32 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparator.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparator.java index 468a2dcc826..0d7446a2066 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparator.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparator.java @@ -43,8 +43,9 @@ @AutoService(BugChecker.class) @BugPattern( summary = - "`SortedSet` properties of a `@Value.Immutable` or `@Value.Modifiable` type must be " - + "annotated with `@Value.NaturalOrder` or `@Value.ReverseOrder`", + """ + `SortedSet` properties of a `@Value.Immutable` or `@Value.Modifiable` type must be \ + annotated with `@Value.NaturalOrder` or `@Value.ReverseOrder`""", link = BUG_PATTERNS_BASE_URL + "ImmutablesSortedSetComparator", linkType = CUSTOM, severity = ERROR, diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java index d4f00b99b13..da0761b4eec 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java @@ -34,8 +34,9 @@ @AutoService(BugChecker.class) @BugPattern( summary = - "Avoid `Publisher`s that emit other `Publishers`s; " - + "the resultant code is hard to reason about", + """ + Avoid `Publisher`s that emit other `Publishers`s; the resultant code is hard to reason \ + about""", link = BUG_PATTERNS_BASE_URL + "NestedPublishers", linkType = CUSTOM, severity = WARNING, diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java index 997a52f644e..28c7b02c776 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java @@ -44,8 +44,9 @@ @AutoService(BugChecker.class) @BugPattern( summary = - "Ensure invocations of `Comparator#comparing{,Double,Int,Long}` match the return type" - + " of the provided function", + """ + Ensure invocations of `Comparator#comparing{,Double,Int,Long}` match the return type of \ + the provided function""", link = BUG_PATTERNS_BASE_URL + "PrimitiveComparison", linkType = CUSTOM, severity = WARNING, diff --git a/pom.xml b/pom.xml index d5d358bbf88..a81a2863708 100644 --- a/pom.xml +++ b/pom.xml @@ -1887,9 +1887,9 @@ true ${version.jdk.source} diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java index 9cfa30b5110..dbf56e80e6b 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java @@ -23,7 +23,7 @@ public IsLikelyTrivialComputation() {} @Override public boolean matches(ExpressionTree expressionTree, VisitorState state) { - if (expressionTree instanceof MethodInvocationTree) { + if (expressionTree instanceof MethodInvocationTree methodInvocation) { // XXX: Method invocations are generally *not* trivial computations, but we make an exception // for nullary method invocations on the result of a trivial computation. This exception // allows this `Matcher` to by the `OptionalOrElseGet` Refaster rule, such that it does not @@ -31,7 +31,6 @@ public boolean matches(ExpressionTree expressionTree, VisitorState state) { // references. Once the `MethodReferenceUsage` bug checker is production-ready, this exception // should be removed. (But at that point, instead defining a `RequiresComputation` matcher may // be more appropriate.) - MethodInvocationTree methodInvocation = (MethodInvocationTree) expressionTree; if (methodInvocation.getArguments().isEmpty() && matches(methodInvocation.getMethodSelect())) { return true; @@ -44,9 +43,8 @@ && matches(methodInvocation.getMethodSelect())) { // XXX: Some `BinaryTree`s may represent what could be considered "trivial computations". // Depending on feedback such trees may be matched in the future. private static boolean matches(ExpressionTree expressionTree) { - if (expressionTree instanceof ArrayAccessTree) { - return matches(((ArrayAccessTree) expressionTree).getExpression()) - && matches(((ArrayAccessTree) expressionTree).getIndex()); + if (expressionTree instanceof ArrayAccessTree arrayAccess) { + return matches(arrayAccess.getExpression()) && matches(arrayAccess.getIndex()); } if (expressionTree instanceof LiteralTree) { @@ -65,26 +63,26 @@ private static boolean matches(ExpressionTree expressionTree) { return true; } - if (expressionTree instanceof MemberReferenceTree) { - return matches(((MemberReferenceTree) expressionTree).getQualifierExpression()); + if (expressionTree instanceof MemberReferenceTree memberReference) { + return matches(memberReference.getQualifierExpression()); } - if (expressionTree instanceof MemberSelectTree) { - return matches(((MemberSelectTree) expressionTree).getExpression()); + if (expressionTree instanceof MemberSelectTree memberSelect) { + return matches(memberSelect.getExpression()); } - if (expressionTree instanceof ParenthesizedTree) { - return matches(((ParenthesizedTree) expressionTree).getExpression()); + if (expressionTree instanceof ParenthesizedTree parenthesized) { + return matches(parenthesized.getExpression()); } - if (expressionTree instanceof TypeCastTree) { - return matches(((TypeCastTree) expressionTree).getExpression()); + if (expressionTree instanceof TypeCastTree typeCast) { + return matches(typeCast.getExpression()); } - if (expressionTree instanceof UnaryTree) { + if (expressionTree instanceof UnaryTree unary) { // XXX: Arguably side-effectful options such as pre- and post-increment and -decrement are not // trivial. - return matches(((UnaryTree) expressionTree).getExpression()); + return matches(unary.getExpression()); } return false; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java index aa11abcdf34..ed758cbcddc 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java @@ -7,7 +7,6 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.LambdaExpressionTree; import com.sun.source.tree.MemberReferenceTree; -import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError; import java.util.Collection; @@ -33,13 +32,8 @@ private static Collection getThrownTypes(ExpressionTree tree, VisitorState return ASTHelpers.getThrownExceptions(lambdaExpression.getBody(), state); } - if (tree instanceof MemberReferenceTree) { - Symbol symbol = ASTHelpers.getSymbol(tree); - if (symbol == null) { - return ImmutableSet.of(); - } - - return symbol.type.getThrownTypes(); + if (tree instanceof MemberReferenceTree memberReference) { + return ASTHelpers.getSymbol(memberReference).type.getThrownTypes(); } Type type = ASTHelpers.getType(tree);