From eb02840ae676795b26c1fb208a48faf6b3570ca9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 22 Feb 2011 14:59:15 +0100 Subject: [PATCH] handle rename of working directory --- .../AbstractPythonTestRunConfiguration.java | 110 ++++++++++-------- 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/python/src/com/jetbrains/python/testing/AbstractPythonTestRunConfiguration.java b/python/src/com/jetbrains/python/testing/AbstractPythonTestRunConfiguration.java index 728a8b5bea7b..480d078dc73a 100644 --- a/python/src/com/jetbrains/python/testing/AbstractPythonTestRunConfiguration.java +++ b/python/src/com/jetbrains/python/testing/AbstractPythonTestRunConfiguration.java @@ -205,62 +205,70 @@ public abstract class AbstractPythonTestRunConfiguration extends AbstractPythonR @Override public RefactoringElementListener getRefactoringElementListener(PsiElement element) { - if (myTestType == TestType.TEST_FOLDER) { - if (element instanceof PsiDirectory) { - VirtualFile vFile = ((PsiDirectory)element).getVirtualFile(); - if (Comparing.equal(new File(vFile.getPath()).getAbsolutePath(), new File(myFolderName).getAbsolutePath())) { - return new RefactoringElementAdapter() { - @Override - protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { - myFolderName = FileUtil.toSystemDependentName(((PsiDirectory) newElement).getVirtualFile().getPath()); + if (element instanceof PsiDirectory) { + VirtualFile vFile = ((PsiDirectory)element).getVirtualFile(); + if ((myTestType == TestType.TEST_FOLDER && pathsEqual(vFile, myFolderName)) || pathsEqual(vFile, getWorkingDirectory())) { + return new RefactoringElementAdapter() { + @Override + protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { + String newPath = FileUtil.toSystemDependentName(((PsiDirectory)newElement).getVirtualFile().getPath()); + setWorkingDirectory(newPath); + if (myTestType == TestType.TEST_FOLDER) { + myFolderName = newPath; } - }; - } - } - } - else { - File scriptFile = new File(myScriptName); - if (!scriptFile.isAbsolute()) { - scriptFile = new File(getWorkingDirectory(), myScriptName); - } - PsiFile containingFile = element.getContainingFile(); - VirtualFile vFile = containingFile == null ? null : containingFile.getVirtualFile(); - if (vFile != null && Comparing.equal(new File(vFile.getPath()).getAbsolutePath(), scriptFile.getAbsolutePath())) { - if (element instanceof PsiFile) { - return new RefactoringElementAdapter() { - @Override - protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { - VirtualFile virtualFile = ((PsiFile)newElement).getVirtualFile(); - if (virtualFile != null) { - myScriptName = FileUtil.toSystemDependentName(virtualFile.getPath()); - } - } - }; - } - if (element instanceof PyClass && (myTestType == TestType.TEST_CLASS || myTestType == TestType.TEST_METHOD) && - Comparing.equal(((PyClass)element).getName(), myClassName)) { - return new RefactoringElementAdapter() { - @Override - protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { - myClassName = ((PyClass) newElement).getName(); - } - }; - } - if (element instanceof PyFunction && - Comparing.equal(((PyFunction) element).getName(), myMethodName)) { - ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(element, ScopeOwner.class); - if ((myTestType == TestType.TEST_FUNCTION && scopeOwner instanceof PyFile) || - (myTestType == TestType.TEST_METHOD && scopeOwner instanceof PyClass && Comparing.equal(scopeOwner.getName(), myClassName))) { - return new RefactoringElementAdapter() { - @Override - protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { - myMethodName = ((PyFunction) newElement).getName(); - } - }; } + }; + } + return null; + } + if (myTestType == TestType.TEST_FOLDER) { + return null; + } + File scriptFile = new File(myScriptName); + if (!scriptFile.isAbsolute()) { + scriptFile = new File(getWorkingDirectory(), myScriptName); + } + PsiFile containingFile = element.getContainingFile(); + VirtualFile vFile = containingFile == null ? null : containingFile.getVirtualFile(); + if (vFile != null && Comparing.equal(new File(vFile.getPath()).getAbsolutePath(), scriptFile.getAbsolutePath())) { + if (element instanceof PsiFile) { + return new RefactoringElementAdapter() { + @Override + protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { + VirtualFile virtualFile = ((PsiFile)newElement).getVirtualFile(); + if (virtualFile != null) { + myScriptName = FileUtil.toSystemDependentName(virtualFile.getPath()); + } + } + }; + } + if (element instanceof PyClass && (myTestType == TestType.TEST_CLASS || myTestType == TestType.TEST_METHOD) && + Comparing.equal(((PyClass)element).getName(), myClassName)) { + return new RefactoringElementAdapter() { + @Override + protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { + myClassName = ((PyClass) newElement).getName(); + } + }; + } + if (element instanceof PyFunction && + Comparing.equal(((PyFunction) element).getName(), myMethodName)) { + ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(element, ScopeOwner.class); + if ((myTestType == TestType.TEST_FUNCTION && scopeOwner instanceof PyFile) || + (myTestType == TestType.TEST_METHOD && scopeOwner instanceof PyClass && Comparing.equal(scopeOwner.getName(), myClassName))) { + return new RefactoringElementAdapter() { + @Override + protected void elementRenamedOrMoved(@NotNull PsiElement newElement) { + myMethodName = ((PyFunction) newElement).getName(); + } + }; } } } return null; } + + private static boolean pathsEqual(VirtualFile vFile, final String folderName) { + return Comparing.equal(new File(vFile.getPath()).getAbsolutePath(), new File(folderName).getAbsolutePath()); + } }