/** * Returns a {@link List} of {@link MethodSub}s for each * method declared method in the inspected class. However, * in safe mode (which *is* the default), this will only return * the public methods. You must configure safe mode to be off * to receive a list of all methods. * @return methods inspectors list */ public List<MethodSub> getMethods() { if (methods == null) { Method[] declared = getType().getDeclaredMethods(); List<MethodSub> subs = new ArrayList<MethodSub>(declared.length); for (Method method : declared) { MethodSub sub = new MethodSub(method); if ((!isSafeMode() || sub.isPublic()) && (showDeprecated || !sub.isDeprecated())) { subs.add(sub); } } Collections.sort(subs); methods = Collections.unmodifiableList(subs); } return methods; }
/** * Returns a {@link List} of {@link FieldSub}s for each * field declared field in the inspected class. However, * in safe mode (which *is* the default), this will only return * the public fields. You must configure safe mode to be off * to receive a list of all fields. * @return fields inspectors list */ public List<FieldSub> getFields() { if (fields == null) { Field[] declared = getType().getDeclaredFields(); List<FieldSub> subs = new ArrayList<FieldSub>(declared.length); for (Field field : declared) { FieldSub sub = new FieldSub(field); if ((!isSafeMode() || sub.isPublic()) && (showDeprecated || !sub.isDeprecated())) { subs.add(sub); } } Collections.sort(subs); fields = Collections.unmodifiableList(subs); } return fields; }
/** * Returns a new ClassTool instance that is inspecting the * the specified {@link Class}. If the specified class * is null, then this will return {@code null}. All other * configuration settings will be copied to the new instance. * If {@link #isSafeMode()} is {@code true} and the specified Class * is not declared {@code public}, then this will return * {@code null}. * @param type class to inspect * @return new class tool */ public ClassTool inspect(Class type) { if (type == null) { return null; } // create the new tool, but only return it if // it is public or isSafeMode() is off ClassTool tool = new ClassTool(this, type); if (isSafeMode() && !tool.isPublic()) { return null; } return tool; }
/** * Returns a {@link List} of {@link ConstructorSub}s for each * constructor declared constructor in the inspected class. However, * in safe mode (which *is* the default), this will only return * the public constructors. You must configure safe mode to be off * to receive a list of all constructors. * @return constructors inspectors list */ public List<ConstructorSub> getConstructors() { if (constructors == null) { Constructor[] declared = getType().getDeclaredConstructors(); List<ConstructorSub> subs = new ArrayList<ConstructorSub>(declared.length); for (Constructor constructor : declared) { ConstructorSub sub = new ConstructorSub(constructor); if ((!isSafeMode() || sub.isPublic()) && (showDeprecated || !sub.isDeprecated())) { subs.add(sub); } } Collections.sort(subs); constructors = Collections.unmodifiableList(subs); } return constructors; }
/** * Creates a new instance that inspects the specified type * and otherwise shares the configuration values of the specified "parent" * ClassTool instance. * @param tool parent class tool * @param type class to inspect */ protected ClassTool(ClassTool tool, Class type) { setType(type); if (tool == null) { throw new IllegalArgumentException("parent tool must not be null"); } // manually duplicate configuration of the parent tool this.showDeprecated = tool.showDeprecated; setSafeMode(tool.isSafeMode()); setLockConfig(tool.isConfigLocked()); }
for (MethodSub method : getMethods()) if (!isSafeMode() || method.isPublic()) if (!isSafeMode() || constructor.isPublic()) if (!isSafeMode() || field.isPublic())