Skip to content

Commit 4beeb8a

Browse files
timtebeekclaude
andauthored
Normalize version numbers in FindJavaVersion (#969)
* Normalize version numbers in `FindJavaVersion` Replace raw version strings with normalized major versions in the `JavaVersionTable` data table. This addresses issue #968 where users expect normalized values like "8" instead of "1.8". - Use `getMajorVersion()` and `getMajorReleaseVersion()` instead of raw `getSourceCompatibility()` and `getTargetCompatibility()` fields - Update column descriptions to clarify they contain major versions Closes #968 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Ensure both are updated in `UpgradeToJava17Test` --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1180190 commit 4beeb8a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/main/java/org/openrewrite/java/migrate/search/FindJavaVersion.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
4646
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
4747
cu.getMarkers().findFirst(JavaVersion.class)
4848
.filter(seen::add)
49-
.map(jv -> new JavaVersionTable.Row(jv.getSourceCompatibility(), jv.getTargetCompatibility()))
49+
.map(jv -> new JavaVersionTable.Row(
50+
Integer.toString(jv.getMajorVersion()),
51+
Integer.toString(jv.getMajorReleaseVersion())))
5052
.ifPresent(row -> table.insertRow(ctx, row));
5153
return cu;
5254
}

src/main/java/org/openrewrite/java/migrate/table/JavaVersionTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public JavaVersionTable(Recipe recipe) {
2929
@Value
3030
public static class Row {
3131
@Column(displayName = "Source compatibility",
32-
description = "The version of Java used to compile the source code")
32+
description = "The major version of Java used to compile the source code")
3333
String sourceVersion;
3434

3535
@Column(displayName = "Target compatibility",
36-
description = "The version of Java the bytecode is compiled to run on")
36+
description = "The major version of Java the bytecode is compiled to run on")
3737
String targetVersion;
3838
}
3939
}

src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.openrewrite.test.RecipeSpec;
2222
import org.openrewrite.test.RewriteTest;
2323

24+
import java.util.Optional;
2425
import java.util.regex.Pattern;
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
@@ -148,10 +149,15 @@ public String test() {
148149
}
149150
}
150151
""",
151-
spec -> spec.afterRecipe(cu ->
152-
assertThat(cu.getMarkers().findFirst(JavaVersion.class))
153-
.map(JavaVersion::getSourceCompatibility)
154-
.hasValue("17"))
152+
spec -> spec.afterRecipe(cu -> {
153+
Optional<JavaVersion> jv = cu.getMarkers().findFirst(JavaVersion.class);
154+
assertThat(jv)
155+
.map(JavaVersion::getSourceCompatibility)
156+
.hasValue("17");
157+
assertThat(jv)
158+
.map(JavaVersion::getMajorVersion)
159+
.hasValue(17);
160+
})
155161
)
156162
)
157163
),

0 commit comments

Comments
 (0)