mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed renaming of django file references (PY-9146).
This commit is contained in:
@@ -17,11 +17,15 @@ package com.jetbrains.python.psi;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.CachingReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceHelper;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -46,4 +50,15 @@ public class FileReferenceWithOneContext extends FileReference {
|
||||
protected Collection<PsiFileSystemItem> getContextsForBindToElement(VirtualFile curVFile, Project project, FileReferenceHelper helper) {
|
||||
return getContexts();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiElement rename(final String newName) throws IncorrectOperationException {
|
||||
if (FileUtil.isAbsolutePlatformIndependent(newName)) {
|
||||
return super.rename(newName);
|
||||
}
|
||||
else {
|
||||
PsiElement element = getElement();
|
||||
return CachingReference.getManipulator(element).handleContentChange(element, getRangeInElement(), newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class TemplateFileReference extends WeakFileReference {
|
||||
dstItem = _dstItem;
|
||||
}
|
||||
|
||||
final Collection<PsiFileSystemItem> contexts = getFileReferenceSet().getDefaultContexts();
|
||||
final Collection<PsiFileSystemItem> contexts = getContexts();
|
||||
switch (contexts.size()) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
@@ -51,11 +51,12 @@ public class PyPathEvaluator {
|
||||
if (argValue == null) {
|
||||
return null;
|
||||
}
|
||||
if (FileUtil.isAbsolute(argValue)) {
|
||||
if (FileUtil.isAbsolutePlatformIndependent(argValue)) {
|
||||
return argValue;
|
||||
}
|
||||
else {
|
||||
return new File(new File(containingFilePath).getParent(), argValue).getPath();
|
||||
String path = new File(new File(containingFilePath).getParent(), argValue).getPath();
|
||||
return path.replace("\\", "/");
|
||||
}
|
||||
}
|
||||
else if (call.isCalleeText(PyNames.REPLACE) && args.length == 2) {
|
||||
@@ -98,13 +99,18 @@ public class PyPathEvaluator {
|
||||
}
|
||||
|
||||
public static String evaluatePathInJoin(String containingFilePath, PyExpression[] args, int endElement, Set<PyExpression> visited) {
|
||||
String result = containingFilePath;
|
||||
String result = null;
|
||||
for (int i = 0; i < endElement; i++) {
|
||||
String arg = evaluate(args[i], result, visited);
|
||||
String arg = evaluate(args[i], containingFilePath, visited);
|
||||
if (arg == null) {
|
||||
return null;
|
||||
}
|
||||
result = arg;
|
||||
if (result == null) {
|
||||
result = arg;
|
||||
}
|
||||
else {
|
||||
result = new File(result, arg).getPath().replace("\\", "/");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user