private static PsiMethod rebuildMethod(@NotNull Project project, @NotNull PsiMethod fromMethod) {
    final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);

    final PsiMethod resultMethod;
    final PsiType returnType = fromMethod.getReturnType();
    if (null == returnType) {
      resultMethod = elementFactory.createConstructor(fromMethod.getName());
    }
    else {
      resultMethod = elementFactory.createMethod(fromMethod.getName(), returnType);
    }

    rebuildTypeParameter(fromMethod, resultMethod);

    final PsiClassType[] referencedTypes = fromMethod.getThrowsList().getReferencedTypes();
    if (referencedTypes.length > 0) {
      PsiJavaCodeReferenceElement[] refs = new PsiJavaCodeReferenceElement[referencedTypes.length];
      for (int i = 0; i < refs.length; i++) {
        refs[i] = elementFactory.createReferenceElementByType(referencedTypes[i]);
      }
      resultMethod.getThrowsList().replace(elementFactory.createReferenceList(refs));
    }

    for (PsiParameter fromParameter : fromMethod.getParameterList().getParameters()) {
      PsiParameter toParameter = elementFactory.createParameter(fromParameter.getName(), fromParameter.getType());
      final PsiModifierList fromParameterModifierList = fromParameter.getModifierList();
      if (fromParameterModifierList != null) {
        final PsiModifierList toParameterModifierList = toParameter.getModifierList();
        copyAnnotations(fromParameterModifierList, toParameterModifierList);
        toParameterModifierList.setModifierProperty(PsiModifier.FINAL, fromParameterModifierList.hasModifierProperty(PsiModifier.FINAL));
      }
      resultMethod.getParameterList().add(toParameter);
    }

    final PsiModifierList fromMethodModifierList = fromMethod.getModifierList();
    final PsiModifierList resultMethodModifierList = resultMethod.getModifierList();
    copyModifiers(fromMethodModifierList, resultMethodModifierList);
    copyAnnotations(fromMethodModifierList, resultMethodModifierList);

    PsiCodeBlock body = fromMethod.getBody();
    if (null != body) {
      resultMethod.getBody().replace(body);
    }
    else {
      resultMethod.getBody().delete();
    }

    return resultMethod;
  }
private static PsiMethod rebuildMethod(@NotNull Project project, @NotNull PsiMethod fromMethod)