/* * TODO: This is identical to FieldInfo.getTypeString(), except for the * 'V' case. It is also very similar to #getParameterTypes(). Try * to refactor common code from these methods. */ private String getReturnTypeStringFromDescriptor(boolean qualified) { String descriptor = getDescriptor(); int rparen = descriptor.indexOf(')'); descriptor = descriptor.substring(rparen + 1); // return type desc. StringBuffer sb = new StringBuffer(); int braceCount = descriptor.lastIndexOf('[') + 1; switch (descriptor.charAt(braceCount)) { // BaseType case 'B': sb.append("byte"); break; case 'C': sb.append("char"); break; case 'D': sb.append("double"); break; case 'F': sb.append("float"); break; case 'I': sb.append("int"); break; case 'J': sb.append("long"); break; case 'S': sb.append("short"); break; case 'Z': sb.append("boolean"); break; case 'V': sb.append("void"); break; // ObjectType case 'L': String clazz = descriptor.substring(1, descriptor.length() - 1); // clazz = clazz.substring(clazz.lastIndexOf('/')+1); clazz = qualified ? org.fife.rsta.ac.java.Util.replaceChar(clazz, '/', '.') : clazz.substring(clazz.lastIndexOf('/') + 1); // clazz = clazz.substring(clazz.lastIndexOf('/')+1); sb.append(clazz); break; // Invalid field descriptor default: sb.append("UNSUPPORTED_TYPE_").append(descriptor); break; } for (int i = 0; i < braceCount; i++) { sb.append("[]"); } return sb.toString(); }
/** * Creates an array of types of each parameter by looking at the method's descriptor field. This * technique should work with Java 1.0+, but won't pick up on generic types added in Java 5. * * @return The parameter types. * @see #createParamTypesFromTypeSignature() */ private String[] createParamTypesFromDescriptor(boolean qualified) { String descriptor = getDescriptor(); int rparen = descriptor.indexOf(')'); String paramDescriptors = descriptor.substring(1, rparen); // String returnDescriptor = descriptor.substring(rparen+1); List paramTypeList = new ArrayList(); String type = null; while (paramDescriptors.length() > 0) { // Can't do lastIndexOf() as there may be > 1 array parameter // in the descriptors. // int braceCount = paramDescriptors.lastIndexOf('[') + 1; int braceCount = -1; while (paramDescriptors.charAt(++braceCount) == '[') ; int pos = braceCount; switch (paramDescriptors.charAt(pos)) { // BaseType case 'B': type = "byte"; pos++; break; case 'C': type = "char"; pos++; break; case 'D': type = "double"; pos++; break; case 'F': type = "float"; pos++; break; case 'I': type = "int"; pos++; break; case 'J': type = "long"; pos++; break; case 'S': type = "short"; pos++; break; case 'Z': type = "boolean"; pos++; break; // ObjectType case 'L': String clazz = paramDescriptors.substring(pos + 1, paramDescriptors.indexOf(';')); type = qualified ? org.fife.rsta.ac.java.Util.replaceChar(clazz, '/', '.') : clazz.substring(clazz.lastIndexOf('/') + 1); // clazz = org.fife.rsta.ac.java.Util.replaceChar(clazz, '/', '.'); // type = clazz; pos += clazz.length() + 2; // "+2" for the 'L' & semicolon break; // Invalid method descriptor default: String temp = "INVALID_TYPE_" + paramDescriptors; type = temp; pos += paramDescriptors.length(); break; } for (int i = 0; i < braceCount; i++) { type += "[]"; } paramTypeList.add(type); paramDescriptors = paramDescriptors.substring(pos); } String[] types = new String[paramTypeList.size()]; types = (String[]) paramTypeList.toArray(types); return types; }