PsiClass (String name, PsiElementFactory factory) { PsiClass aClass = (PsiClass)myAnonOrLocalClass.copy(); PsiIdentifier identifier = factory.createIdentifier(name); Objects.requireNonNull(aClass.getNameIdentifier()).replace(identifier); for (PsiMethod method : aClass.getMethods()) { if (method.isConstructor()) { PsiIdentifier methodName = method.getNameIdentifier(); if (methodName != null) { methodName.replace(identifier); } } } return aClass; }