Skip to content

Commit

Permalink
Rebase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Oct 11, 2023
1 parent e1647c6 commit 13d65c6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1887,9 +1887,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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ 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
// suggest the introduction of lambda expressions that are better expressed as method
// 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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,13 +32,8 @@ private static Collection<Type> 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);
Expand Down

0 comments on commit 13d65c6

Please sign in to comment.