PsiClass (final CreateClassKind classKind, final PsiDirectory directory, final String name, final PsiManager manager, @NotNull final PsiElement contextElement, final PsiFile sourceFile, final String superClassName) { final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject()); final PsiElementFactory factory = facade.getElementFactory(); return WriteAction.compute(() -> { try { PsiClass targetClass; if (directory != null) { try { targetClass = classKind.createInDirectory(directory, name); } catch (final IncorrectOperationException e) { scheduleFileOrPackageCreationFailedMessageBox(e, name, directory, false); return null; } if (!facade.getResolveHelper().isAccessible(targetClass, contextElement, null)) { PsiUtil.setModifierProperty(targetClass, PsiModifier.PUBLIC, true); } } else { //tests PsiClass aClass = classKind.create(factory, name); targetClass = (PsiClass)sourceFile.add(aClass); if (ScratchUtil.isScratch(sourceFile.getVirtualFile())) { PsiUtil.setModifierProperty(targetClass, PsiModifier.PACKAGE_LOCAL, true); } } if (StringUtil.isNotEmpty(superClassName) && (classKind != CreateClassKind.ENUM || !superClassName.equals(CommonClassNames.JAVA_LANG_ENUM)) && (classKind != CreateClassKind.RECORD || !superClassName.equals(CommonClassNames.JAVA_LANG_RECORD))) { setupSuperClassReference(targetClass, superClassName); } if (contextElement instanceof PsiJavaCodeReferenceElement) { CreateFromUsageBaseFix.setupGenericParameters(targetClass, (PsiJavaCodeReferenceElement)contextElement); } return targetClass; } catch (IncorrectOperationException e) { LOG.error(e); return null; } }); }