You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/06/01 07:16:47 UTC
(groovy) branch master updated: GROOVY-12055: Assess toLower/UpperCase calls which should use Locale.ROOT (cont'd)
This is an automated email from the ASF dual-hosted git repository.
paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 2fa2df78c9 GROOVY-12055: Assess toLower/UpperCase calls which should use Locale.ROOT (cont'd)
2fa2df78c9 is described below
commit 2fa2df78c91e928421a5d5ecc5965af1cb8fa7b5
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Jun 1 17:16:37 2026 +1000
GROOVY-12055: Assess toLower/UpperCase calls which should use Locale.ROOT (cont'd)
---
.../groovy/ast/tools/ClassNodeUtilsTest.groovy | 54 ++++++++++++++++++++++
.../org/apache/groovy/antlr/GroovydocVisitor.java | 3 +-
.../groovy/jmx/builder/JmxBuilderTools.groovy | 6 +--
3 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/src/test/groovy/org/apache/groovy/ast/tools/ClassNodeUtilsTest.groovy b/src/test/groovy/org/apache/groovy/ast/tools/ClassNodeUtilsTest.groovy
new file mode 100644
index 0000000000..a88570c8e9
--- /dev/null
+++ b/src/test/groovy/org/apache/groovy/ast/tools/ClassNodeUtilsTest.groovy
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.ast.tools
+
+import org.junit.jupiter.api.Test
+
+import static org.apache.groovy.ast.tools.ClassNodeUtils.getPropNameForAccessor
+import static org.junit.jupiter.api.Assertions.assertEquals
+
+/**
+ * Tests for {@link ClassNodeUtils}.
+ */
+final class ClassNodeUtilsTest {
+
+ @Test
+ void 'getPropNameForAccessor strips the accessor prefix'() {
+ assertEquals('age', getPropNameForAccessor('getAge'))
+ assertEquals('age', getPropNameForAccessor('setAge'))
+ assertEquals('active', getPropNameForAccessor('isActive'))
+ assertEquals('x', getPropNameForAccessor('getX'))
+ }
+
+ @Test
+ void 'getPropNameForAccessor uses JavaBean decapitalization for acronyms'() {
+ // GROOVY-12055 follow-up: must match the runtime rule (MetaClassImpl uses
+ // BeanUtils.decapitalize), e.g. getURL -> URL, not uRL
+ assertEquals('URL', getPropNameForAccessor('getURL'))
+ assertEquals('URL', getPropNameForAccessor('setURL'))
+ assertEquals('URLConnection', getPropNameForAccessor('getURLConnection'))
+ }
+
+ @Test
+ void 'getPropNameForAccessor returns the original when not a valid accessor'() {
+ assertEquals('foo', getPropNameForAccessor('foo'))
+ assertEquals('get', getPropNameForAccessor('get'))
+ assertEquals('is', getPropNameForAccessor('is'))
+ }
+}
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
index 5466299d70..9bdec2febe 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
@@ -66,6 +66,7 @@ import java.util.Properties;
import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.deemedInternal;
import static org.apache.groovy.ast.tools.ExpressionUtils.transformInlineConstants;
+import static org.codehaus.groovy.runtime.StringGroovyMethods.uncapitalize;
import static org.codehaus.groovy.transform.trait.Traits.isTrait;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PROTECTED;
@@ -605,7 +606,7 @@ public class GroovydocVisitor extends ClassCodeVisitorSupport {
if (methodDoc.name().equals(expectedMethodName)) {
//extract the field name
- String fieldName = propName.substring(0, 1).toLowerCase() + propName.substring(1);
+ String fieldName = uncapitalize(propName);
SimpleGroovyFieldDoc currentFieldDoc = new SimpleGroovyFieldDoc(fieldName, classDoc);
//find the type of the field; if it's a setter, need to get the type of the params
diff --git a/subprojects/groovy-jmx/src/main/groovy/groovy/jmx/builder/JmxBuilderTools.groovy b/subprojects/groovy-jmx/src/main/groovy/groovy/jmx/builder/JmxBuilderTools.groovy
index 34559b2bd4..f1503d1638 100644
--- a/subprojects/groovy-jmx/src/main/groovy/groovy/jmx/builder/JmxBuilderTools.groovy
+++ b/subprojects/groovy-jmx/src/main/groovy/groovy/jmx/builder/JmxBuilderTools.groovy
@@ -223,8 +223,7 @@ class JmxBuilderTools {
*/
static String capitalize(String value) {
if (!value) return null
- if (value.length() == 1) return value.toUpperCase()
- return (value.length() > 1) ? value[0].toUpperCase() + value[1..-1] : value.toUpperCase()
+ value.capitalize()
}
/**
@@ -234,8 +233,7 @@ class JmxBuilderTools {
*/
static String uncapitalize(String value) {
if (!value) return null
- if (value.length() == 1) return value.toLowerCase()
- return (value.length() > 1) ? value[0].toLowerCase() + value[1..-1] : value.toLowerCase()
+ value.uncapitalize()
}
/**