Skip to content

Commit

Permalink
Rebase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Aug 29, 2023
1 parent 5d4cf5f commit e124955
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-jdk11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
# the code is compiled using JDK 17, while the tests are executed
# using JDK 11.
- name: Check out code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false
- name: Set up JDK
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
with:
java-version: |
11.0.19
Expand Down
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 @@ -1892,9 +1892,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 e124955

Please sign in to comment.