Rebase cleanup

This commit is contained in:
Stephan Schroevers
2023-08-29 11:17:33 +03:00
parent b9f2f8dd0d
commit 1d625f9f76
6 changed files with 27 additions and 32 deletions

View File

@@ -43,8 +43,9 @@ import javax.lang.model.element.Modifier;
@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,

View File

@@ -34,8 +34,9 @@ import com.sun.tools.javac.code.Type;
@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,

View File

@@ -44,8 +44,9 @@ import tech.picnic.errorprone.bugpatterns.util.SourceCode;
@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,

View File

@@ -1917,9 +1917,9 @@
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<!-- Normal builds use Jabel to target an older JDK version
than what would normally be supported given the language
features used, but this causes Sonar to report parse errors.
So for Sonar builds we target a JDK version that is properly
than any that would normally be supported given the language
features used, but this causes Sonar to report parse errors. So
for Sonar builds we target a JDK version that is properly
compatible with the source code. -->
<version.jdk.target>${version.jdk.source}</version.jdk.target>
</properties>

View File

@@ -23,7 +23,7 @@ public final class IsLikelyTrivialComputation implements Matcher<ExpressionTree>
@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 final class IsLikelyTrivialComputation implements Matcher<ExpressionTree>
// 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 @@ public final class IsLikelyTrivialComputation implements Matcher<ExpressionTree>
// 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 @@ public final class IsLikelyTrivialComputation implements Matcher<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;

View File

@@ -7,7 +7,6 @@ import com.google.errorprone.util.ASTHelpers;
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 @@ public final class ThrowsCheckedException implements Matcher<ExpressionTree> {
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);