@Test public void run() throws Exception { final PrintStream ps = System.out; final ByteArrayOutputStream out = new ByteArrayOutputStream(); System.setOut(new PrintStream(out)); try { ListSetters.main(new String[]{"-c", Foo.class.getName()}); } finally { System.setOut(ps); } assertTrue(new String(out.toByteArray()).contains("Str")); assertTrue(new String(out.toByteArray()).contains("Integer")); }
public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(OptionBuilder .isRequired(true).hasArg(true) .withLongOpt("class").withDescription("the class to introspect").create("c")); final CommandLine line; try { line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return; } final String clazz = line.getOptionValue("class"); final Collection<Class<?>> ancestors = Classes.ancestors(Thread.currentThread().getContextClassLoader().loadClass(clazz)); final List<String> list = new LinkedList<>(); for (final Class<?> c : ancestors) { for (final Method m : c.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; } if (!m.getName().startsWith("set")) { continue; } if (m.getGenericParameterTypes().length != 1) { continue; } list.add(m.getName().substring(3)); } } Collections.sort(list); for (final String s : list) { System.out.println("- " + s); } }
ListSetters { public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(OptionBuilder .isRequired(true).hasArg(true) .withLongOpt("class").withDescription("the class to introspect").create("c")); final CommandLine line; try { line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return; } final String clazz = line.getOptionValue("class"); final Collection<Class<?>> ancestors = Classes.ancestors(Thread.currentThread().getContextClassLoader().loadClass(clazz)); final List<String> list = new LinkedList<>(); for (final Class<?> c : ancestors) { for (final Method m : c.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; } if (!m.getName().startsWith("set")) { continue; } if (m.getGenericParameterTypes().length != 1) { continue; } list.add(m.getName().substring(3)); } } Collections.sort(list); for (final String s : list) { System.out.println("- " + s); } } }
ListSetters { public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(OptionBuilder .isRequired(true).hasArg(true) .withLongOpt("class").withDescription("the class to introspect").create("c")); final CommandLine line; try { line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return; } final String clazz = line.getOptionValue("class"); final Collection<Class<?>> ancestors = Classes.ancestors(Thread.currentThread().getContextClassLoader().loadClass(clazz)); final List<String> list = new LinkedList<>(); for (final Class<?> c : ancestors) { for (final Method m : c.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; } if (!m.getName().startsWith("set")) { continue; } if (m.getGenericParameterTypes().length != 1) { continue; } list.add(m.getName().substring(3)); } } Collections.sort(list); for (final String s : list) { System.out.println("- " + s); } } private  ListSetters(); }
ListSetters { public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(OptionBuilder .isRequired(true).hasArg(true) .withLongOpt("class").withDescription("the class to introspect").create("c")); final CommandLine line; try { line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return; } final String clazz = line.getOptionValue("class"); final Collection<Class<?>> ancestors = Classes.ancestors(Thread.currentThread().getContextClassLoader().loadClass(clazz)); final List<String> list = new LinkedList<>(); for (final Class<?> c : ancestors) { for (final Method m : c.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; } if (!m.getName().startsWith("set")) { continue; } if (m.getGenericParameterTypes().length != 1) { continue; } list.add(m.getName().substring(3)); } } Collections.sort(list); for (final String s : list) { System.out.println("- " + s); } } private  ListSetters(); static void main(final String[] args); }
ListSetters { public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(OptionBuilder .isRequired(true).hasArg(true) .withLongOpt("class").withDescription("the class to introspect").create("c")); final CommandLine line; try { line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return; } final String clazz = line.getOptionValue("class"); final Collection<Class<?>> ancestors = Classes.ancestors(Thread.currentThread().getContextClassLoader().loadClass(clazz)); final List<String> list = new LinkedList<>(); for (final Class<?> c : ancestors) { for (final Method m : c.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; } if (!m.getName().startsWith("set")) { continue; } if (m.getGenericParameterTypes().length != 1) { continue; } list.add(m.getName().substring(3)); } } Collections.sort(list); for (final String s : list) { System.out.println("- " + s); } } private  ListSetters(); static void main(final String[] args);  }