File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
main/java/org/openrewrite/spring
test/kotlin/org/openrewrite/spring Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments