RefactoringElementListener (PsiElement element) { if (element instanceof PsiFile) { VirtualFile virtualFile = ((PsiFile)element).getVirtualFile(); if (virtualFile != null && Objects.equals(new File(virtualFile.getPath()).getAbsolutePath(), new File(myScriptName).getAbsolutePath())) { return new RefactoringElementAdapter() { @Override public void elementRenamedOrMoved(@NotNull PsiElement newElement) { VirtualFile virtualFile = ((PsiFile)newElement).getVirtualFile(); if (virtualFile != null) { updateScriptName(virtualFile.getPath()); } } @Override public void undoElementMovedOrRenamed(@NotNull PsiElement newElement, @NotNull String oldQualifiedName) { updateScriptName(oldQualifiedName); } private void updateScriptName(String path) { myScriptName = FileUtil.toSystemDependentName(path); } }; } } return null; }