List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:Main.java
public static void main(String[] args) throws Exception { Class<?> clazz = String.class; int modifier = clazz.getModifiers(); if (Modifier.isStatic(modifier)) { System.out.println("isStatic"); }/*from w w w . j a v a 2 s. c om*/ }
From source file:org.apache.flink.configuration.ConfigDocsCompletenessChecker.java
public static void main(String[] args) throws Exception { String configFileContents = FileUtils.readFileToString(new File("docs/setup/config.md")); Field[] fields = ConfigConstants.class.getFields(); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(String.class) && !field.getName().startsWith("DEFAULT")) { Object val = field.get(null); if (!configFileContents.contains((String) val)) { System.out.println("++++ " + val + " is not mentioned in the configuration file!!!"); }//from w w w. ja v a2 s .c o m } } }
From source file:Main.java
public static boolean fieldIsInvalid(Field field) { return (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) || field.isSynthetic();/*from w w w.j av a 2 s .c o m*/ }
From source file:Main.java
public static boolean hasGetterSignature(Method m) { // First: static methods can't be getters if (Modifier.isStatic(m.getModifiers())) { return false; }//from w w w . j ava2s. c o m // Must take no args Class<?>[] pts = m.getParameterTypes(); if (pts != null && pts.length != 0) { return false; } // Can't be a void method if (Void.TYPE == m.getReturnType()) { return false; } // Otherwise looks ok: return true; }
From source file:Main.java
private static void getClassModifier(Class clazz) { int modifier = clazz.getModifiers(); if (Modifier.isStatic(modifier)) { System.out.println(clazz.getName() + " class modifier is static"); }// w w w. j av a 2 s . c o m }
From source file:Main.java
private static Field getSingletonField(Class<?> hostClas) { Field f = null;//from w ww . j av a 2 s.co m try { f = hostClas.getDeclaredField("I"); if (!Modifier.isStatic(f.getModifiers())) throw new Exception("'I' field should be static." + f); f.setAccessible(true); } catch (Throwable ex) { } return f; }
From source file:Main.java
private static Method findGetter(Method[] methods, String name, Class<?> paramType) { String getterName = "get" + name; String isGetterName = "is" + name; for (Method method : methods) { if (Modifier.isStatic(method.getModifiers())) { continue; }/*from w w w . ja v a2 s . c o m*/ String methodName = method.getName(); if (!methodName.equals(getterName) && !methodName.equals(isGetterName)) { continue; } if (!method.getReturnType().equals(paramType)) { continue; } if (method.getParameterTypes().length == 0) { return method; } } return null; }
From source file:Main.java
/** * Method for finding enclosing class for non-static inner classes */// w w w . j a va 2s .c o m public static Class<?> getOuterClass(Class<?> type) { // as above, GAE has some issues... try { // one more: method locals, anonymous, are not good: if (type.getEnclosingMethod() != null) { return null; } if (!Modifier.isStatic(type.getModifiers())) { return type.getEnclosingClass(); } } catch (SecurityException e) { } catch (NullPointerException e) { } return null; }
From source file:Main.java
public static Method[] getSelfMethod(Object o) { Class c = o.getClass();//from ww w. j a v a 2 s . c o m Method[] ms = o.getClass().getMethods(); List list = new ArrayList(); for (Method m : ms) { int mod = m.getModifiers(); if (m.getDeclaringClass().equals(c) && Modifier.isPublic(mod) && !Modifier.isStatic(mod)) { list.add(m); } } return (Method[]) list.toArray(new Method[0]); }
From source file:Main.java
public static Map<String, Object> optPublicFieldKeyValueMap(Object obj) { Map<String, Object> map = new HashMap<String, Object>(); if (obj != null) { Field[] fields = obj.getClass().getFields(); for (Field f : fields) { try { boolean isStatic = Modifier.isStatic(f.getModifiers()); if (!isStatic) { Object value = f.get(obj); if (value != null) map.put(f.getName(), value); }// w ww . ja va 2s . co m } catch (Exception e) { } } } return map; }