List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:com.mayabot.thriftpool.utils.ReflectUtils.java
/** * ???// w w w . j a v a 2 s.c o m * * @param clazz * @param methodName ??method1(int, String)?????????method2 * @return * @throws NoSuchMethodException * @throws ClassNotFoundException * @throws IllegalStateException ??????? */ // public static Method findMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes) // throws NoSuchMethodException, ClassNotFoundException { // String signature = clazz.getName() + "." + methodName; // if(parameterTypes != null && parameterTypes.length > 0){ // signature += StringUtils.join(parameterTypes); // } // Method method = Signature_METHODS_CACHE.get(signature); // if(method != null){ // return method; // } // if (parameterTypes == null) { // List<Method> finded = new ArrayList<Method>(); // for (Method m : clazz.getMethods()) { // if (m.getName().equals(methodName)) { // finded.add(m); // } // } // if (finded.isEmpty()) { // throw new NoSuchMethodException("No such method " + methodName + " in class " + clazz); // } // if(finded.size() > 1) { // String msg = String.format("Not unique method for method name(%s) in class(%s), find %d methods.", // methodName, clazz.getName(), finded.size()); // throw new IllegalStateException(msg); // } // method = finded.get(0); // } else { // Class<?>[] types = new Class<?>[parameterTypes.length]; // for (int i = 0; i < parameterTypes.length; i ++) { // types[i] = ReflectUtils.name2class(parameterTypes[i]); // } // method = clazz.getMethod(methodName, types); // // } // Signature_METHODS_CACHE.put(signature, method); // return method; // } // public static Method findMethodByMethodName(Class<?> clazz, String methodName) // throws NoSuchMethodException, ClassNotFoundException { // return findMethodByMethodSignature(clazz, methodName, null); // } public static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) throws NoSuchMethodException { Constructor<?> targetConstructor; try { targetConstructor = clazz.getConstructor(new Class<?>[] { paramType }); } catch (NoSuchMethodException e) { targetConstructor = null; Constructor<?>[] constructors = clazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (Modifier.isPublic(constructor.getModifiers()) && constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0].isAssignableFrom(paramType)) { targetConstructor = constructor; break; } } if (targetConstructor == null) { throw e; } } return targetConstructor; }
From source file:com.glaf.core.util.ReflectUtils.java
public static boolean isBeanPropertyReadMethod(Method method) { return method != null && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && method.getReturnType() != void.class && method.getDeclaringClass() != Object.class && method.getParameterTypes().length == 0 && ((method.getName().startsWith("get") && method.getName().length() > 3) || (method.getName().startsWith("is") && method.getName().length() > 2)); }
From source file:org.glowroot.agent.weaving.ClassAnalyzer.java
private static boolean hasMainOrPossibleProcrunStartMethod(List<ThinMethod> methods) { for (ThinMethod method : methods) { // checking for start* methods since those seem to be common for procrun users if (Modifier.isPublic(method.access()) && Modifier.isStatic(method.access()) && (method.name().equals("main") || method.name().startsWith("start")) && method.descriptor().equals("([Ljava/lang/String;)V")) { return true; }/*from w ww.j ava2 s . com*/ } return false; }
From source file:org.apache.poi.util.MethodUtils.java
/** * <p>Return an accessible method (that is, one that can be invoked via * reflection) that implements the specified method, by scanning through * all implemented interfaces and subinterfaces. If no such method * can be found, return <code>null</code>.</p> * * <p> There isn't any good reason why this method must be private. * It is because there doesn't seem any reason why other classes should * call this rather than the higher level methods.</p> * * @param clazz Parent class for the interfaces to be checked * @param methodName Method name of the method we wish to call * @param parameterTypes The parameter type signatures *//*from w w w . ja va 2 s . c o m*/ private static Method getAccessibleMethodFromInterfaceNest(Class clazz, String methodName, Class[] parameterTypes) { Method method = null; // Search up the superclass chain for (; clazz != null; clazz = clazz.getSuperclass()) { // Check the implemented interfaces of the parent class Class[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { // Is this interface public? if (!Modifier.isPublic(interfaces[i].getModifiers())) { continue; } // Does the method exist on this interface? try { method = interfaces[i].getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { /* Swallow, if no method is found after the loop then this * method returns null. */ } if (method != null) { return method; } // Recursively check our parent interfaces method = getAccessibleMethodFromInterfaceNest(interfaces[i], methodName, parameterTypes); if (method != null) { return method; } } } // If we found a method return it if (method != null) { return (method); } // We did not find anything return (null); }
From source file:com.glaf.core.util.ReflectUtils.java
public static boolean isBeanPropertyWriteMethod(Method method) { return method != null && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass() != Object.class && method.getParameterTypes().length == 1 && method.getName().startsWith("set") && method.getName().length() > 3; }
From source file:javadz.beanutils.MethodUtils.java
/** * <p>Return an accessible method (that is, one that can be invoked via * reflection) by scanning through the superclasses. If no such method * can be found, return <code>null</code>.</p> * * @param clazz Class to be checked/*from w w w .j a va 2 s .co m*/ * @param methodName Method name of the method we wish to call * @param parameterTypes The parameter type signatures */ private static Method getAccessibleMethodFromSuperclass(Class clazz, String methodName, Class[] parameterTypes) { Class parentClazz = clazz.getSuperclass(); while (parentClazz != null) { if (Modifier.isPublic(parentClazz.getModifiers())) { try { return parentClazz.getMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { return null; } } parentClazz = parentClazz.getSuperclass(); } return null; }
From source file:org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.java
private boolean isPublic(Method method) { return Modifier.isPublic(method.getModifiers()); }
From source file:org.apache.hadoop.yarn.api.TestPBImplRecords.java
/** * this method generate record instance by calling newIntance * using reflection, add register the generated value to typeValueCache */// w w w. j av a 2 s .co m @SuppressWarnings("rawtypes") private static Object generateByNewInstance(Class clazz) throws Exception { Object ret = typeValueCache.get(clazz); if (ret != null) { return ret; } Method newInstance = null; Type[] paramTypes = new Type[0]; // get newInstance method with most parameters for (Method m : clazz.getMethods()) { int mod = m.getModifiers(); if (m.getDeclaringClass().equals(clazz) && Modifier.isPublic(mod) && Modifier.isStatic(mod) && m.getName().equals("newInstance")) { Type[] pts = m.getGenericParameterTypes(); if (newInstance == null || (pts.length > paramTypes.length)) { newInstance = m; paramTypes = pts; } } } if (newInstance == null) { throw new IllegalArgumentException("type " + clazz.getName() + " does not have newInstance method"); } Object[] args = new Object[paramTypes.length]; for (int i = 0; i < args.length; i++) { args[i] = genTypeValue(paramTypes[i]); } ret = newInstance.invoke(null, args); typeValueCache.put(clazz, ret); return ret; }
From source file:h2o.common.spring.util.ClassUtils.java
/** * Determine whether the given method is overridable in the given target class. * @param method the method to check//from w w w. j a va2 s. co m * @param targetClass the target class to check against */ @SuppressWarnings("rawtypes") private static boolean isOverridable(Method method, Class targetClass) { if (Modifier.isPrivate(method.getModifiers())) { return false; } if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) { return true; } return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass)); }
From source file:com.laidians.utils.ClassUtils.java
/** * Determine whether the given method is overridable in the given target class. * @param method the method to check/*ww w.j av a 2 s .c o m*/ * @param targetClass the target class to check against */ private static boolean isOverridable(Method method, Class targetClass) { if (Modifier.isPrivate(method.getModifiers())) { return false; } if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) { return true; } return getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass)); }