void (Project project, PsiElement element) { final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class); if (newExpression == null) { return; } final PsiMethod constructor = newExpression.resolveConstructor(); if (constructor != null) { final PsiModifierList modifierList = constructor.getModifierList(); modifierList.setModifierProperty(PsiModifier.PRIVATE, false); return; } final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)element; final PsiElement target = referenceElement.resolve(); if (!(target instanceof PsiClass aClass)) { return; } final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); final PsiMethod newConstructor = elementFactory.createConstructor(); final PsiModifierList modifierList = newConstructor.getModifierList(); modifierList.setModifierProperty(PsiModifier.PACKAGE_LOCAL, true); aClass.add(newConstructor); }