8009143: Eliminate Dynalink dependency on java.beans
Reviewed-by: jlaskey, lagergren, sundar
--- a/nashorn/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java Tue Feb 26 22:57:51 2013 +0530
+++ b/nashorn/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java Wed Feb 27 15:20:26 2013 +0100
@@ -83,7 +83,6 @@
package jdk.internal.dynalink.beans;
-import java.beans.Introspector;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@@ -136,16 +135,16 @@
// Add the method as a property getter and/or setter
if(name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0) {
// Property getter
- setPropertyGetter(Introspector.decapitalize(name.substring(3)), introspector.unreflect(
+ setPropertyGetter(decapitalize(name.substring(3)), introspector.unreflect(
getMostGenericGetter(method)), ValidationType.INSTANCE_OF);
} else if(name.startsWith("is") && name.length() > 2 && method.getParameterTypes().length == 0 &&
method.getReturnType() == boolean.class) {
// Boolean property getter
- setPropertyGetter(Introspector.decapitalize(name.substring(2)), introspector.unreflect(
+ setPropertyGetter(decapitalize(name.substring(2)), introspector.unreflect(
getMostGenericGetter(method)), ValidationType.INSTANCE_OF);
} else if(name.startsWith("set") && name.length() > 3 && method.getParameterTypes().length == 1) {
// Property setter
- addMember(Introspector.decapitalize(name.substring(3)), methodHandle, propertySetters);
+ addMember(decapitalize(name.substring(3)), methodHandle, propertySetters);
}
}
@@ -170,6 +169,27 @@
}
}
+ private static String decapitalize(String str) {
+ assert str != null;
+ if(str.isEmpty()) {
+ return str;
+ }
+
+ final char c0 = str.charAt(0);
+ if(Character.isLowerCase(c0)) {
+ return str;
+ }
+
+ // If it has two consecutive upper-case characters, i.e. "URL", don't decapitalize
+ if(str.length() > 1 && Character.isUpperCase(str.charAt(1))) {
+ return str;
+ }
+
+ final char c[] = str.toCharArray();
+ c[0] = Character.toLowerCase(c0);
+ return new String(c);
+ }
+
abstract FacetIntrospector createFacetIntrospector();
void setPropertyGetter(String name, MethodHandle handle, ValidationType validationType) {
--- a/nashorn/src/jdk/internal/dynalink/beans/BeansLinker.java Tue Feb 26 22:57:51 2013 +0530
+++ b/nashorn/src/jdk/internal/dynalink/beans/BeansLinker.java Wed Feb 27 15:20:26 2013 +0100
@@ -83,7 +83,6 @@
package jdk.internal.dynalink.beans;
-import java.beans.BeanInfo;
import java.lang.invoke.MethodHandles;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.DynamicLinkerFactory;
@@ -99,11 +98,9 @@
* <ul>
* <li>expose all public methods of form {@code setXxx()}, {@code getXxx()}, and {@code isXxx()} as property setters and
* getters for {@code dyn:setProp} and {@code dyn:getProp} operations;</li>
- * <li>expose all property getters and setters declared by the class' {@link BeanInfo};</li>
- * <li>expose all public methods and methods declared by the class' {@link BeanInfo} for invocation through
- * {@code dyn:callMethod} operation;</li>
- * <li>expose all public methods and methods declared by the class' {@link BeanInfo} for retrieval for
- * {@code dyn:getMethod} operation; the methods thus retrieved can then be invoked using {@code dyn:call};</li>
+ * <li>expose all public methods for invocation through {@code dyn:callMethod} operation;</li>
+ * <li>expose all public methods for retrieval for {@code dyn:getMethod} operation; the methods thus retrieved can then
+ * be invoked using {@code dyn:call};</li>
* <li>expose all public fields as properties, unless there are getters or setters for the properties of the same name;</li>
* <li>expose {@code dyn:getLength}, {@code dyn:getElem} and {@code dyn:setElem} on native Java arrays, as well as
* {@link java.util.List} and {@link java.util.Map} objects; ({@code dyn:getLength} works on any