Advertisement
Stiepen

Method lister

Jan 16th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.lang.reflect.*;
  2.  
  3. public abstract class classlister
  4. {    
  5.     private static String arrayDecrypt(String in) {
  6. //        String out = "";
  7. //        System.out.println("arraydecrypt: " + in);
  8.         if (!in.substring(0, 1).equals("[")) return in;
  9.         switch(in.charAt(1)) {
  10.         case 'B':
  11.             return "Byte[]";
  12.         case 'C':
  13.             return "Char[]";
  14.         case 'D':
  15.             return "Double[]";
  16.         case 'F':
  17.             return "Float[]";
  18.         case 'J':
  19.             return "Int[]";
  20.         case 'L':
  21.             return arrayDecrypt(in.substring(2, in.length() - 1)) + "[]";
  22. //          return "Byte[]";
  23.         case 'S':
  24.             return "Short[]";
  25.         case 'Z':
  26.             return "Boolean[]";
  27.         }
  28.         return null;
  29.     }
  30.  
  31.     public static void ListMethods()//String className)
  32.     {
  33.         try {
  34.             Class cls = java.lang.Class.class;//sum.kern.Stift.class;//Class.forName(className);
  35.             for (Method m : cls.getMethods()) {
  36.                 String text = m.getName() + "(";
  37.                 String args = "";
  38.                 String exceptions = "";
  39.                 for(Class c : m.getParameterTypes()) {
  40.                     if (!args.equals(""))
  41.                         args += ", ";
  42.                     args += arrayDecrypt(c.getName());
  43.                 }
  44.                
  45.                 for (Class c : m.getExceptionTypes()) {
  46.                     if (!exceptions.equals(""))
  47.                         exceptions += ", ";
  48.                     exceptions += c.getName();
  49.                 }
  50.                 System.out.println(Modifier.toString(m.getModifiers()) + " " + arrayDecrypt(m.getReturnType().getName()) + " " + text + args + ")");
  51.                 //System.out.println(m.toString());
  52.             }
  53.         } catch (Exception ex) {
  54.             ex.printStackTrace();
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement