List of usage examples for java.lang.reflect Method getModifiers
@Override public int getModifiers()
From source file:com.espertech.esper.util.MethodResolver.java
private static boolean isPublicAndStatic(Method method, boolean allowInstance) { int modifiers = method.getModifiers(); if (allowInstance) { return Modifier.isPublic(modifiers); } else {/*from ww w.j a va 2 s. c o m*/ return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers); } }
From source file:org.getobjects.foundation.kvc.KVCWrapper.java
@SuppressWarnings("unchecked") private static Method[] getPublicDeclaredMethods(Class _class) { Method methods[] = declaredMethodCache.get(_class); if (methods != null) return methods; final Class fclz = _class; methods = (Method[]) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return fclz.getMethods(); }/*from w w w .j av a 2 s .c o m*/ }); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; int j = method.getModifiers(); if (!Modifier.isPublic(j)) methods[i] = null; } declaredMethodCache.put(_class, methods); return methods; }
From source file:org.jdto.impl.BeanPropertyUtils.java
/** * Determine wether a method is accessor or not, by looking at some properties. * @param method/*from w w w. j ava2 s .co m*/ * @param maxParams * @param hasReturnType * @param prefixes * @return */ private static boolean isAccessorMethod(Method method, int maxParams, boolean hasReturnType, String... prefixes) { //first of all, we only want public methods. if (!Modifier.isPublic(method.getModifiers())) { return false; } //check if the method should return something or not. if (hasReturnType) { if (method.getReturnType() == Void.TYPE) { return false; } } //check the method parameter length int parameterAmount = method.getParameterTypes().length; if (parameterAmount > maxParams) { return false; } //check the naming conventions String methodName = method.getName(); if (!org.jdto.util.StringUtils.startsWithAny(methodName, prefixes)) { return false; } //well everything has succeeded, then is an accessor! return true; }
From source file:net.radai.beanz.util.ReflectionUtil.java
public static boolean isFinal(Method method) { return Modifier.isFinal(method.getModifiers()); }
From source file:net.radai.beanz.util.ReflectionUtil.java
public static boolean isStatic(Method method) { return Modifier.isStatic(method.getModifiers()); }
From source file:org.apache.xml.security.utils.CachedXPathFuncHereAPI.java
private static void fixupFunctionTable() { boolean installed = false; if (log.isDebugEnabled()) { log.debug("Registering Here function"); }//w w w .ja v a 2 s. c o m /** * Try to register our here() implementation as internal function. */ try { Class[] args = { String.class, Expression.class }; Method installFunction = FunctionTable.class.getMethod("installFunction", args); if ((installFunction.getModifiers() & Modifier.STATIC) != 0) { Object[] params = { "here", new FuncHere() }; installFunction.invoke(null, params); installed = true; } } catch (Throwable t) { log.debug("Error installing function using the static installFunction method", t); } if (!installed) { try { funcTable = new FunctionTable(); Class[] args = { String.class, Class.class }; Method installFunction = FunctionTable.class.getMethod("installFunction", args); Object[] params = { "here", FuncHere.class }; installFunction.invoke(funcTable, params); installed = true; } catch (Throwable t) { log.debug("Error installing function using the static installFunction method", t); } } if (log.isDebugEnabled()) { if (installed) { log.debug("Registered class " + FuncHere.class.getName() + " for XPath function 'here()' function in internal table"); } else { log.debug("Unable to register class " + FuncHere.class.getName() + " for XPath function 'here()' function in internal table"); } } }
From source file:Main.java
/** * find the setter method and set the value. *//* www. j a v a 2s . co m*/ public static void setProperties(Object bean, Map<String, Object> properties) { for (Method method : bean.getClass().getMethods()) { String name = method.getName(); if (name.length() > 3 && name.startsWith("set") && Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 1 && method.getDeclaringClass() != Object.class) { String key = name.substring(3, 4).toLowerCase() + name.substring(4); try { Object value = properties.get(key); if (value != null) { method.invoke(bean, new Object[] { convertCompatibleType(value, method.getParameterTypes()[0]) }); } } catch (Exception e) { } } } }
From source file:net.sf.ehcache.config.BeanHandler.java
/** * Finds a creator method.// w w w .j a v a 2 s . co m */ private static Method findCreateMethod(Class objClass, String name) { final String methodName = makeMethodName("create", name); final Method[] methods = objClass.getMethods(); for (int i = 0; i < methods.length; i++) { final Method method = methods[i]; if (!method.getName().equals(methodName)) { continue; } if (Modifier.isStatic(method.getModifiers())) { continue; } if (method.getParameterTypes().length != 0) { continue; } if (method.getReturnType().isPrimitive() || method.getReturnType().isArray()) { continue; } return method; } return null; }
From source file:com.diversityarrays.kdxplore.stats.StatsUtil.java
static public void initCheck() { if (checkDone) { return;//w w w . java2 s .co m } Set<String> okIfExhibitMissing = new HashSet<>(); Collections.addAll(okIfExhibitMissing, "getFormat", "getValueClass", "getStatsName", "getLowOutliers", "getHighOutliers"); List<String> errors = new ArrayList<String>(); Set<String> unMatchedStatNameValues = new HashSet<String>(); for (SimpleStatistics.StatName sname : StatName.values()) { unMatchedStatNameValues.add(sname.displayName); } for (Method m : SimpleStatistics.class.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; // shouldn't happen! } ExhibitColumn ec = m.getAnnotation(ExhibitColumn.class); if (ec == null) { if (okIfExhibitMissing.contains(m.getName())) { // if ("getQuartiles".equals(m.getName())) { // System.err.println("%TODO: @ExhibitColumn for 'SimpleStatistics.getQuartiles()'"); // } } else { errors.add("Missing @ExhibitColumn: " + m.getName()); } } else { String ecValue = ec.value(); boolean found = false; for (SimpleStatistics.StatName sname : StatName.values()) { if (sname.displayName.equals(ecValue)) { unMatchedStatNameValues.remove(sname.displayName); METHOD_BY_STATNAME.put(sname, m); found = true; break; } } if (!found) { errors.add("Doesn't match any StatName: '" + ecValue + "', method=" + m.getName()); } } } if (!unMatchedStatNameValues.isEmpty()) { errors.add(StringUtil.join("Unmatched StatName values: ", " ", unMatchedStatNameValues)); } if (!errors.isEmpty()) { throw new RuntimeException(StringUtil.join("Problems in SimpleStatistics config: ", "\n", errors)); } checkDone = true; }
From source file:au.com.dw.testdatacapturej.reflection.util.ReflectionUtil.java
/** * Check if a class has a default setter method for a field, using the specific class of the field only. * i.e. no superclasses or interfaces./* ww w .j ava 2 s. c o m*/ * * Since we may want to invoke the setter method, abstract methods are not included (i.e. will return * false). * * @param clazz * @param parameterClass * @param setterMethodName * @return */ private static boolean hasSetterMethodForParameterClass(Class<?> clazz, String setterMethodName, Class<?> parameterClass) { boolean hasSetterMethodForParameterClass = false; try { Method method = clazz.getDeclaredMethod(setterMethodName, parameterClass); if (method != null) { int mod = method.getModifiers(); // ignore abstract methods if (!Modifier.isAbstract(mod)) { hasSetterMethodForParameterClass = true; } } } catch (NoSuchMethodException nsme) { // no need to do anything, since this is what we are checking for } catch (Exception e) { e.printStackTrace(); } return hasSetterMethodForParameterClass; }