Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
cu.getMarkers().findFirst(JavaVersion.class)
.filter(seen::add)
.map(jv -> new JavaVersionTable.Row(jv.getSourceCompatibility(), jv.getTargetCompatibility()))
.map(jv -> new JavaVersionTable.Row(
Integer.toString(jv.getMajorVersion()),
Integer.toString(jv.getMajorReleaseVersion())))
.ifPresent(row -> table.insertRow(ctx, row));
return cu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public JavaVersionTable(Recipe recipe) {
@Value
public static class Row {
@Column(displayName = "Source compatibility",
description = "The version of Java used to compile the source code")
description = "The major version of Java used to compile the source code")
String sourceVersion;

@Column(displayName = "Target compatibility",
description = "The version of Java the bytecode is compiled to run on")
description = "The major version of Java the bytecode is compiled to run on")
String targetVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.Optional;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -148,10 +149,15 @@ public String test() {
}
}
""",
spec -> spec.afterRecipe(cu ->
assertThat(cu.getMarkers().findFirst(JavaVersion.class))
.map(JavaVersion::getSourceCompatibility)
.hasValue("17"))
spec -> spec.afterRecipe(cu -> {
Optional<JavaVersion> jv = cu.getMarkers().findFirst(JavaVersion.class);
assertThat(jv)
.map(JavaVersion::getSourceCompatibility)
.hasValue("17");
assertThat(jv)
.map(JavaVersion::getMajorVersion)
.hasValue(17);
})
)
)
),
Expand Down