From 470a255b0d9a592f61eab3bfb3880306fc408ce4 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 18 Jan 2023 15:47:50 -0800 Subject: [PATCH] Polish --- .../TypeElementMembers.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java index 8d542b3c2c..d7b073e711 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java @@ -171,21 +171,17 @@ class TypeElementMembers { if (this.isRecord && this.fields.containsKey(methodName)) { return methodName; } - String name; if (methodName.startsWith("is")) { - name = methodName.substring(2); + return lowerCaseFirstCharacter(methodName.substring(2)); } - else if (methodName.startsWith("get")) { - name = methodName.substring(3); + if (methodName.startsWith("get") || methodName.startsWith("set")) { + return lowerCaseFirstCharacter(methodName.substring(3)); } - else if (methodName.startsWith("set")) { - name = methodName.substring(3); - } - else { - throw new AssertionError("methodName must start with 'is', 'get' or 'set', was '" + methodName + "'"); - } - name = Character.toLowerCase(name.charAt(0)) + name.substring(1); - return name; + throw new IllegalStateException("methodName must start with 'is', 'get' or 'set', was '" + methodName + "'"); + } + + private String lowerCaseFirstCharacter(String string) { + return Character.toLowerCase(string.charAt(0)) + string.substring(1); } private void processField(VariableElement field) {