jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java

Print this page
rev 5725 : Merge


  49 
  50     /**
  51      * Finds public method (static or non-static)
  52      * that is accessible from public class.
  53      *
  54      * @param type  the class that can have method
  55      * @param name  the name of method to find
  56      * @param args  parameter types that is used to find method
  57      * @return object that represents found method
  58      * @throws NoSuchMethodException if method could not be found
  59      *                               or some methods are found
  60      */
  61     public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
  62         if (name == null) {
  63             throw new IllegalArgumentException("Method name is not set");
  64         }
  65         PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
  66         Signature signature = new Signature(type, name, args);
  67 
  68         Method method = CACHE.get(signature);
  69         if (method != null) {

  70             return method;
  71         }
  72         method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods()));

  73         CACHE.put(signature, method);

  74         return method;
  75     }
  76 
  77     /**
  78      * Finds public non-static method
  79      * that is accessible from public class.
  80      *
  81      * @param type  the class that can have method
  82      * @param name  the name of method to find
  83      * @param args  parameter types that is used to find method
  84      * @return object that represents found method
  85      * @throws NoSuchMethodException if method could not be found
  86      *                               or some methods are found
  87      */
  88     public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException {
  89         Method method = findMethod(type, name, args);
  90         if (Modifier.isStatic(method.getModifiers())) {
  91             throw new NoSuchMethodException("Method '" + name + "' is static");
  92         }
  93         return method;




  49 
  50     /**
  51      * Finds public method (static or non-static)
  52      * that is accessible from public class.
  53      *
  54      * @param type  the class that can have method
  55      * @param name  the name of method to find
  56      * @param args  parameter types that is used to find method
  57      * @return object that represents found method
  58      * @throws NoSuchMethodException if method could not be found
  59      *                               or some methods are found
  60      */
  61     public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
  62         if (name == null) {
  63             throw new IllegalArgumentException("Method name is not set");
  64         }
  65         PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
  66         Signature signature = new Signature(type, name, args);
  67 
  68         Method method = CACHE.get(signature);
  69         boolean cached = method != null;
  70         if (cached && isPackageAccessible(method.getDeclaringClass())) {
  71             return method;
  72         }
  73         method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods()));
  74         if (!cached) {
  75             CACHE.put(signature, method);
  76         }
  77         return method;
  78     }
  79 
  80     /**
  81      * Finds public non-static method
  82      * that is accessible from public class.
  83      *
  84      * @param type  the class that can have method
  85      * @param name  the name of method to find
  86      * @param args  parameter types that is used to find method
  87      * @return object that represents found method
  88      * @throws NoSuchMethodException if method could not be found
  89      *                               or some methods are found
  90      */
  91     public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException {
  92         Method method = findMethod(type, name, args);
  93         if (Modifier.isStatic(method.getModifiers())) {
  94             throw new NoSuchMethodException("Method '" + name + "' is static");
  95         }
  96         return method;