| 17 | "To search for methods involving 'word'"; |
| 18 | private static Pattern p = Pattern.compile("\\w+\\."); |
| 19 | public static void main(String[] args) { |
| 20 | if(args.length < 1) { |
| 21 | System.out.println(usage); |
| 22 | System.exit(0); |
| 23 | } |
| 24 | int lines = 0; |
| 25 | try { |
| 26 | Class<?> c = Class.forName(args[0]); |
| 27 | Method[] methods = c.getMethods(); |
| 28 | Constructor[] ctors = c.getConstructors(); |
| 29 | if(args.length == 1) { |
| 30 | for(Method method : methods) |
| 31 | System.out.println( |
| 32 | p.matcher( |
| 33 | method.toString()).replaceAll("")); |
| 34 | for(Constructor ctor : ctors) |
| 35 | System.out.println( |
| 36 | p.matcher(ctor.toString()).replaceAll("")); |
| 37 | lines = methods.length + ctors.length; |
| 38 | } else { |
| 39 | for(Method method : methods) |
| 40 | if(method.toString().contains(args[1])) { |
| 41 | System.out.println(p.matcher( |
| 42 | method.toString()).replaceAll("")); |
| 43 | lines++; |
| 44 | } |
| 45 | for(Constructor ctor : ctors) |
| 46 | if(ctor.toString().contains(args[1])) { |
| 47 | System.out.println(p.matcher( |
| 48 | ctor.toString()).replaceAll("")); |
| 49 | lines++; |
| 50 | } |
| 51 | } |
| 52 | } catch(ClassNotFoundException e) { |
| 53 | System.out.println("No such class: " + e); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | /* Output: |
| 58 | public static void main(String[]) |