Skip to content

Commit 316f660

Browse files
Add InstanceOfPatternMatch recipe to java-version-17.yml (#179)
* Add `InstanceOfPatternMatch` recipe to `java-version-17.yml` Related: openrewrite/rewrite#2690 * Move InstanceOfPatternMatch under UpgradeToJava17 * Add test for `InstanceOfPatternMatch` recipe --------- Co-authored-by: Tim te Beek <[email protected]>
1 parent 8c7d4ee commit 316f660

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/resources/META-INF/rewrite/java-version-17.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ recipeList:
3232
- org.openrewrite.java.migrate.lang.StringFormatted
3333
- org.openrewrite.java.migrate.lombok.UpdateLombokToJava17
3434
- org.openrewrite.github.SetupJavaUpgradeJavaVersion
35+
- org.openrewrite.java.InstanceOfPatternMatch
3536
---
3637
type: specs.openrewrite.org/v1beta/recipe
3738
name: org.openrewrite.java.migrate.JavaVersion17

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ public void test() {
9191
// This is a comment
9292
Set<String> stringSet = Collections.singleton("aaa");
9393
List<String> stringList = Collections.singletonList("bbb");
94-
Map<String, String> stringMap = Collections.singletonMap("a-key", "a-value");
94+
Map<String, Object> stringMap = Collections.singletonMap("a-key", "a-value");
95+
Object value = stringMap.get("a-key");
96+
if (value instanceof String) {
97+
System.out.println(((String) value).length());
98+
}
9599
}
96100
}
97101
""",
@@ -110,7 +114,11 @@ public void test() {
110114
// This is a comment
111115
Set<String> stringSet = Set.of("aaa");
112116
List<String> stringList = List.of("bbb");
113-
Map<String, String> stringMap = Map.of("a-key", "a-value");
117+
Map<String, Object> stringMap = Map.of("a-key", "a-value");
118+
Object value = stringMap.get("a-key");
119+
if (value instanceof String s) {
120+
System.out.println(s.length());
121+
}
114122
}
115123
}
116124
"""

0 commit comments

Comments
 (0)