# HG changeset patch # User attila # Date 1361974826 -3600 # Node ID cd471d62bb6ab60046dd49755f956eb86830e5d5 # Parent bd8e2707574af204f6a256d01e5c7ef06e4afb39 8009143: Eliminate Dynalink dependency on java.beans Reviewed-by: jlaskey, lagergren, sundar diff -r bd8e2707574a -r cd471d62bb6a nashorn/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java --- 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) { diff -r bd8e2707574a -r cd471d62bb6a nashorn/src/jdk/internal/dynalink/beans/BeansLinker.java --- 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 @@ *