Remove java.beans dependency of Reflections library
*/
package org.jboss.weld.util.reflection;
-import java.beans.Introspector;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
@@ -111,9 +110,9 @@ public class Reflections {
final String get = "get";
final String is = "is";
if (methodName.startsWith(get)) {
- return Introspector.decapitalize(methodName.substring(get.length()));
+ return decapitalize(methodName.substring(get.length()));
} else if (methodName.startsWith(is)) {
- return Introspector.decapitalize(methodName.substring(is.length()));
+ return decapitalize(methodName.substring(is.length()));
} else {
return null;
}
@@ -493,4 +492,32 @@ public class Reflections {
return ((method.getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC)
&& method.getDeclaringClass().isInterface();
}
+
+ /**
+ * Copy of java.beans.Introspector#decapitalize(name) to reduce java.desktop
+ * module dependency.
+ *
+ * Utility method to take a string and convert it to normal Java variable name
+ * capitalization. This normally means converting the first character from upper
+ * case to lower case, but in the (unusual) special case when there is more than
+ * one character and both the first and second characters are upper case, we
+ * leave it alone.
+ * <p>
+ * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".
+ *
+ * @param name
+ * The string to be decapitalized.
+ * @return The decapitalized version of the string.
+ */
+ public static String decapitalize(String name) {
+ if (name == null || name.length() == 0) {
+ return name;
+ }
+ if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))) {
+ return name;
+ }
+ char[] chars = name.toCharArray();
+ chars[0] = Character.toLowerCase(chars[0]);
+ return new String(chars);
+ }
}
