This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new e90de6da59 StringFormatter class
e90de6da59 is described below

commit e90de6da5952a70b687f2c2925e9fdf6142dfc21
Author: James Bognar <[email protected]>
AuthorDate: Fri Nov 28 09:20:19 2025 -0500

    StringFormatter class
---
 .../juneau/common/reflect/ParameterInfo.java       | 33 +++++++++++++++++++++-
 .../apache/juneau/common/utils/StringUtils.java    |  6 +---
 .../apache/juneau/common/utils/ThrowableUtils.java |  4 +--
 .../java/org/apache/juneau/common/utils/Utils.java |  4 +--
 .../src/main/java/org/apache/juneau/ClassMeta.java |  2 +-
 .../main/java/org/apache/juneau/xml/XmlUtils.java  |  2 +-
 6 files changed, 38 insertions(+), 13 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
index 52e6cfda83..19c11db6fb 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/ParameterInfo.java
@@ -16,6 +16,7 @@
  */
 package org.apache.juneau.common.reflect;
 
+import static org.apache.juneau.common.utils.AssertionUtils.*;
 import static org.apache.juneau.common.utils.CollectionUtils.*;
 import static org.apache.juneau.common.utils.Utils.*;
 
@@ -115,13 +116,43 @@ public class ParameterInfo extends ElementInfo implements 
Annotatable {
        private final ResettableSupplier<String> resolvedName = 
memoizeResettable(this::findNameInternal);  // Resolved name from @Name 
annotation or bytecode.
        private final ResettableSupplier<String> resolvedQualifier = 
memoizeResettable(this::findQualifierInternal);  // Resolved qualifier from 
@Named annotation.
 
+       /**
+        * Creates a ParameterInfo wrapper for the specified parameter.
+        *
+        * <p>
+        * This convenience method automatically determines the declaring 
executable from the parameter
+        * and finds the matching ParameterInfo.
+        *
+        * <h5 class='section'>Example:</h5>
+        * <p class='bjava'>
+        *      Parameter <jv>p</jv> = ...;
+        *      ParameterInfo <jv>pi</jv> = 
ParameterInfo.<jsm>of</jsm>(<jv>p</jv>);
+        * </p>
+        *
+        * @param inner The parameter being wrapped. Must not be <jk>null</jk>.
+        * @return A ParameterInfo object wrapping the parameter.
+        * @throws IllegalArgumentException If the parameter is <jk>null</jk> 
or cannot be found in its declaring executable.
+        */
+       public static ParameterInfo of(Parameter inner) {
+               assertArgNotNull("inner", inner);
+               var exec = inner.getDeclaringExecutable();
+               ExecutableInfo execInfo = exec instanceof Constructor ? 
ConstructorInfo.of((Constructor<?>)exec) : MethodInfo.of((Method)exec);
+               var params = execInfo.getParameters();
+               for (var param : params) {
+                       if (param.inner() == inner) {
+                               return param;
+                       }
+               }
+               throw new IllegalArgumentException("Parameter not found in 
declaring executable: " + inner);
+       }
+
        /**
         * Constructor.
         *
         * <p>
         * Creates a new ParameterInfo wrapper for the specified parameter. 
This constructor is protected
         * and should not be called directly. ParameterInfo instances are 
typically obtained from
-        * {@link ExecutableInfo#getParameters()}.
+        * {@link ExecutableInfo#getParameters()} or {@link #of(Parameter)}.
         *
         * @param executable The ExecutableInfo (MethodInfo or ConstructorInfo) 
that contains this parameter.
         * @param inner The parameter being wrapped.
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
index f342752c0f..ac5306f369 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
@@ -847,11 +847,7 @@ public class StringUtils {
         * @see #mformat(String, Object...) for MessageFormat-style formatting
         */
        public static String format(String pattern, Object...args) {
-               if (pattern == null)
-                       return null;
-               if (args == null || args.length == 0)
-                       return pattern;
-               return String.format(pattern, args);
+               return StringFormat.format(pattern, args);
        }
 
        /**
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ThrowableUtils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ThrowableUtils.java
index febed11c07..17ddd6809e 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ThrowableUtils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ThrowableUtils.java
@@ -236,7 +236,7 @@ public class ThrowableUtils {
         * @return A new RuntimeException with the formatted message and cause.
         */
        public static RuntimeException rex(Throwable cause, String msg, 
Object...args) {
-               return new RuntimeException(args.length == 0 ? msg : mf(msg, 
args), cause);
+               return new RuntimeException(mf(msg, args), cause);
        }
 
        /**
@@ -247,7 +247,7 @@ public class ThrowableUtils {
         * @return A new RuntimeException with the formatted message.
         */
        public static BeanRuntimeException bex(String msg, Object...args) {
-               return new BeanRuntimeException(args.length == 0 ? msg : 
mf(msg, args));
+               return new BeanRuntimeException(msg, args);
        }
 
        /**
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
index f07312fb5c..c65d36dc08 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
@@ -296,8 +296,6 @@ public class Utils {
         * @return The formatted string.
         */
        public static String mf(String pattern, Object...args) {
-               if (args.length == 0)
-                       return pattern;
                return StringFormat.format(pattern, args);
        }
 
@@ -403,7 +401,7 @@ public class Utils {
         * @see StringUtils#mformat(String, Object...)
         */
        public static Supplier<String> mfs(String pattern, Object...args) {
-               return () -> mformat(pattern, args);
+               return () -> StringFormat.format(pattern, args);
        }
 
        /**
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index c7ceba9c11..058ca16438 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -1842,7 +1842,7 @@ public class ClassMeta<T> implements Type {
                if (isEnum()) {
                        var t = (T)enumValues.getKey(arg);
                        if (t == null && ! 
beanContext.isIgnoreUnknownEnumValues())
-                               throw new ExecutableException("Could not 
resolve enum value '" + arg + "' on class '" + getInnerClass().getName() + "'");
+                               throw new ExecutableException("Could not 
resolve enum value ''{0}'' on class ''{1}''", arg, getInnerClass().getName());
                        return t;
                }
 
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java
index 5fcf82cb69..41ff285242 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java
@@ -479,7 +479,7 @@ public class XmlUtils {
                                        if (xmlNs.prefix().equals(prefix))
                                                return Namespace.of(prefix, 
xmlNs.namespaceURI());
                        }
-                       throw bex("Found @Xml.prefix annotation with no 
matching URI.  prefix='" + prefix + "'");
+                       throw bex("Found @Xml.prefix annotation with no 
matching URI.  prefix=''{0}''", prefix);
                }
 
                // If only namespaceURI specified, need to search for prefix.

Reply via email to