PsiMethod () { PsiMethod result; try { final StringBuilder methodTextDeclaration = new StringBuilder(); methodTextDeclaration.append(getAllModifierProperties(getModifierList())); PsiType returnType = getReturnType(); if (null != returnType && returnType.isValid()) { methodTextDeclaration.append(returnType.getCanonicalText()).append(' '); } methodTextDeclaration.append(getName()); methodTextDeclaration.append('('); if (getParameterList().getParametersCount() > 0) { for (PsiParameter parameter : getParameterList().getParameters()) { methodTextDeclaration.append(parameter.getType().getCanonicalText()).append(' ').append(parameter.getName()).append(','); } methodTextDeclaration.deleteCharAt(methodTextDeclaration.length() - 1); } methodTextDeclaration.append(')'); methodTextDeclaration.append('{').append(" ").append('}'); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(getManager().getProject()); result = elementFactory.createMethodFromText(methodTextDeclaration.toString(), getContainingClass()); if (null != getBody()) { result.getBody().replace(getBody()); } } catch (Exception ex) { result = null; } return result; }