@NotNull
private <T extends PsiModifierListOwner & PsiNamedElement> PsiMethod generateDelegateMethod(@NotNull PsiClass psiClass, @NotNull T psiElement, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull PsiSubstitutor psiSubstitutor) {
final PsiType returnType = psiSubstitutor.substitute(psiMethod.getReturnType());
final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiClass.getManager(), psiMethod.getName())
.withModifier(PsiModifier.PUBLIC)
.withMethodReturnType(returnType)
.withContainingClass(psiClass)
//Have to go to original method, or some refactoring action will not work (like extract parameter oder change signature)
.withNavigationElement(psiMethod);
for (PsiTypeParameter typeParameter : psiMethod.getTypeParameters()) {
methodBuilder.withTypeParameter(typeParameter);
}
final PsiReferenceList throwsList = psiMethod.getThrowsList();
for (PsiClassType psiClassType : throwsList.getReferencedTypes()) {
methodBuilder.withException(psiClassType);
}
final PsiParameterList parameterList = psiMethod.getParameterList();
final StringBuilder paramString = new StringBuilder();
int parameterIndex = 0;
for (PsiParameter psiParameter : parameterList.getParameters()) {
final PsiType psiParameterType = psiSubstitutor.substitute(psiParameter.getType());
final String generatedParameterName = StringUtils.defaultIfEmpty(psiParameter.getName(), "p" + parameterIndex);
methodBuilder.withParameter(generatedParameterName, psiParameterType);
parameterIndex++;
paramString.append(generatedParameterName).append(',');
}
if (paramString.length() > 0) {
paramString.deleteCharAt(paramString.length() - 1);
}
final boolean isMethodCall = psiElement instanceof PsiMethod;
methodBuilder.withBody(PsiMethodUtil.createCodeBlockFromText(
String.format("%sthis.%s%s.%s(%s);",
PsiType.VOID.equals(returnType) ? "" : "return ",
psiElement.getName(),
isMethodCall ? "()" : "",
psiMethod.getName(),