void (String newClassName, PsiClass psiClass) { String actionTitle = getTitle(psiClass); Project project = psiClass.getProject(); WriteCommandAction.writeCommandAction(project).withName(actionTitle).withGroupId(actionTitle).run(() -> { PsiJavaFile containingFile = ObjectUtils.tryCast(psiClass.getContainingFile(), PsiJavaFile.class); LOG.assertTrue(containingFile != null); PsiClass[] classes = containingFile.getClasses(); int nClasses = classes.length; LOG.assertTrue(nClasses > 0); final PsiTypeParameterList oldTypeParameterList = psiClass.getTypeParameterList(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiClass newClass = factory.createClass(newClassName); PsiModifierList modifiers = newClass.getModifierList(); LOG.assertTrue(modifiers != null); modifiers.setModifierProperty(PsiModifier.PUBLIC, false); newClass = (PsiClass)containingFile.addAfter(newClass, classes[nClasses - 1]); PsiIdentifier newClassIdentifier = newClass.getNameIdentifier(); LOG.assertTrue(newClassIdentifier != null); startTemplate(oldTypeParameterList, project, psiClass, newClass, false); CodeInsightUtil.positionCursor(project, containingFile, newClassIdentifier); }); }