Skip to content

Commit 8ce19f9

Browse files
committed
Don't replace web annotation names that aren't camel cased
1 parent 610c949 commit 8ce19f9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/java/org/openrewrite/spring/ImplicitWebAnnotationNames.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private Optional<J.Literal> nameArgumentValue(J.Annotation annotation) {
100100
.findAny()
101101
.flatMap(arg -> arg.whenType(J.Assign.class)
102102
.map(assign -> assign.getAssignment().whenType(J.Literal.class))
103-
.orElse(arg.whenType(J.Literal.class)));
103+
.orElse(arg.whenType(J.Literal.class)))
104+
.filter(value -> value.getValue().toString().matches("[a-z][A-Za-z0-9]*"));
104105
}
105106
}

src/test/kotlin/org/openrewrite/spring/ImplicitWebAnnotationNamesTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,29 @@ class ImplicitWebAnnotationNamesTest {
128128
}
129129
""")
130130
}
131+
132+
@Test
133+
fun onlyDropCamelCasedNames() {
134+
val controller = jp.parse("""
135+
import org.springframework.web.bind.annotation.*;
136+
137+
public class UsersController {
138+
public ResponseEntity<String> getUser(@PathVariable("id") Long id,
139+
@PathVariable(value = "another_name") Long anotherName) {
140+
}
141+
}
142+
""".trimIndent())
143+
144+
val fixed = controller.refactor().visit(ImplicitWebAnnotationNames()).fix().fixed
145+
146+
assertRefactored(fixed, """
147+
import org.springframework.web.bind.annotation.*;
148+
149+
public class UsersController {
150+
public ResponseEntity<String> getUser(@PathVariable Long id,
151+
@PathVariable(value = "another_name") Long anotherName) {
152+
}
153+
}
154+
""")
155+
}
131156
}

0 commit comments

Comments
 (0)