Collection<PsiMethod> (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiClass baseClassBuilder, List<BuilderInfo> builderInfos, @NotNull PsiClassType bType, @NotNull PsiClassType cType) { final Collection<PsiMethod> result = new ArrayList<>(); final Collection<String> existedMethodNames = PsiClassUtil.collectClassMethodsIntern(baseClassBuilder).stream() .filter(psiMethod -> PsiAnnotationSearchUtil.isNotAnnotatedWith(psiMethod, LombokClassNames.TOLERATE)) .map(PsiMethod::getName).collect(Collectors.toSet()); // create builder methods builderInfos.stream() .filter(info -> info.notAlreadyExistingMethod(existedMethodNames)) .map(BuilderInfo::renderBuilderMethods) .forEach(result::addAll); final PsiManager psiManager = psiClass.getManager(); final boolean forceCallSuper = PsiClassUtil.hasSuperClass(psiClass); if (shouldGenerateToBuilderMethods(psiAnnotation)) { // precalculate obtainVia builderInfos.forEach(BuilderInfo::withObtainVia); if (!existedMethodNames.contains(STATIC_FILL_VALUES_METHOD_NAME)) { // create '$fillValuesFromInstanceIntoBuilder' method final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiManager, STATIC_FILL_VALUES_METHOD_NAME) .withMethodReturnType(PsiTypes.voidType()) .withParameter(INSTANCE_VARIABLE_NAME, PsiClassUtil.getTypeWithGenerics(psiClass)) .withParameter(BUILDER_VARIABLE_NAME, getTypeWithWildcardsForSuperBuilderTypeParameters(baseClassBuilder)) .withContainingClass(baseClassBuilder) .withNavigationElement(psiClass) .withModifier(PsiModifier.PRIVATE) .withModifier(PsiModifier.STATIC); addTypeParameters(psiClass, null, methodBuilder); final String toBuilderMethodCalls = builderInfos.stream() .map(BuilderInfo::renderToBuilderCallWithoutPrependLogic) .collect(Collectors.joining(';' + BUILDER_VARIABLE_NAME + '.', BUILDER_VARIABLE_NAME + '.', ";\n")); methodBuilder.withBodyText(toBuilderMethodCalls); result.add(methodBuilder); } if (!existedMethodNames.contains(FILL_VALUES_METHOD_NAME)) { // create '$fillValuesFrom' method final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiManager, FILL_VALUES_METHOD_NAME) .withMethodReturnType(bType) .withParameter(INSTANCE_VARIABLE_NAME, cType) .withContainingClass(baseClassBuilder) .withNavigationElement(psiClass) .withModifier(PsiModifier.PROTECTED); final String callSuperCode = "super." + FILL_VALUES_METHOD_NAME + "(" + INSTANCE_VARIABLE_NAME + ");\n"; final String codeBlockText = String.format("%s%s.%s(%s, this);\nreturn self();", forceCallSuper ? callSuperCode : "", baseClassBuilder.getQualifiedName(), STATIC_FILL_VALUES_METHOD_NAME, INSTANCE_VARIABLE_NAME); methodBuilder.withBodyText(codeBlockText); result.add(methodBuilder); } } if (!existedMethodNames.contains(SELF_METHOD)) { // create 'self' method final LombokLightMethodBuilder selfMethod = new LombokLightMethodBuilder(psiManager, SELF_METHOD) .withMethodReturnType(bType) .withContainingClass(baseClassBuilder) .withNavigationElement(psiClass) .withModifier(PsiModifier.ABSTRACT) .withModifier(PsiModifier.PROTECTED); result.add(selfMethod); } final String buildMethodName = getBuildMethodName(psiAnnotation); if (!existedMethodNames.contains(buildMethodName)) { // create 'build' method final LombokLightMethodBuilder buildMethod = new LombokLightMethodBuilder(psiManager, buildMethodName) .withMethodReturnType(cType) .withContainingClass(baseClassBuilder) .withNavigationElement(psiClass) .withModifier(PsiModifier.ABSTRACT) .withModifier(PsiModifier.PUBLIC); createRelevantNonNullAnnotation(psiClass, buildMethod); result.add(buildMethod); } if (!existedMethodNames.contains(ToStringProcessor.TO_STRING_METHOD_NAME)) { // create 'toString' method result.add(createToStringMethod(psiAnnotation, baseClassBuilder, forceCallSuper)); } return result; }