1.1 --- a/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java Tue Aug 19 20:43:03 2014 +0100 1.2 +++ b/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java Wed Aug 20 10:25:28 2014 +0200 1.3 @@ -97,7 +97,6 @@ 1.4 import java.util.HashMap; 1.5 import java.util.List; 1.6 import java.util.Map; 1.7 - 1.8 import jdk.internal.dynalink.CallSiteDescriptor; 1.9 import jdk.internal.dynalink.beans.GuardedInvocationComponent.ValidationType; 1.10 import jdk.internal.dynalink.linker.GuardedInvocation; 1.11 @@ -123,18 +122,18 @@ 1.12 private final Map<String, DynamicMethod> propertySetters = new HashMap<>(); 1.13 private final Map<String, DynamicMethod> methods = new HashMap<>(); 1.14 1.15 - AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard) { 1.16 + AbstractJavaLinker(final Class<?> clazz, final MethodHandle classGuard) { 1.17 this(clazz, classGuard, classGuard); 1.18 } 1.19 1.20 - AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard, MethodHandle assignableGuard) { 1.21 + AbstractJavaLinker(final Class<?> clazz, final MethodHandle classGuard, final MethodHandle assignableGuard) { 1.22 this.clazz = clazz; 1.23 this.classGuard = classGuard; 1.24 this.assignableGuard = assignableGuard; 1.25 1.26 final FacetIntrospector introspector = createFacetIntrospector(); 1.27 // Add methods and properties 1.28 - for(Method method: introspector.getMethods()) { 1.29 + for(final Method method: introspector.getMethods()) { 1.30 final String name = method.getName(); 1.31 // Add method 1.32 addMember(name, method, methods); 1.33 @@ -153,7 +152,7 @@ 1.34 } 1.35 1.36 // Add field getter/setters as property getters/setters. 1.37 - for(Field field: introspector.getFields()) { 1.38 + for(final Field field: introspector.getFields()) { 1.39 final String name = field.getName(); 1.40 // Only add a property getter when one is not defined already as a getXxx()/isXxx() method. 1.41 if(!propertyGetters.containsKey(name)) { 1.42 @@ -166,7 +165,7 @@ 1.43 } 1.44 1.45 // Add inner classes, but only those for which we don't hide a property with it 1.46 - for(Map.Entry<String, MethodHandle> innerClassSpec: introspector.getInnerClassGetters().entrySet()) { 1.47 + for(final Map.Entry<String, MethodHandle> innerClassSpec: introspector.getInnerClassGetters().entrySet()) { 1.48 final String name = innerClassSpec.getKey(); 1.49 if(!propertyGetters.containsKey(name)) { 1.50 setPropertyGetter(name, innerClassSpec.getValue(), ValidationType.EXACT_CLASS); 1.51 @@ -174,7 +173,7 @@ 1.52 } 1.53 } 1.54 1.55 - private static String decapitalize(String str) { 1.56 + private static String decapitalize(final String str) { 1.57 assert str != null; 1.58 if(str.isEmpty()) { 1.59 return str; 1.60 @@ -209,7 +208,7 @@ 1.61 return getUnmodifiableKeys(methods); 1.62 } 1.63 1.64 - private static Collection<String> getUnmodifiableKeys(Map<String, ?> m) { 1.65 + private static Collection<String> getUnmodifiableKeys(final Map<String, ?> m) { 1.66 return Collections.unmodifiableCollection(m.keySet()); 1.67 } 1.68 1.69 @@ -222,7 +221,7 @@ 1.70 * @param handle the method handle that implements the property getter 1.71 * @param validationType the validation type for the property 1.72 */ 1.73 - private void setPropertyGetter(String name, SingleDynamicMethod handle, ValidationType validationType) { 1.74 + private void setPropertyGetter(final String name, final SingleDynamicMethod handle, final ValidationType validationType) { 1.75 propertyGetters.put(name, new AnnotatedDynamicMethod(handle, validationType)); 1.76 } 1.77 1.78 @@ -232,7 +231,7 @@ 1.79 * @param prefixLen the getter prefix in the method name; should be 3 for getter names starting with "get" and 2 for 1.80 * names starting with "is". 1.81 */ 1.82 - private void setPropertyGetter(Method getter, int prefixLen) { 1.83 + private void setPropertyGetter(final Method getter, final int prefixLen) { 1.84 setPropertyGetter(decapitalize(getter.getName().substring(prefixLen)), createDynamicMethod( 1.85 getMostGenericGetter(getter)), ValidationType.INSTANCE_OF); 1.86 } 1.87 @@ -246,15 +245,15 @@ 1.88 * @param handle the method handle that implements the property getter 1.89 * @param validationType the validation type for the property 1.90 */ 1.91 - void setPropertyGetter(String name, MethodHandle handle, ValidationType validationType) { 1.92 + void setPropertyGetter(final String name, final MethodHandle handle, final ValidationType validationType) { 1.93 setPropertyGetter(name, new SimpleDynamicMethod(handle, clazz, name), validationType); 1.94 } 1.95 1.96 - private void addMember(String name, AccessibleObject ao, Map<String, DynamicMethod> methodMap) { 1.97 + private void addMember(final String name, final AccessibleObject ao, final Map<String, DynamicMethod> methodMap) { 1.98 addMember(name, createDynamicMethod(ao), methodMap); 1.99 } 1.100 1.101 - private void addMember(String name, SingleDynamicMethod method, Map<String, DynamicMethod> methodMap) { 1.102 + private void addMember(final String name, final SingleDynamicMethod method, final Map<String, DynamicMethod> methodMap) { 1.103 final DynamicMethod existingMethod = methodMap.get(name); 1.104 final DynamicMethod newMethod = mergeMethods(method, existingMethod, clazz, name); 1.105 if(newMethod != existingMethod) { 1.106 @@ -270,9 +269,9 @@ 1.107 * @param name the common name of the reflective members. 1.108 * @return a dynamic method representing all the specified reflective members. 1.109 */ 1.110 - static DynamicMethod createDynamicMethod(Iterable<? extends AccessibleObject> members, Class<?> clazz, String name) { 1.111 + static DynamicMethod createDynamicMethod(final Iterable<? extends AccessibleObject> members, final Class<?> clazz, final String name) { 1.112 DynamicMethod dynMethod = null; 1.113 - for(AccessibleObject method: members) { 1.114 + for(final AccessibleObject method: members) { 1.115 dynMethod = mergeMethods(createDynamicMethod(method), dynMethod, clazz, name); 1.116 } 1.117 return dynMethod; 1.118 @@ -285,7 +284,7 @@ 1.119 * @param m the reflective member 1.120 * @return the single dynamic method representing the reflective member 1.121 */ 1.122 - private static SingleDynamicMethod createDynamicMethod(AccessibleObject m) { 1.123 + private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) { 1.124 if(CallerSensitiveDetector.isCallerSensitive(m)) { 1.125 return new CallerSensitiveDynamicMethod(m); 1.126 } 1.127 @@ -301,7 +300,7 @@ 1.128 * @param m the method or constructor 1.129 * @return the method handle 1.130 */ 1.131 - private static MethodHandle unreflectSafely(AccessibleObject m) { 1.132 + private static MethodHandle unreflectSafely(final AccessibleObject m) { 1.133 if(m instanceof Method) { 1.134 final Method reflMethod = (Method)m; 1.135 final MethodHandle handle = Lookup.PUBLIC.unreflect(reflMethod); 1.136 @@ -313,7 +312,7 @@ 1.137 return StaticClassIntrospector.editConstructorMethodHandle(Lookup.PUBLIC.unreflectConstructor((Constructor<?>)m)); 1.138 } 1.139 1.140 - private static DynamicMethod mergeMethods(SingleDynamicMethod method, DynamicMethod existing, Class<?> clazz, String name) { 1.141 + private static DynamicMethod mergeMethods(final SingleDynamicMethod method, final DynamicMethod existing, final Class<?> clazz, final String name) { 1.142 if(existing == null) { 1.143 return method; 1.144 } else if(existing.contains(method)) { 1.145 @@ -331,7 +330,7 @@ 1.146 } 1.147 1.148 @Override 1.149 - public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices) 1.150 + public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) 1.151 throws Exception { 1.152 final LinkRequest ncrequest = request.withoutRuntimeContext(); 1.153 // BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn". 1.154 @@ -353,8 +352,8 @@ 1.155 return null; 1.156 } 1.157 1.158 - protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor, 1.159 - LinkerServices linkerServices, List<String> operations) throws Exception { 1.160 + protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor, 1.161 + final LinkerServices linkerServices, final List<String> operations) throws Exception { 1.162 if(operations.isEmpty()) { 1.163 return null; 1.164 } 1.165 @@ -374,27 +373,27 @@ 1.166 return null; 1.167 } 1.168 1.169 - static final <T> List<T> pop(List<T> l) { 1.170 + static final <T> List<T> pop(final List<T> l) { 1.171 return l.subList(1, l.size()); 1.172 } 1.173 1.174 - MethodHandle getClassGuard(CallSiteDescriptor desc) { 1.175 + MethodHandle getClassGuard(final CallSiteDescriptor desc) { 1.176 return getClassGuard(desc.getMethodType()); 1.177 } 1.178 1.179 - MethodHandle getClassGuard(MethodType type) { 1.180 + MethodHandle getClassGuard(final MethodType type) { 1.181 return Guards.asType(classGuard, type); 1.182 } 1.183 1.184 - GuardedInvocationComponent getClassGuardedInvocationComponent(MethodHandle invocation, MethodType type) { 1.185 + GuardedInvocationComponent getClassGuardedInvocationComponent(final MethodHandle invocation, final MethodType type) { 1.186 return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, ValidationType.EXACT_CLASS); 1.187 } 1.188 1.189 - private MethodHandle getAssignableGuard(MethodType type) { 1.190 + private MethodHandle getAssignableGuard(final MethodType type) { 1.191 return Guards.asType(assignableGuard, type); 1.192 } 1.193 1.194 - private GuardedInvocation getCallPropWithThis(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) { 1.195 + private GuardedInvocation getCallPropWithThis(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) { 1.196 switch(callSiteDescriptor.getNameTokenCount()) { 1.197 case 3: { 1.198 return createGuardedDynamicMethodInvocation(callSiteDescriptor, linkerServices, 1.199 @@ -406,25 +405,25 @@ 1.200 } 1.201 } 1.202 1.203 - private GuardedInvocation createGuardedDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor, 1.204 - LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap){ 1.205 + private GuardedInvocation createGuardedDynamicMethodInvocation(final CallSiteDescriptor callSiteDescriptor, 1.206 + final LinkerServices linkerServices, final String methodName, final Map<String, DynamicMethod> methodMap){ 1.207 final MethodHandle inv = getDynamicMethodInvocation(callSiteDescriptor, linkerServices, methodName, methodMap); 1.208 return inv == null ? null : new GuardedInvocation(inv, getClassGuard(callSiteDescriptor.getMethodType())); 1.209 } 1.210 1.211 - private static MethodHandle getDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor, 1.212 - LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap) { 1.213 + private static MethodHandle getDynamicMethodInvocation(final CallSiteDescriptor callSiteDescriptor, 1.214 + final LinkerServices linkerServices, final String methodName, final Map<String, DynamicMethod> methodMap) { 1.215 final DynamicMethod dynaMethod = getDynamicMethod(methodName, methodMap); 1.216 return dynaMethod != null ? dynaMethod.getInvocation(callSiteDescriptor, linkerServices) : null; 1.217 } 1.218 1.219 - private static DynamicMethod getDynamicMethod(String methodName, Map<String, DynamicMethod> methodMap) { 1.220 + private static DynamicMethod getDynamicMethod(final String methodName, final Map<String, DynamicMethod> methodMap) { 1.221 final DynamicMethod dynaMethod = methodMap.get(methodName); 1.222 return dynaMethod != null ? dynaMethod : getExplicitSignatureDynamicMethod(methodName, methodMap); 1.223 } 1.224 1.225 - private static SingleDynamicMethod getExplicitSignatureDynamicMethod(String methodName, 1.226 - Map<String, DynamicMethod> methodsMap) { 1.227 + private static SingleDynamicMethod getExplicitSignatureDynamicMethod(final String methodName, 1.228 + final Map<String, DynamicMethod> methodsMap) { 1.229 // What's below is meant to support the "name(type, type, ...)" syntax that programmers can use in a method name 1.230 // to manually pin down an exact overloaded variant. This is not usually required, as the overloaded method 1.231 // resolution works correctly in almost every situation. However, in presence of many language-specific 1.232 @@ -457,8 +456,8 @@ 1.233 private static final MethodHandle CONSTANT_NULL_DROP_METHOD_HANDLE = MethodHandles.dropArguments( 1.234 MethodHandles.constant(Object.class, null), 0, MethodHandle.class); 1.235 1.236 - private GuardedInvocationComponent getPropertySetter(CallSiteDescriptor callSiteDescriptor, 1.237 - LinkerServices linkerServices, List<String> operations) throws Exception { 1.238 + private GuardedInvocationComponent getPropertySetter(final CallSiteDescriptor callSiteDescriptor, 1.239 + final LinkerServices linkerServices, final List<String> operations) throws Exception { 1.240 final MethodType type = callSiteDescriptor.getMethodType(); 1.241 switch(callSiteDescriptor.getNameTokenCount()) { 1.242 case 2: { 1.243 @@ -543,8 +542,8 @@ 1.244 "getTarget", MethodType.methodType(MethodHandle.class, MethodHandles.Lookup.class)); 1.245 private static final MethodHandle GETTER_INVOKER = MethodHandles.invoker(MethodType.methodType(Object.class, Object.class)); 1.246 1.247 - private GuardedInvocationComponent getPropertyGetter(CallSiteDescriptor callSiteDescriptor, 1.248 - LinkerServices linkerServices, List<String> ops) throws Exception { 1.249 + private GuardedInvocationComponent getPropertyGetter(final CallSiteDescriptor callSiteDescriptor, 1.250 + final LinkerServices linkerServices, final List<String> ops) throws Exception { 1.251 final MethodType type = callSiteDescriptor.getMethodType(); 1.252 switch(callSiteDescriptor.getNameTokenCount()) { 1.253 case 2: { 1.254 @@ -622,7 +621,7 @@ 1.255 } 1.256 } 1.257 1.258 - private MethodHandle getGuard(ValidationType validationType, MethodType methodType) { 1.259 + private MethodHandle getGuard(final ValidationType validationType, final MethodType methodType) { 1.260 switch(validationType) { 1.261 case EXACT_CLASS: { 1.262 return getClassGuard(methodType); 1.263 @@ -646,8 +645,8 @@ 1.264 MethodType.methodType(boolean.class, DynamicMethod.class)); 1.265 private static final MethodHandle DYNAMIC_METHOD_IDENTITY = MethodHandles.identity(DynamicMethod.class); 1.266 1.267 - private GuardedInvocationComponent getMethodGetter(CallSiteDescriptor callSiteDescriptor, 1.268 - LinkerServices linkerServices, List<String> ops) throws Exception { 1.269 + private GuardedInvocationComponent getMethodGetter(final CallSiteDescriptor callSiteDescriptor, 1.270 + final LinkerServices linkerServices, final List<String> ops) throws Exception { 1.271 final MethodType type = callSiteDescriptor.getMethodType(); 1.272 switch(callSiteDescriptor.getNameTokenCount()) { 1.273 case 2: { 1.274 @@ -704,7 +703,7 @@ 1.275 } 1.276 } 1.277 1.278 - private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount) { 1.279 + private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) { 1.280 if(descriptor.getMethodType().parameterCount() != paramCount) { 1.281 throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters."); 1.282 } 1.283 @@ -719,7 +718,7 @@ 1.284 * @return the method handle for retrieving the property, or null if the property does not exist 1.285 */ 1.286 @SuppressWarnings("unused") 1.287 - private Object getPropertyGetterHandle(Object id) { 1.288 + private Object getPropertyGetterHandle(final Object id) { 1.289 return propertyGetters.get(id); 1.290 } 1.291 1.292 @@ -733,8 +732,8 @@ 1.293 private final MethodHandle getPropertySetterHandle = GET_PROPERTY_SETTER_HANDLE.bindTo(this); 1.294 1.295 @SuppressWarnings("unused") 1.296 - private MethodHandle getPropertySetterHandle(CallSiteDescriptor setterDescriptor, LinkerServices linkerServices, 1.297 - Object id) { 1.298 + private MethodHandle getPropertySetterHandle(final CallSiteDescriptor setterDescriptor, final LinkerServices linkerServices, 1.299 + final Object id) { 1.300 return getDynamicMethodInvocation(setterDescriptor, linkerServices, String.valueOf(id), propertySetters); 1.301 } 1.302 1.303 @@ -743,7 +742,7 @@ 1.304 private final MethodHandle getDynamicMethod = GET_DYNAMIC_METHOD.bindTo(this); 1.305 1.306 @SuppressWarnings("unused") 1.307 - private DynamicMethod getDynamicMethod(Object name) { 1.308 + private DynamicMethod getDynamicMethod(final Object name) { 1.309 return getDynamicMethod(String.valueOf(name), methods); 1.310 } 1.311 1.312 @@ -754,7 +753,7 @@ 1.313 * @return the dynamic method (either {@link SimpleDynamicMethod} or {@link OverloadedDynamicMethod}, or null if the 1.314 * method with the specified name does not exist. 1.315 */ 1.316 - DynamicMethod getDynamicMethod(String name) { 1.317 + DynamicMethod getDynamicMethod(final String name) { 1.318 return getDynamicMethod(name, methods); 1.319 } 1.320 1.321 @@ -765,16 +764,16 @@ 1.322 * @param getter the getter 1.323 * @return getter with same name, declared on the most generic superclass/interface of the declaring class 1.324 */ 1.325 - private static Method getMostGenericGetter(Method getter) { 1.326 + private static Method getMostGenericGetter(final Method getter) { 1.327 return getMostGenericGetter(getter.getName(), getter.getReturnType(), getter.getDeclaringClass()); 1.328 } 1.329 1.330 - private static Method getMostGenericGetter(String name, Class<?> returnType, Class<?> declaringClass) { 1.331 + private static Method getMostGenericGetter(final String name, final Class<?> returnType, final Class<?> declaringClass) { 1.332 if(declaringClass == null) { 1.333 return null; 1.334 } 1.335 // Prefer interfaces 1.336 - for(Class<?> itf: declaringClass.getInterfaces()) { 1.337 + for(final Class<?> itf: declaringClass.getInterfaces()) { 1.338 final Method itfGetter = getMostGenericGetter(name, returnType, itf); 1.339 if(itfGetter != null) { 1.340 return itfGetter; 1.341 @@ -787,7 +786,7 @@ 1.342 if(!CheckRestrictedPackage.isRestrictedClass(declaringClass)) { 1.343 try { 1.344 return declaringClass.getMethod(name); 1.345 - } catch(NoSuchMethodException e) { 1.346 + } catch(final NoSuchMethodException e) { 1.347 // Intentionally ignored, meant to fall through 1.348 } 1.349 } 1.350 @@ -798,18 +797,18 @@ 1.351 private final SingleDynamicMethod method; 1.352 /*private*/ final ValidationType validationType; 1.353 1.354 - AnnotatedDynamicMethod(SingleDynamicMethod method, ValidationType validationType) { 1.355 + AnnotatedDynamicMethod(final SingleDynamicMethod method, final ValidationType validationType) { 1.356 this.method = method; 1.357 this.validationType = validationType; 1.358 } 1.359 1.360 - MethodHandle getInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) { 1.361 + MethodHandle getInvocation(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) { 1.362 return method.getInvocation(callSiteDescriptor, linkerServices); 1.363 } 1.364 1.365 @SuppressWarnings("unused") 1.366 - MethodHandle getTarget(MethodHandles.Lookup lookup) { 1.367 - MethodHandle inv = method.getTarget(lookup); 1.368 + MethodHandle getTarget(final MethodHandles.Lookup lookup) { 1.369 + final MethodHandle inv = method.getTarget(lookup); 1.370 assert inv != null; 1.371 return inv; 1.372 }