Require JDK 17 rather than JDK 11 (#603)

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+.
This commit is contained in:
Stephan Schroevers
2024-02-11 16:57:13 +01:00
committed by GitHub
parent 1f50772433
commit 433b8b90c0
46 changed files with 283 additions and 315 deletions

View File

@@ -106,9 +106,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs combine.children="append">
<arg>-Xplugin:RefasterRuleCompiler</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>

View File

@@ -154,8 +154,8 @@ public final class RefasterRuleCollection extends BugChecker implements Compilat
String expectedClassName = ruleCollectionUnderTest + "Test";
for (Tree typeDeclaration : tree.getTypeDecls()) {
if (typeDeclaration instanceof ClassTree) {
if (!((ClassTree) typeDeclaration).getSimpleName().contentEquals(expectedClassName)) {
if (typeDeclaration instanceof ClassTree classTree) {
if (!classTree.getSimpleName().contentEquals(expectedClassName)) {
state.reportMatch(
describeMatch(
typeDeclaration,
@@ -276,9 +276,10 @@ public final class RefasterRuleCollection extends BugChecker implements Compilat
unexpectedMatchesByLineNumber.entries().stream()
.map(
e ->
String.format(
"Rule `%s` matches on line %s, while it should match in a method named `test%s`.",
e.getValue(), e.getKey(), e.getValue()))
"""
Rule `%s` matches on line %s, while it should match in a method named \
`test%s`."""
.formatted(e.getValue(), e.getKey(), e.getValue()))
.collect(toImmutableSet()),
state);
}