void () { PsiClass aClass = myJavaFacade.findClass("pack.MyClass2", GlobalSearchScope.allScope(myProject)); assertNotNull(aClass); PsiField field = aClass.getFields()[0]; ApplicationManager.getApplication().runWriteAction(() -> { aClass.getNameIdentifier().replace(myJavaFacade.getElementFactory().createIdentifier("NewName")); }); assertTrue(field.isValid()); }