PsiMethod () { String constructor; AccessModifier accessModifier = AccessModifier.PUBLIC; PsiModifierList list = myRecord.getModifierList(); if (list != null) { accessModifier = AccessModifier.fromModifierList(list); } if (myCompact) { constructor = myRecord.getName() + "{\n}"; } else { PsiRecordComponent[] components = myRecord.getRecordComponents(); String parameters = StreamEx.of(components).map(PsiRecordComponent::getText).joining(",", "(", ")"); String body = StreamEx.of(components).map(PsiRecordComponent::getName).map(name -> "this." + name + "=" + name + ";\n").joining("", "{", "}"); constructor = myRecord.getName() + parameters + body; } Project project = myRecord.getProject(); PsiMethod ctor = JavaPsiFacade.getElementFactory(project).createMethodFromText(constructor, myRecord); ctor.getModifierList().setModifierProperty(accessModifier.toPsiModifier(), true); if (!myCompact) { JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(myRecord.getContainingFile()); boolean finalParameters = settings.isGenerateFinalParameters(); PsiParameterList parameterList = ctor.getParameterList(); for (PsiParameter parameter : parameterList.getParameters()) { PsiModifierList modifierList = parameter.getModifierList(); if (modifierList != null) { modifierList.setModifierProperty(PsiModifier.FINAL, finalParameters); PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(modifierList); for (PsiAnnotation annotation : parameter.getAnnotations()) { PsiAnnotation.TargetType applicable = AnnotationTargetUtil.findAnnotationTarget(annotation, targets); if (applicable == null) { annotation.delete(); } } } } } CodeStyleManager.getInstance(project).reformat(ctor); return ctor; }