List of usage examples for java.lang.reflect Modifier toString
public static String toString(int mod)
From source file:MyClass.java
public static String getModifiers(Executable exec) { int mod = exec.getModifiers(); if (exec instanceof Method) { mod = mod & Modifier.methodModifiers(); } else if (exec instanceof Constructor) { mod = mod & Modifier.constructorModifiers(); }/*from w ww . j a v a2 s .com*/ return Modifier.toString(mod); }
From source file:com.link_intersystems.lang.reflect.SerializableField.java
@SuppressWarnings("unchecked") @Override//from ww w . j a v a2 s. c om protected Field deserialize(Serializable restoreInfo) throws NoSuchFieldException { MemberSerialization<Field> memberSerializationInfo = (MemberSerialization<Field>) restoreInfo; Class<?> declaringClass = memberSerializationInfo.getDeclaringClass(); String fieldName = memberSerializationInfo.getMemberName(); int modifiers = memberSerializationInfo.getModifiers(); Field field = declaringClass.getDeclaredField(fieldName); int currentModifiers = getModifier(field); if (modifiers != currentModifiers) { throw new SerializationException("Unable to restore field " + fieldName + " declared at " + declaringClass + ". Modifiers changed since serialization. Expected modifiers are " + Modifier.toString(modifiers) + ", but current modifiers are " + Modifier.toString(currentModifiers)); } return field; }
From source file:ReflectionTest.java
/** * Prints all methods of a class/*w w w .j av a 2 s .c o m*/ * @param cl a class */ public static void printMethods(Class cl) { Method[] methods = cl.getDeclaredMethods(); for (Method m : methods) { Class retType = m.getReturnType(); String name = m.getName(); System.out.print(" "); // print modifiers, return type and method name String modifiers = Modifier.toString(m.getModifiers()); if (modifiers.length() > 0) System.out.print(modifiers + " "); System.out.print(retType.getName() + " " + name + "("); // print parameter types Class[] paramTypes = m.getParameterTypes(); for (int j = 0; j < paramTypes.length; j++) { if (j > 0) System.out.print(", "); System.out.print(paramTypes[j].getName()); } System.out.println(");"); } }
From source file:hu.bme.mit.sette.common.validator.reflection.ConstructorValidator.java
/** * Sets the required modifiers for the constructor. * * @param modifiers/*from www . j av a2 s . c o m*/ * the required modifiers for the constructor * @return this object */ public ConstructorValidator withModifiers(final int modifiers) { if (getSubject() != null) { Constructor<?> constructor = getSubject(); if ((constructor.getModifiers() & modifiers) != modifiers) { this.addException(String.format( "The constructor must have all the " + "specified modifiers\n(modifiers: [%s])", Modifier.toString(modifiers))); } } return this; }
From source file:ShowClass.java
/** Return a string version of modifiers, handling spaces nicely. */ public static String modifiers(int m) { if (m == 0)/*from w ww. java2 s . c o m*/ return ""; else return Modifier.toString(m) + " "; }
From source file:MyJavaP.java
/** * Format the fields and methods of one class, given its name. *//*w w w .j av a 2 s . c o m*/ protected void doClass(String className) { try { Class c = Class.forName(className); System.out.println(Modifier.toString(c.getModifiers()) + ' ' + c + " {"); int mods; Field fields[] = c.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (!Modifier.isPrivate(fields[i].getModifiers()) && !Modifier.isProtected(fields[i].getModifiers())) System.out.println("\t" + fields[i]); } Constructor[] constructors = c.getConstructors(); for (int j = 0; j < constructors.length; j++) { Constructor constructor = constructors[j]; System.out.println("\t" + constructor); } Method methods[] = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (!Modifier.isPrivate(methods[i].getModifiers()) && !Modifier.isProtected(methods[i].getModifiers())) System.out.println("\t" + methods[i]); } System.out.println("}"); } catch (ClassNotFoundException e) { System.err.println("Error: Class " + className + " not found!"); } catch (Exception e) { System.err.println(e); } }
From source file:kilim.tools.DumpClass.java
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {// www . j a v a 2s.com p(".class "); p(Modifier.toString(access)); p(" "); pn(name); if (superName != null) pn(".super " + superName); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { p(".implements "); pn(interfaces[i]); } } }
From source file:hu.bme.mit.sette.common.validator.reflection.ConstructorValidator.java
/** * Sets the prohibited modifiers for the constructor. * * @param modifiers/* w w w.j a v a 2 s . c o m*/ * the prohibited modifiers for the constructor. * @return this object */ public ConstructorValidator withoutModifiers(final int modifiers) { if (getSubject() != null) { Constructor<?> constructor = getSubject(); if ((constructor.getModifiers() & modifiers) != 0) { this.addException(String.format( "The constructor must not have any of " + "the specified modifiers\n(modifiers: [%s])", Modifier.toString(modifiers))); } } return this; }
From source file:ReflectionTest.java
/** * Prints all fields of a class// www. j a v a 2 s . co m * @param cl a class */ public static void printFields(Class cl) { Field[] fields = cl.getDeclaredFields(); for (Field f : fields) { Class type = f.getType(); String name = f.getName(); System.out.print(" "); String modifiers = Modifier.toString(f.getModifiers()); if (modifiers.length() > 0) System.out.print(modifiers + " "); System.out.println(type.getName() + " " + name + ";"); } }
From source file:kilim.tools.DumpClass.java
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { p(".field "); p(Modifier.toString(access)); p(" ");/*from w w w. j ava 2 s.c om*/ p(name); p(" "); p(desc); if (value != null) { p(" = "); if (value instanceof String) { pn("\"" + value + "\""); } else { pn(value.toString()); } } else { pn(); } return null; }