@Test public void getSignatureTest01() { try { Class<?> clazz = Class.forName("com.credits.scapi.v0.SmartContract"); Map<Method, String> methods = JavaReflect.getDeclaredMethods(clazz); methods.forEach((k, v) -> { LOGGER.info(v); }); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
public static Map<Method, String> getDeclaredMethods(Class clazz) { Map<Method, String> res = new HashMap<>(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { StringBuilder methodString = new StringBuilder(); methodString.append(method.getReturnType().equals(Void.class) ? "void" : method.getReturnType().getSimpleName()); methodString.append(" ") .append(method.getName()) .append("("); Parameter[] parameters = method.getParameters(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; methodString.append(parameter.getType().getSimpleName()) .append(" ") .append(parameter.getName()); if (i < parameters.length - 1) { methodString.append(", "); } } methodString.append(")"); if (method.getExceptionTypes().length > 0) { methodString.append(" throws ") .append(Arrays.stream(method.getExceptionTypes()).map(Class::getSimpleName).collect(Collectors.joining(", "))); } res.put(method, methodString.toString()); } return res; }
JavaReflect { public static Map<Method, String> getDeclaredMethods(Class clazz) { Map<Method, String> res = new HashMap<>(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { StringBuilder methodString = new StringBuilder(); methodString.append(method.getReturnType().equals(Void.class) ? "void" : method.getReturnType().getSimpleName()); methodString.append(" ") .append(method.getName()) .append("("); Parameter[] parameters = method.getParameters(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; methodString.append(parameter.getType().getSimpleName()) .append(" ") .append(parameter.getName()); if (i < parameters.length - 1) { methodString.append(", "); } } methodString.append(")"); if (method.getExceptionTypes().length > 0) { methodString.append(" throws ") .append(Arrays.stream(method.getExceptionTypes()).map(Class::getSimpleName).collect(Collectors.joining(", "))); } res.put(method, methodString.toString()); } return res; } }
JavaReflect { public static Map<Method, String> getDeclaredMethods(Class clazz) { Map<Method, String> res = new HashMap<>(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { StringBuilder methodString = new StringBuilder(); methodString.append(method.getReturnType().equals(Void.class) ? "void" : method.getReturnType().getSimpleName()); methodString.append(" ") .append(method.getName()) .append("("); Parameter[] parameters = method.getParameters(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; methodString.append(parameter.getType().getSimpleName()) .append(" ") .append(parameter.getName()); if (i < parameters.length - 1) { methodString.append(", "); } } methodString.append(")"); if (method.getExceptionTypes().length > 0) { methodString.append(" throws ") .append(Arrays.stream(method.getExceptionTypes()).map(Class::getSimpleName).collect(Collectors.joining(", "))); } res.put(method, methodString.toString()); } return res; }  }
JavaReflect { public static Map<Method, String> getDeclaredMethods(Class clazz) { Map<Method, String> res = new HashMap<>(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { StringBuilder methodString = new StringBuilder(); methodString.append(method.getReturnType().equals(Void.class) ? "void" : method.getReturnType().getSimpleName()); methodString.append(" ") .append(method.getName()) .append("("); Parameter[] parameters = method.getParameters(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; methodString.append(parameter.getType().getSimpleName()) .append(" ") .append(parameter.getName()); if (i < parameters.length - 1) { methodString.append(", "); } } methodString.append(")"); if (method.getExceptionTypes().length > 0) { methodString.append(" throws ") .append(Arrays.stream(method.getExceptionTypes()).map(Class::getSimpleName).collect(Collectors.joining(", "))); } res.put(method, methodString.toString()); } return res; }  static Map<Method, String> getDeclaredMethods(Class clazz); static Map<Field, String> getDeclaredFields(Class clazz); }
JavaReflect { public static Map<Method, String> getDeclaredMethods(Class clazz) { Map<Method, String> res = new HashMap<>(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { StringBuilder methodString = new StringBuilder(); methodString.append(method.getReturnType().equals(Void.class) ? "void" : method.getReturnType().getSimpleName()); methodString.append(" ") .append(method.getName()) .append("("); Parameter[] parameters = method.getParameters(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; methodString.append(parameter.getType().getSimpleName()) .append(" ") .append(parameter.getName()); if (i < parameters.length - 1) { methodString.append(", "); } } methodString.append(")"); if (method.getExceptionTypes().length > 0) { methodString.append(" throws ") .append(Arrays.stream(method.getExceptionTypes()).map(Class::getSimpleName).collect(Collectors.joining(", "))); } res.put(method, methodString.toString()); } return res; }  static Map<Method, String> getDeclaredMethods(Class clazz); static Map<Field, String> getDeclaredFields(Class clazz);  }