nashorn/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java
changeset 24778 2ff5d7041566
parent 24719 f726e9d67629
child 25252 e8bfc909db53
--- a/nashorn/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Wed Jun 04 13:55:21 2014 +0530
+++ b/nashorn/src/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Wed Jun 04 13:08:57 2014 +0200
@@ -123,18 +123,18 @@
     private final Map<String, DynamicMethod> propertySetters = new HashMap<>();
     private final Map<String, DynamicMethod> methods = new HashMap<>();
 
-    AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard) {
+    AbstractJavaLinker(final Class<?> clazz, final MethodHandle classGuard) {
         this(clazz, classGuard, classGuard);
     }
 
-    AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard, MethodHandle assignableGuard) {
+    AbstractJavaLinker(final Class<?> clazz, final MethodHandle classGuard, final MethodHandle assignableGuard) {
         this.clazz = clazz;
         this.classGuard = classGuard;
         this.assignableGuard = assignableGuard;
 
         final FacetIntrospector introspector = createFacetIntrospector();
         // Add methods and properties
-        for(Method method: introspector.getMethods()) {
+        for(final Method method: introspector.getMethods()) {
             final String name = method.getName();
             // Add method
             addMember(name, method, methods);
@@ -153,7 +153,7 @@
         }
 
         // Add field getter/setters as property getters/setters.
-        for(Field field: introspector.getFields()) {
+        for(final Field field: introspector.getFields()) {
             final String name = field.getName();
             // Only add a property getter when one is not defined already as a getXxx()/isXxx() method.
             if(!propertyGetters.containsKey(name)) {
@@ -166,7 +166,7 @@
         }
 
         // Add inner classes, but only those for which we don't hide a property with it
-        for(Map.Entry<String, MethodHandle> innerClassSpec: introspector.getInnerClassGetters().entrySet()) {
+        for(final Map.Entry<String, MethodHandle> innerClassSpec: introspector.getInnerClassGetters().entrySet()) {
             final String name = innerClassSpec.getKey();
             if(!propertyGetters.containsKey(name)) {
                 setPropertyGetter(name, innerClassSpec.getValue(), ValidationType.EXACT_CLASS);
@@ -174,7 +174,7 @@
         }
     }
 
-    private static String decapitalize(String str) {
+    private static String decapitalize(final String str) {
         assert str != null;
         if(str.isEmpty()) {
             return str;
@@ -209,7 +209,7 @@
         return getUnmodifiableKeys(methods);
     }
 
-    private static Collection<String> getUnmodifiableKeys(Map<String, ?> m) {
+    private static Collection<String> getUnmodifiableKeys(final Map<String, ?> m) {
         return Collections.unmodifiableCollection(m.keySet());
     }
 
@@ -222,7 +222,7 @@
      * @param handle the method handle that implements the property getter
      * @param validationType the validation type for the property
      */
-    private void setPropertyGetter(String name, SingleDynamicMethod handle, ValidationType validationType) {
+    private void setPropertyGetter(final String name, final SingleDynamicMethod handle, final ValidationType validationType) {
         propertyGetters.put(name, new AnnotatedDynamicMethod(handle, validationType));
     }
 
@@ -232,7 +232,7 @@
      * @param prefixLen the getter prefix in the method name; should be 3 for getter names starting with "get" and 2 for
      * names starting with "is".
      */
-    private void setPropertyGetter(Method getter, int prefixLen) {
+    private void setPropertyGetter(final Method getter, final int prefixLen) {
         setPropertyGetter(decapitalize(getter.getName().substring(prefixLen)), createDynamicMethod(
                 getMostGenericGetter(getter)), ValidationType.INSTANCE_OF);
     }
@@ -246,15 +246,15 @@
      * @param handle the method handle that implements the property getter
      * @param validationType the validation type for the property
      */
-    void setPropertyGetter(String name, MethodHandle handle, ValidationType validationType) {
+    void setPropertyGetter(final String name, final MethodHandle handle, final ValidationType validationType) {
         setPropertyGetter(name, new SimpleDynamicMethod(handle, clazz, name), validationType);
     }
 
-    private void addMember(String name, AccessibleObject ao, Map<String, DynamicMethod> methodMap) {
+    private void addMember(final String name, final AccessibleObject ao, final Map<String, DynamicMethod> methodMap) {
         addMember(name, createDynamicMethod(ao), methodMap);
     }
 
-    private void addMember(String name, SingleDynamicMethod method, Map<String, DynamicMethod> methodMap) {
+    private void addMember(final String name, final SingleDynamicMethod method, final Map<String, DynamicMethod> methodMap) {
         final DynamicMethod existingMethod = methodMap.get(name);
         final DynamicMethod newMethod = mergeMethods(method, existingMethod, clazz, name);
         if(newMethod != existingMethod) {
@@ -270,9 +270,9 @@
      * @param name the common name of the reflective members.
      * @return a dynamic method representing all the specified reflective members.
      */
-    static DynamicMethod createDynamicMethod(Iterable<? extends AccessibleObject> members, Class<?> clazz, String name) {
+    static DynamicMethod createDynamicMethod(final Iterable<? extends AccessibleObject> members, final Class<?> clazz, final String name) {
         DynamicMethod dynMethod = null;
-        for(AccessibleObject method: members) {
+        for(final AccessibleObject method: members) {
             dynMethod = mergeMethods(createDynamicMethod(method), dynMethod, clazz, name);
         }
         return dynMethod;
@@ -285,7 +285,7 @@
      * @param m the reflective member
      * @return the single dynamic method representing the reflective member
      */
-    private static SingleDynamicMethod createDynamicMethod(AccessibleObject m) {
+    private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
         if(CallerSensitiveDetector.isCallerSensitive(m)) {
             return new CallerSensitiveDynamicMethod(m);
         }
@@ -301,7 +301,7 @@
      * @param m the method or constructor
      * @return the method handle
      */
-    private static MethodHandle unreflectSafely(AccessibleObject m) {
+    private static MethodHandle unreflectSafely(final AccessibleObject m) {
         if(m instanceof Method) {
             final Method reflMethod = (Method)m;
             final MethodHandle handle = Lookup.PUBLIC.unreflect(reflMethod);
@@ -313,7 +313,7 @@
         return StaticClassIntrospector.editConstructorMethodHandle(Lookup.PUBLIC.unreflectConstructor((Constructor<?>)m));
     }
 
-    private static DynamicMethod mergeMethods(SingleDynamicMethod method, DynamicMethod existing, Class<?> clazz, String name) {
+    private static DynamicMethod mergeMethods(final SingleDynamicMethod method, final DynamicMethod existing, final Class<?> clazz, final String name) {
         if(existing == null) {
             return method;
         } else if(existing.contains(method)) {
@@ -331,7 +331,7 @@
     }
 
     @Override
-    public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
+    public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
             throws Exception {
         final LinkRequest ncrequest = request.withoutRuntimeContext();
         // BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn".
@@ -353,8 +353,8 @@
         return null;
     }
 
-    protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor,
-            LinkerServices linkerServices, List<String> operations) throws Exception {
+    protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
+            final LinkerServices linkerServices, final List<String> operations) throws Exception {
         if(operations.isEmpty()) {
             return null;
         }
@@ -374,27 +374,27 @@
         return null;
     }
 
-    static final <T> List<T> pop(List<T> l) {
+    static final <T> List<T> pop(final List<T> l) {
         return l.subList(1, l.size());
     }
 
-    MethodHandle getClassGuard(CallSiteDescriptor desc) {
+    MethodHandle getClassGuard(final CallSiteDescriptor desc) {
         return getClassGuard(desc.getMethodType());
     }
 
-    MethodHandle getClassGuard(MethodType type) {
+    MethodHandle getClassGuard(final MethodType type) {
         return Guards.asType(classGuard, type);
     }
 
-    GuardedInvocationComponent getClassGuardedInvocationComponent(MethodHandle invocation, MethodType type) {
+    GuardedInvocationComponent getClassGuardedInvocationComponent(final MethodHandle invocation, final MethodType type) {
         return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, ValidationType.EXACT_CLASS);
     }
 
-    private MethodHandle getAssignableGuard(MethodType type) {
+    private MethodHandle getAssignableGuard(final MethodType type) {
         return Guards.asType(assignableGuard, type);
     }
 
-    private GuardedInvocation getCallPropWithThis(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) {
+    private GuardedInvocation getCallPropWithThis(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) {
         switch(callSiteDescriptor.getNameTokenCount()) {
             case 3: {
                 return createGuardedDynamicMethodInvocation(callSiteDescriptor, linkerServices,
@@ -406,25 +406,25 @@
         }
     }
 
-    private GuardedInvocation createGuardedDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor,
-            LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap){
+    private GuardedInvocation createGuardedDynamicMethodInvocation(final CallSiteDescriptor callSiteDescriptor,
+            final LinkerServices linkerServices, final String methodName, final Map<String, DynamicMethod> methodMap){
         final MethodHandle inv = getDynamicMethodInvocation(callSiteDescriptor, linkerServices, methodName, methodMap);
         return inv == null ? null : new GuardedInvocation(inv, getClassGuard(callSiteDescriptor.getMethodType()));
     }
 
-    private static MethodHandle getDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor,
-            LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap) {
+    private static MethodHandle getDynamicMethodInvocation(final CallSiteDescriptor callSiteDescriptor,
+            final LinkerServices linkerServices, final String methodName, final Map<String, DynamicMethod> methodMap) {
         final DynamicMethod dynaMethod = getDynamicMethod(methodName, methodMap);
         return dynaMethod != null ? dynaMethod.getInvocation(callSiteDescriptor, linkerServices) : null;
     }
 
-    private static DynamicMethod getDynamicMethod(String methodName, Map<String, DynamicMethod> methodMap) {
+    private static DynamicMethod getDynamicMethod(final String methodName, final Map<String, DynamicMethod> methodMap) {
         final DynamicMethod dynaMethod = methodMap.get(methodName);
         return dynaMethod != null ? dynaMethod : getExplicitSignatureDynamicMethod(methodName, methodMap);
     }
 
-    private static SingleDynamicMethod getExplicitSignatureDynamicMethod(String methodName,
-            Map<String, DynamicMethod> methodsMap) {
+    private static SingleDynamicMethod getExplicitSignatureDynamicMethod(final String methodName,
+            final Map<String, DynamicMethod> methodsMap) {
         // What's below is meant to support the "name(type, type, ...)" syntax that programmers can use in a method name
         // to manually pin down an exact overloaded variant. This is not usually required, as the overloaded method
         // resolution works correctly in almost every situation. However, in presence of many language-specific
@@ -457,8 +457,8 @@
     private static final MethodHandle CONSTANT_NULL_DROP_METHOD_HANDLE = MethodHandles.dropArguments(
             MethodHandles.constant(Object.class, null), 0, MethodHandle.class);
 
-    private GuardedInvocationComponent getPropertySetter(CallSiteDescriptor callSiteDescriptor,
-            LinkerServices linkerServices, List<String> operations) throws Exception {
+    private GuardedInvocationComponent getPropertySetter(final CallSiteDescriptor callSiteDescriptor,
+            final LinkerServices linkerServices, final List<String> operations) throws Exception {
         switch(callSiteDescriptor.getNameTokenCount()) {
             case 2: {
                 // Must have three arguments: target object, property name, and property value.
@@ -547,8 +547,8 @@
             "getTarget", MethodType.methodType(MethodHandle.class, MethodHandles.Lookup.class));
     private static final MethodHandle GETTER_INVOKER = MethodHandles.invoker(MethodType.methodType(Object.class, Object.class));
 
-    private GuardedInvocationComponent getPropertyGetter(CallSiteDescriptor callSiteDescriptor,
-            LinkerServices linkerServices, List<String> ops) throws Exception {
+    private GuardedInvocationComponent getPropertyGetter(final CallSiteDescriptor callSiteDescriptor,
+            final LinkerServices linkerServices, final List<String> ops) throws Exception {
         switch(callSiteDescriptor.getNameTokenCount()) {
             case 2: {
                 // Since we can't know what kind of a getter we'll get back on different invocations, we'll just
@@ -631,7 +631,7 @@
         }
     }
 
-    private MethodHandle getGuard(ValidationType validationType, MethodType methodType) {
+    private MethodHandle getGuard(final ValidationType validationType, final MethodType methodType) {
         switch(validationType) {
             case EXACT_CLASS: {
                 return getClassGuard(methodType);
@@ -655,8 +655,8 @@
             MethodType.methodType(boolean.class, Object.class));
     private static final MethodHandle OBJECT_IDENTITY = MethodHandles.identity(Object.class);
 
-    private GuardedInvocationComponent getMethodGetter(CallSiteDescriptor callSiteDescriptor,
-            LinkerServices linkerServices, List<String> ops) throws Exception {
+    private GuardedInvocationComponent getMethodGetter(final CallSiteDescriptor callSiteDescriptor,
+            final LinkerServices linkerServices, final List<String> ops) throws Exception {
         // The created method handle will always return a DynamicMethod (or null), but since we don't want that type to
         // be visible outside of this linker, declare it to return Object.
         final MethodType type = callSiteDescriptor.getMethodType().changeReturnType(Object.class);
@@ -730,7 +730,7 @@
         }
     }
 
-    static MethodPair matchReturnTypes(MethodHandle m1, MethodHandle m2) {
+    static MethodPair matchReturnTypes(final MethodHandle m1, final MethodHandle m2) {
         final MethodType type1 = m1.type();
         final MethodType type2 = m2.type();
         final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
@@ -740,7 +740,7 @@
                 m2.asType(type2.changeReturnType(commonRetType)));
     }
 
-    private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount) {
+    private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) {
         if(descriptor.getMethodType().parameterCount() != paramCount) {
             throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters.");
         }
@@ -755,7 +755,7 @@
      * @return the method handle for retrieving the property, or null if the property does not exist
      */
     @SuppressWarnings("unused")
-    private Object getPropertyGetterHandle(Object id) {
+    private Object getPropertyGetterHandle(final Object id) {
         return propertyGetters.get(id);
     }
 
@@ -769,8 +769,8 @@
     private final MethodHandle getPropertySetterHandle = GET_PROPERTY_SETTER_HANDLE.bindTo(this);
 
     @SuppressWarnings("unused")
-    private MethodHandle getPropertySetterHandle(CallSiteDescriptor setterDescriptor, LinkerServices linkerServices,
-            Object id) {
+    private MethodHandle getPropertySetterHandle(final CallSiteDescriptor setterDescriptor, final LinkerServices linkerServices,
+            final Object id) {
         return getDynamicMethodInvocation(setterDescriptor, linkerServices, String.valueOf(id), propertySetters);
     }
 
@@ -782,7 +782,7 @@
     // This method is marked to return Object instead of DynamicMethod as it's used as a linking component and we don't
     // want to make the DynamicMethod type observable externally (e.g. as the return type of a MethodHandle returned for
     // "dyn:getMethod" linking).
-    private Object getDynamicMethod(Object name) {
+    private Object getDynamicMethod(final Object name) {
         return getDynamicMethod(String.valueOf(name), methods);
     }
 
@@ -793,7 +793,7 @@
      * @return the dynamic method (either {@link SimpleDynamicMethod} or {@link OverloadedDynamicMethod}, or null if the
      * method with the specified name does not exist.
      */
-    DynamicMethod getDynamicMethod(String name) {
+    DynamicMethod getDynamicMethod(final String name) {
         return getDynamicMethod(name, methods);
     }
 
@@ -804,16 +804,16 @@
      * @param getter the getter
      * @return getter with same name, declared on the most generic superclass/interface of the declaring class
      */
-    private static Method getMostGenericGetter(Method getter) {
+    private static Method getMostGenericGetter(final Method getter) {
         return getMostGenericGetter(getter.getName(), getter.getReturnType(), getter.getDeclaringClass());
     }
 
-    private static Method getMostGenericGetter(String name, Class<?> returnType, Class<?> declaringClass) {
+    private static Method getMostGenericGetter(final String name, final Class<?> returnType, final Class<?> declaringClass) {
         if(declaringClass == null) {
             return null;
         }
         // Prefer interfaces
-        for(Class<?> itf: declaringClass.getInterfaces()) {
+        for(final Class<?> itf: declaringClass.getInterfaces()) {
             final Method itfGetter = getMostGenericGetter(name, returnType, itf);
             if(itfGetter != null) {
                 return itfGetter;
@@ -826,7 +826,7 @@
         if(!CheckRestrictedPackage.isRestrictedClass(declaringClass)) {
             try {
                 return declaringClass.getMethod(name);
-            } catch(NoSuchMethodException e) {
+            } catch(final NoSuchMethodException e) {
                 // Intentionally ignored, meant to fall through
             }
         }
@@ -837,18 +837,18 @@
         private final SingleDynamicMethod method;
         /*private*/ final ValidationType validationType;
 
-        AnnotatedDynamicMethod(SingleDynamicMethod method, ValidationType validationType) {
+        AnnotatedDynamicMethod(final SingleDynamicMethod method, final ValidationType validationType) {
             this.method = method;
             this.validationType = validationType;
         }
 
-        MethodHandle getInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) {
+        MethodHandle getInvocation(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) {
             return method.getInvocation(callSiteDescriptor, linkerServices);
         }
 
         @SuppressWarnings("unused")
-        MethodHandle getTarget(MethodHandles.Lookup lookup) {
-            MethodHandle inv = method.getTarget(lookup);
+        MethodHandle getTarget(final MethodHandles.Lookup lookup) {
+            final MethodHandle inv = method.getTarget(lookup);
             assert inv != null;
             return inv;
         }