PsiMethod (PsiExtensibleClass aClass, List<PsiMethod> ownMethods, @NotNull PsiRecordHeader recordHeader) { String className = aClass.getName(); if (className == null) return null; for (PsiMethod method : ownMethods) { if (JavaPsiRecordUtil.isCompactConstructor(method) || JavaPsiRecordUtil.isExplicitCanonicalConstructor(method)) return null; } PsiElementFactory factory = JavaPsiFacade.getElementFactory(recordHeader.getProject()); String sb = className + recordHeader.getText() + "{" + StringUtil.join(recordHeader.getRecordComponents(), c -> "this." + c.getName() + "=" + c.getName() + ";", "\n") + "}"; PsiMethod nonPhysical; try { nonPhysical = factory.createMethodFromText(sb, recordHeader.getContainingClass()); } catch (IncorrectOperationException e) { return null; } PsiModifierList classModifierList = aClass.getModifierList(); AccessModifier modifier = classModifierList == null ? AccessModifier.PUBLIC : AccessModifier.fromModifierList(classModifierList); nonPhysical.getModifierList().setModifierProperty(modifier.toPsiModifier(), true); return new LightRecordCanonicalConstructor(nonPhysical, aClass); }