Summary of changes:
- Consolidate the `OptionalOrElseGet` Refaster rule and the
`OptionalOrElse` bug checker into the latter, keeping the best of
both.
- Rename the `OptionalOrElse` bug checker to `OptionalOrElseGet` to
avoid confusion.
- Replace the `IsLikelyTrivialComputation` matcher with the inverse
`RequiresComputation` variant.
- Introduce an `OptionalOrElse` Refaster rule that simplifies
expressions in the "opposite direction".
By raising this baseline the project can now use Java 17 language features such
as text blocks, switch expressions and `instanceof` pattern matching. The code
has been updated to make use of these constructs.
Note that the project can still be used by builds that target an older version
of Java, as long as those builds are executed using JDK 17+.
The new `@TypeMigration` annotation can be placed on Refaster rule
collections to indicate that they migrate most or all public methods of
an indicated type. The new check validates the claim made by the
annotation.
Error Prone checks deal with source code and type matchers, both of
which generally involve canonical type names, rather than the strings
produced by `Class#getName()`. This distinction is particularly relevant
when dealing with nested types.
These changes enable testing of a wider range of `Matcher` implementations. In
a nutshell:
- The `Matcher` under test is now passed `VisitorState` instances with an
accurate `TreePath`.
- The `Matcher` under test is no longer consulted for method select and cast
type expressions, mirroring Refaster behavior.
Flags Mockito mock and spy creation expressions that explicitly specify the
type of mock or spy to create, while this information can also be inferred from
context.
JSpecify's annotations have more well-defined semantics. Its `@Nullable`
annotation is also a type-use annotation recognized by Google Java
Format, so the formatter places it after any field or method modifiers.
See https://jspecify.dev
By emitting a website link, if available, and reporting the matching Refaster
rule in the description's message rather than the check name. Additionally, it
is now possible to provide a custom explanatory text, to assign a custom
severity to Refaster rules, and to override the severity of matches for all
Refaster rules by passing `-Xep:Refaster:[SEVERITY]`.
Violations of Refaster rules defined in this repository now include a link to
the rule's documentation, hosted on https://error-prone.picnic.tech.
This new matcher is used to improve the `AssertThatIsOdd` and
`AssertThatIsEven` Refaster templates.
While there, apply assorted semi-related test improvements.
This rule is implemented using a Refaster template, relying on the new
`ThrowsCheckedException` matcher.
While there, introduce `AbstractTestChecker` to simplify the test setup for
Refaster `Matcher`s. This base class flags all `ExpressionTree`s matched by the
`Matcher` under test.
This new checker inspects inline code passed to `CompilationTestHelper` and
`BugCheckerRefactoringTestHelper` instances. It requires that this code is
properly formatted and that its imports are organized. Only code that
represents the expected output of a refactoring operation is allowed to have
unused imports, as most `BugChecker`s do not (and are not able to) remove
imports that become obsolete as a result of applying their suggested fix(es).