Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static class MemberInfoParam extends MemberInfo {
- private final int paramID;
- private final String type;
- public MemberInfoParam(ISrgMapping srg, IMCPMapping mcp, int paramID) {
- this(srg, mcp, paramID, findType(srg, paramID));
- }
- public static String findType(ISrgMapping method, int param) {
- int i = 1;
- String desc = method.getDesc();
- Matcher paramMatcher = DESC_PARAM.matcher(desc.substring(1, desc.lastIndexOf(')')));
- while (paramMatcher.find()) {
- if (i == param) {
- return paramMatcher.group();
- }
- i++;
- }
- throw new IllegalArgumentException("Could not find type name. Method: " + method + " param: " + param);
- }
- public MemberInfoParam(ISrgMapping srg, IMCPMapping mcp, int paramID, String type) {
- super(srg, mcp);
- this.paramID = paramID;
- this.type = getReadableName(type);
- }
- private static String getReadableName(String className) {
- String ret = className;
- int arrayDimensions = 0;
- while (ret.startsWith("[")) {
- ret = ret.substring(1);
- arrayDimensions++;
- }
- if (className.startsWith("L")) {
- ret = className.replaceAll("^L", "").replaceAll(";$", "").replaceAll("\\/", ".");
- } else {
- if (ret.length() != 1) {
- throw new IllegalArgumentException("Invalid descriptor \"" + className + "");
- }
- ret = getPrimitiveName(ret.charAt(0));
- }
- for (int i = 0; i < arrayDimensions; i++) {
- ret += "[]";
- }
- return ret;
- }
- private static String getPrimitiveName(char desc) {
- switch(desc) {
- case 'B': return "byte";
- case 'C': return "char";
- case 'D': return "double";
- case 'F': return "float";
- case 'I': return "int";
- case 'J': return "long";
- case 'S': return "short";
- case 'Z': return "boolean";
- default: throw new IllegalArgumentException("Invalid primitive descriptor '" + desc + "'");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment