private String createUsage(Method method) {
    MCCommand cmd = method.getAnnotation(MCCommand.class);
    List<String> str = new ArrayList<String>();
    String thecmd = cmd.cmds().length > 0 ? cmd.cmds()[0] : "";
    String thesubcmd = cmd.subCmds().length > 0 ? cmd.subCmds()[0] : null;

    Class<?> types[] = method.getParameterTypes();
    if (commandIndex == 0) {
      str.add(thecmd);
      if (thesubcmd != null) {
        str.add(thesubcmd);
      }
    }
    for (int i = 1; i < types.length; i++) {
      Class<?> theclass = types[i];
      str.add(getUsageString(theclass));
      if (i == commandIndex) {
        str.add(thecmd);
        if (thesubcmd != null) {
          str.add(thesubcmd);
        }
      }
    }
    return StringUtils.join(str, " ");
  }
예제 #2
0
 private String createUsage(Method method) {
   MCCommand cmd = method.getAnnotation(MCCommand.class);
   StringBuilder sb = new StringBuilder(cmd.cmds().length > 0 ? cmd.cmds()[0] + " " : "");
   int startIndex = 1;
   if (cmd.subCmds().length > 0) {
     sb.append(cmd.subCmds()[0] + " ");
     startIndex = 2;
   }
   Class<?> types[] = method.getParameterTypes();
   for (int i = startIndex; i < types.length; i++) {
     Class<?> theclass = types[i];
     sb.append(getUsageString(theclass));
   }
   return sb.toString();
 }
예제 #3
0
 private void addMethod(Object obj, Method method, MCCommand mc, String cmd) {
   int ml = method.getParameterTypes().length;
   if (mc.subCmds().length == 0) {
     TreeMap<Integer, MethodWrapper> mthds = methods.get(cmd);
     if (mthds == null) {
       mthds = new TreeMap<Integer, MethodWrapper>();
     }
     int order =
         (mc.order() != -1 ? mc.order() * 100000 : Integer.MAX_VALUE) - ml * 100 - mthds.size();
     MethodWrapper mw = new MethodWrapper(obj, method);
     mthds.put(order, mw);
     methods.put(cmd, mthds);
     addUsage(mw, mc);
   } else {
     Map<String, TreeMap<Integer, MethodWrapper>> basemthds = subCmdMethods.get(cmd);
     if (basemthds == null) {
       basemthds = new HashMap<String, TreeMap<Integer, MethodWrapper>>();
       subCmdMethods.put(cmd, basemthds);
     }
     for (String subcmd : mc.subCmds()) {
       TreeMap<Integer, MethodWrapper> mthds = basemthds.get(subcmd);
       if (mthds == null) {
         mthds = new TreeMap<Integer, MethodWrapper>();
         basemthds.put(subcmd, mthds);
       }
       int order =
           (mc.order() != -1 ? mc.order() * 100000 : Integer.MAX_VALUE) - ml * 100 - mthds.size();
       MethodWrapper mw = new MethodWrapper(obj, method);
       /// Set help order
       if (mc.helpOrder() == Integer.MAX_VALUE) {
         mw.helpOrder = (float) (Integer.MAX_VALUE - usage.size());
       }
       mthds.put(order, mw);
       addUsage(mw, mc);
     }
   }
 }