PsiJavaFile (final String name, final VirtualFile dir) { executeCommand("Create Class" + name, () -> { ApplicationManager.getApplication().runWriteAction(() -> { myClass = JavaDirectoryService.getInstance().createClass(myPsiManager.findDirectory(dir), name); myClass = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(myClass); }); myContainingFile = (PsiJavaFile)myClass.getContainingFile(); }); return myContainingFile; }