Wed, 27 Feb 2013 15:20:26 +0100
8009143: Eliminate Dynalink dependency on java.beans
Reviewed-by: jlaskey, lagergren, sundar
1.1 --- a/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java Tue Feb 26 22:57:51 2013 +0530 1.2 +++ b/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java Wed Feb 27 15:20:26 2013 +0100 1.3 @@ -83,7 +83,6 @@ 1.4 1.5 package jdk.internal.dynalink.beans; 1.6 1.7 -import java.beans.Introspector; 1.8 import java.lang.invoke.MethodHandle; 1.9 import java.lang.invoke.MethodHandles; 1.10 import java.lang.invoke.MethodType; 1.11 @@ -136,16 +135,16 @@ 1.12 // Add the method as a property getter and/or setter 1.13 if(name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0) { 1.14 // Property getter 1.15 - setPropertyGetter(Introspector.decapitalize(name.substring(3)), introspector.unreflect( 1.16 + setPropertyGetter(decapitalize(name.substring(3)), introspector.unreflect( 1.17 getMostGenericGetter(method)), ValidationType.INSTANCE_OF); 1.18 } else if(name.startsWith("is") && name.length() > 2 && method.getParameterTypes().length == 0 && 1.19 method.getReturnType() == boolean.class) { 1.20 // Boolean property getter 1.21 - setPropertyGetter(Introspector.decapitalize(name.substring(2)), introspector.unreflect( 1.22 + setPropertyGetter(decapitalize(name.substring(2)), introspector.unreflect( 1.23 getMostGenericGetter(method)), ValidationType.INSTANCE_OF); 1.24 } else if(name.startsWith("set") && name.length() > 3 && method.getParameterTypes().length == 1) { 1.25 // Property setter 1.26 - addMember(Introspector.decapitalize(name.substring(3)), methodHandle, propertySetters); 1.27 + addMember(decapitalize(name.substring(3)), methodHandle, propertySetters); 1.28 } 1.29 } 1.30 1.31 @@ -170,6 +169,27 @@ 1.32 } 1.33 } 1.34 1.35 + private static String decapitalize(String str) { 1.36 + assert str != null; 1.37 + if(str.isEmpty()) { 1.38 + return str; 1.39 + } 1.40 + 1.41 + final char c0 = str.charAt(0); 1.42 + if(Character.isLowerCase(c0)) { 1.43 + return str; 1.44 + } 1.45 + 1.46 + // If it has two consecutive upper-case characters, i.e. "URL", don't decapitalize 1.47 + if(str.length() > 1 && Character.isUpperCase(str.charAt(1))) { 1.48 + return str; 1.49 + } 1.50 + 1.51 + final char c[] = str.toCharArray(); 1.52 + c[0] = Character.toLowerCase(c0); 1.53 + return new String(c); 1.54 + } 1.55 + 1.56 abstract FacetIntrospector createFacetIntrospector(); 1.57 1.58 void setPropertyGetter(String name, MethodHandle handle, ValidationType validationType) {
2.1 --- a/src/jdk/internal/dynalink/beans/BeansLinker.java Tue Feb 26 22:57:51 2013 +0530 2.2 +++ b/src/jdk/internal/dynalink/beans/BeansLinker.java Wed Feb 27 15:20:26 2013 +0100 2.3 @@ -83,7 +83,6 @@ 2.4 2.5 package jdk.internal.dynalink.beans; 2.6 2.7 -import java.beans.BeanInfo; 2.8 import java.lang.invoke.MethodHandles; 2.9 import jdk.internal.dynalink.CallSiteDescriptor; 2.10 import jdk.internal.dynalink.DynamicLinkerFactory; 2.11 @@ -99,11 +98,9 @@ 2.12 * <ul> 2.13 * <li>expose all public methods of form {@code setXxx()}, {@code getXxx()}, and {@code isXxx()} as property setters and 2.14 * getters for {@code dyn:setProp} and {@code dyn:getProp} operations;</li> 2.15 - * <li>expose all property getters and setters declared by the class' {@link BeanInfo};</li> 2.16 - * <li>expose all public methods and methods declared by the class' {@link BeanInfo} for invocation through 2.17 - * {@code dyn:callMethod} operation;</li> 2.18 - * <li>expose all public methods and methods declared by the class' {@link BeanInfo} for retrieval for 2.19 - * {@code dyn:getMethod} operation; the methods thus retrieved can then be invoked using {@code dyn:call};</li> 2.20 + * <li>expose all public methods for invocation through {@code dyn:callMethod} operation;</li> 2.21 + * <li>expose all public methods for retrieval for {@code dyn:getMethod} operation; the methods thus retrieved can then 2.22 + * be invoked using {@code dyn:call};</li> 2.23 * <li>expose all public fields as properties, unless there are getters or setters for the properties of the same name;</li> 2.24 * <li>expose {@code dyn:getLength}, {@code dyn:getElem} and {@code dyn:setElem} on native Java arrays, as well as 2.25 * {@link java.util.List} and {@link java.util.Map} objects; ({@code dyn:getLength} works on any