private void printMethods(IType type, StringBuilder sb) throws JavaModelException { IMethod[] methods = type.getMethods(); if (methods.length > 0) { sb.append("<METHODS>"); for (IMethod method : methods) { sb.append("<METHOD NAME=\"" + method.getElementName() + "\">"); ILocalVariable[] vars = method.getParameters(); sb.append("<PARAMETERS>"); if (vars.length > 0) { for (int i = 0; i < vars.length; i += 1) { System.out.println(vars[i].toString()); System.out.println(vars[i].getSource()); sb.append("<PARAMETER>" + vars[i].getSource() + "</PARAMETER>"); } } else { sb.append("<PARAMETER>void</PARAMETER>"); } sb.append("</PARAMETERS>"); // method.gets sb.append("<SIGNATURE>" + method.getSignature() + "</SIGNATURE>"); sb.append("<RETURNTYPE>" + method.getReturnType() + "</RETURNTYPE>"); sb.append("</METHOD>"); } sb.append("</METHODS>"); } }
public static String getReturnTypeString(IMethod method, boolean classTypesOnly) { try { String qualifiedReturnType = Signature.getReturnType(method.getSignature()); if (!classTypesOnly || qualifiedReturnType.startsWith("L") || qualifiedReturnType.startsWith("Q")) { return Signature.getSignatureSimpleName(qualifiedReturnType.replace('/', '.')); } } catch (IllegalArgumentException e) { } catch (JavaModelException e) { } return null; }
public static String[] getParameterTypesString(IMethod method) { try { String[] parameterQualifiedTypes = Signature.getParameterTypes(method.getSignature()); int length = parameterQualifiedTypes == null ? 0 : parameterQualifiedTypes.length; String[] parameterPackages = new String[length]; for (int i = 0; i < length; i++) { parameterQualifiedTypes[i] = parameterQualifiedTypes[i].replace('/', '.'); parameterPackages[i] = Signature.getSignatureSimpleName(parameterQualifiedTypes[i]); } return parameterPackages; } catch (IllegalArgumentException e) { } catch (JavaModelException e) { } return null; }