private PsiClass createClass(String name) throws IncorrectOperationException {
    renameReferences(myAnonOrLocalClass);
    updateSelfReferences(myAnonOrLocalClass, name);

    PsiElementFactory factory = JavaPsiFacade.getElementFactory(myProject);

    PsiClass aClass;
    if (myAnonOrLocalClass instanceof PsiAnonymousClass anonymousClass) {
      aClass = createInnerFromAnonymous(name, anonymousClass, factory);
    }
    else {
      aClass = createInnerFromLocal(name, factory);
    }
    final PsiTypeParameterList typeParameterList = aClass.getTypeParameterList();
    LOG.assertTrue(typeParameterList != null);
    for (PsiTypeParameter typeParameter : myTypeParametersToCreate) {
      typeParameterList.add(typeParameter);
    }

    setupModifiers(aClass);

    if (myVariableInfos.length > 0) {
      removeInitializers(aClass);
      createFields(aClass);
    }

    if (myAnonOrLocalClass instanceof PsiAnonymousClass) {
      createAnonymousClassConstructor(aClass);
    }

    PsiElement lastChild = aClass.getLastChild();
    if (PsiUtil.isJavaToken(lastChild, JavaTokenType.SEMICOLON)) {
      lastChild.delete();
    }

    return aClass;
  }
private PsiClass createClass(String name)