List of usage examples for java.lang.reflect Method getModifiers
@Override public int getModifiers()
From source file:com.acuityph.commons.util.ClassUtils.java
/** * Checks if is property getter./*from w w w. j a v a 2s . c om*/ * * @param method * the method * @return true, if is property getter */ public static boolean isPropertyGetter(final Method method) { Assert.notNull(method, "method is null!"); final int mod = method.getModifiers(); final boolean expectsNoParameters = method.getParameterTypes().length == 0; final boolean returnsSomething = !void.class.equals(method.getReturnType()); return !isPrivate(mod) && !isStatic(mod) && expectsNoParameters && returnsSomething && isPropertyGetterName(method.getName()); }
From source file:org.blocks4j.reconf.client.elements.ConfigurationItemElement.java
private static boolean isConcrete(Method method) { return !Modifier.isAbstract(method.getModifiers()); }
From source file:de.micromata.genome.tpsb.GroovyExceptionInterceptor.java
protected static void collectMethods(Class<?> cls, Map<String, Method> collected) { for (Method m : cls.getDeclaredMethods()) { if ((m.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC) { continue; }/*from w ww . j a v a 2s. c o m*/ if ((m.getModifiers() & Modifier.STATIC) == Modifier.STATIC) { continue; } if (m.getAnnotation(TpsbIgnore.class) != null) { continue; } if (ignoreMethods.contains(m.getName()) == true) { continue; } if (m.getReturnType().isPrimitive() == true) { continue; } String sm = methodToString(m); if (collected.containsKey(sm) == true) { continue; } collected.put(sm, m); } Class<?> scls = cls.getSuperclass(); if (scls == Object.class) { return; } collectMethods(scls, collected); }
From source file:jenkins.scm.api.MethodUtils.java
/** * Checks if the method is abstract or not. * @param clazz the class.//from ww w . j a v a 2 s. co m * @param methodName the method name. * @param parameterTypes the parameter types. * @return {@code true} if the method does not exist or is abstract. */ static boolean isAbstract(Class<?> clazz, String methodName, Class<?>... parameterTypes) { Method m = getMethodImpl(clazz, methodName, parameterTypes); return m == null || Modifier.isAbstract(m.getModifiers()); }
From source file:com.qmetry.qaf.automation.step.JavaStepFinder.java
public static Map<String, TestStep> getAllJavaSteps() { Map<String, TestStep> stepMapping = new HashMap<String, TestStep>(); Set<Method> steps = new LinkedHashSet<Method>(); List<String> pkgs = new ArrayList<String>(); pkgs.add(STEPS_PACKAGE);//from ww w. java 2 s. c om if (getBundle().containsKey(STEP_PROVIDER_PKG.key)) { pkgs.addAll(Arrays.asList(getBundle().getStringArray(STEP_PROVIDER_PKG.key))); } for (String pkg : pkgs) { logger.info("pkg: " + pkg); try { List<Class<?>> classes = CLASS_FINDER.getClasses(pkg); steps.addAll(getAllMethodsWithAnnotation(classes, QAFTestStep.class)); } catch (Exception e) { System.err.println("Unable to load steps for package: " + pkg); } } for (Method step : steps) { if (!Modifier.isPrivate(step.getModifiers())) { // exclude private methods. // Case: step provided using QAFTestStepProvider at class level add(stepMapping, new JavaStep(step)); } } return stepMapping; }
From source file:ome.util.ReflectionUtils.java
static List checkGettersAndSetters(Method[] methods) { List goodMethods = new ArrayList(); if (null == methods) { return goodMethods; }//from ww w . j ava 2 s . c o m for (int i = 0; i < methods.length; i++) { boolean ok = true; Method method = methods[i]; int mod = method.getModifiers(); if (!Modifier.isPublic(mod) || Modifier.isStatic(mod)) { ok = false; } if (method.getName().startsWith("get")) { if (0 != method.getParameterTypes().length) { ok = false; } } else if (method.getName().startsWith("set")) { // No constaints yet on setters. } else { ok = false; } if (ok) { goodMethods.add(method); } } return goodMethods; }
From source file:org.grails.datastore.mapping.reflect.ReflectionUtils.java
/** * Make the given method accessible, explicitly setting it accessible if necessary. * The <code>setAccessible(true)</code> method is only called when actually necessary, * to avoid unnecessary conflicts with a JVM SecurityManager (if active). * * Based on the same method in Spring core. * * @param method the method to make accessible * @see java.lang.reflect.Method#setAccessible *///w w w .j av a 2s. co m public static void makeAccessible(Method method) { if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) { method.setAccessible(true); } }
From source file:org.echocat.velma.support.MainClassDiscovery.java
@Nullable protected static Method getPublicStaticMethodOf(@Nonnull Class<?> ofType, @Nonnull Class<?> returnType, @Nonnull String methodName, @Nullable Class<?>... parameterTypes) { try {/* w w w . j av a 2s .co m*/ final Method method = ofType.getMethod(methodName, parameterTypes); final int modifiers = method.getModifiers(); if (!isStatic(modifiers)) { throw new IllegalArgumentException(method + " is not static."); } if (!isPublic(modifiers)) { throw new IllegalArgumentException(method + " is not public."); } if (!returnType.equals(method.getReturnType())) { throw new IllegalArgumentException(method + " does not return " + returnType.getName() + "."); } return method; } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Could not find public static " + returnType.getSimpleName() + " " + ofType.getSimpleName() + "." + methodName + "(" + Arrays.toString(parameterTypes) + ").", e); } }
From source file:mangotiger.poker.channel.EventChannelImpl.java
static boolean methodMatchesEvent(final Method method, final Class<?> event) { return METHOD_NAME.equals(method.getName()) && Modifier.isPublic(method.getModifiers()) && Void.TYPE.equals(method.getReturnType()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].isAssignableFrom(event); }
From source file:api.Status.java
public static Result getStatus() { ObjectNode metrics = Json.newObject(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); TreeMap<String, Object> values = new TreeMap<String, Object>(); for (Method method : os.getClass().getDeclaredMethods()) { method.setAccessible(true);// w ww .j a va 2s . c o m if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) { Object value; try { value = method.invoke(os); values.put(method.getName(), value); } catch (Exception e) { Logger.warn("Error when invoking " + os.getClass().getName() + " (OperatingSystemMXBean) method " + method.getName() + ": " + e); } // try } // if } // for metrics.put("jvmLoad", (Double) values.get("getProcessCpuLoad")); metrics.put("cpuLoad", (Double) values.get("getSystemCpuLoad")); metrics.put("openFD", (Long) values.get("getOpenFileDescriptorCount")); metrics.put("maxFD", (Long) values.get("getMaxFileDescriptorCount")); metrics.put("freeMemory", (Long) values.get("getFreePhysicalMemorySize")); metrics.put("totalMemory", (Long) values.get("getTotalPhysicalMemorySize")); return ok(metrics.toString()); }