mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
Fix test data in several tests that failed after PyUtil#deleteElementSafely was introduces
* `pass` is consistently inserted on the new line now * excess spaces left after element was deleted are removed Use PyUtil#deleteElementSafely in pull, push and extract superclass refactoring implementations. It turned out that all problems with whitespaces left after we moved function are rooted in awkward implementation of PyFunctionImpl#delete() that delegated to plain AST manipulation and thus ignored usual additional reformatting step. I removed it and it's allowed to clean a lot of test files and remove the code that was added previously exactly for this purpose in PyMoveSymbolProcessor.
This commit is contained in:
@@ -534,11 +534,6 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
|
||||
return name != null ? name.getStartOffset() : super.getTextOffset();
|
||||
}
|
||||
|
||||
public void delete() throws IncorrectOperationException {
|
||||
ASTNode node = getNode();
|
||||
node.getTreeParent().removeChild(node);
|
||||
}
|
||||
|
||||
public PyStringLiteralExpression getDocStringExpression() {
|
||||
final PyStatementList stmtList = getStatementList();
|
||||
return DocStringUtil.findDocStringExpression(stmtList);
|
||||
|
||||
@@ -204,16 +204,6 @@ public final class PyClassRefactoringUtil {
|
||||
}
|
||||
|
||||
|
||||
public static <T extends PyElement & PyStatementListContainer> void insertPassIfNeeded(@NotNull T element) {
|
||||
final PyStatementList statements = element.getStatementList();
|
||||
if (statements.getStatements().length == 0) {
|
||||
statements.add(
|
||||
PyElementGenerator.getInstance(element.getProject())
|
||||
.createFromText(LanguageLevel.getDefault(), PyPassStatement.class, PyNames.PASS)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores references saved by {@link #rememberNamedReferences(com.intellij.psi.PsiElement, String...)}.
|
||||
*
|
||||
|
||||
@@ -65,7 +65,6 @@ class ClassFieldsManager extends FieldsManager {
|
||||
result.addAll(PyClassRefactoringUtil.copyFieldDeclarationToStatement(statements, destClass.getStatementList(), destClass));
|
||||
}
|
||||
deleteElements(statements);
|
||||
PyClassRefactoringUtil.insertPassIfNeeded(from);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ class InstanceFieldsManager extends FieldsManager {
|
||||
if (fromInitMethod != null) { // If class has no init method that means all its fields declared in other methods, so nothing to remove
|
||||
deleteElements(Collections2.filter(statements, new InitsOnly(fromInitMethod)));
|
||||
//We can't leave class constructor with empty body
|
||||
PyClassRefactoringUtil.insertPassIfNeeded(fromInitMethod);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.intellij.util.containers.MultiMap;
|
||||
import com.jetbrains.NotNullPredicate;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyElement;
|
||||
import com.jetbrains.python.refactoring.classes.PyClassRefactoringUtil;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.jetbrains.python.refactoring.classes.PyDependenciesComparator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -129,7 +129,6 @@ public abstract class MembersManager<T extends PyElement> implements Function<T,
|
||||
final Collection<PyMemberInfo<PyElement>> members = managerToMember.get(membersManager);
|
||||
TypeSafeMovingStrategy.moveCheckingTypesAtRunTime(from, membersManager, members, to);
|
||||
}*/
|
||||
PyClassRefactoringUtil.insertPassIfNeeded(from);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +244,7 @@ public abstract class MembersManager<T extends PyElement> implements Function<T,
|
||||
*/
|
||||
protected static void deleteElements(@NotNull final Collection<? extends PsiElement> pyElementsToDelete) {
|
||||
for (final PsiElement element : pyElementsToDelete) {
|
||||
element.delete();
|
||||
PyUtil.deleteElementSafely(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,6 @@ class MethodsManager extends MembersManager<PyFunction> {
|
||||
}
|
||||
deleteElements(methodsToMove);
|
||||
|
||||
PyClassRefactoringUtil.insertPassIfNeeded(from);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.jetbrains.python.refactoring.move;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
@@ -73,19 +70,8 @@ public class PyMoveSymbolProcessor {
|
||||
|
||||
private void deleteElement() {
|
||||
final PsiElement elementBody = PyMoveModuleMembersHelper.expandNamedElementBody(myMovedElement);
|
||||
final Project project = myMovedElement.getProject();
|
||||
final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
|
||||
final PsiFile pyFile = myMovedElement.getContainingFile();
|
||||
assert elementBody != null;
|
||||
final Document document = manager.getDocument(pyFile);
|
||||
final PsiElement prevVisible = PsiTreeUtil.prevVisibleLeaf(elementBody);
|
||||
final PsiElement nextVisible = PsiTreeUtil.nextVisibleLeaf(elementBody);
|
||||
PyUtil.deleteElementSafely(elementBody);
|
||||
assert document != null;
|
||||
manager.commitDocument(document);
|
||||
CodeStyleManager.getInstance(project).reformatText(pyFile,
|
||||
prevVisible != null ? prevVisible.getTextRange().getEndOffset() : 0,
|
||||
nextVisible != null ? nextVisible.getTextOffset() : pyFile.getTextLength());
|
||||
}
|
||||
|
||||
private void optimizeImports(@Nullable PsiFile originalFile) {
|
||||
|
||||
@@ -5,7 +5,7 @@ def foo():
|
||||
print("Hello Pycharm!")
|
||||
|
||||
|
||||
class A: pass
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
foo()
|
||||
@@ -2,8 +2,8 @@ def m():
|
||||
print 1
|
||||
|
||||
|
||||
class A: pass
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
b = A()
|
||||
a = m()
|
||||
|
||||
@@ -2,7 +2,7 @@ def m(x):
|
||||
print 1
|
||||
|
||||
|
||||
class A: pass
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
m(1)
|
||||
@@ -10,4 +10,4 @@ class Child(Base):
|
||||
self.my = 2
|
||||
|
||||
def f(self):
|
||||
pass
|
||||
pass
|
||||
@@ -10,4 +10,4 @@ class Child(Base):
|
||||
self.my = 2
|
||||
|
||||
def f(self):
|
||||
pass
|
||||
pass
|
||||
@@ -8,4 +8,4 @@ class Child(Base):
|
||||
self.my = 1
|
||||
|
||||
def f(self):
|
||||
pass
|
||||
pass
|
||||
@@ -6,4 +6,4 @@ class A:
|
||||
self.b = 1
|
||||
|
||||
def foo(self):
|
||||
pass
|
||||
pass
|
||||
@@ -10,4 +10,4 @@ class A:
|
||||
self.b = 1
|
||||
|
||||
def foo(self):
|
||||
pass
|
||||
pass
|
||||
@@ -5,6 +5,5 @@ def foo(r):
|
||||
:param r:
|
||||
:return:
|
||||
"""
|
||||
|
||||
x = 1
|
||||
x = 2
|
||||
@@ -7,4 +7,4 @@ class ToClass(object):
|
||||
|
||||
class FromClass(ToClass):
|
||||
def __init__(self):
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -20,8 +20,8 @@ class ToClass(object):
|
||||
|
||||
|
||||
class FromClass(ToClass):
|
||||
def __init__(self): pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def lala(self):
|
||||
pass
|
||||
@@ -3,4 +3,3 @@ __author__ = 'catherine'
|
||||
def function_1():
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
if True:
|
||||
pass
|
||||
|
||||
|
||||
while True:
|
||||
for _ in range(10):
|
||||
# comment
|
||||
|
||||
@@ -22,8 +22,6 @@ class Parent:
|
||||
|
||||
class Child(Parent): # Try to pull members up
|
||||
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super(Child, self).__init__()
|
||||
self.a = 12
|
||||
|
||||
@@ -6,4 +6,4 @@ class Parent2:
|
||||
|
||||
|
||||
class Child2(Parent2):
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -3,4 +3,4 @@ class Parent:
|
||||
|
||||
|
||||
class Child(Parent):
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -9,7 +9,8 @@ class Parent(object):
|
||||
|
||||
|
||||
class Child(Parent, object):
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
AC = 11
|
||||
|
||||
|
||||
@@ -8,12 +8,6 @@ class AnyClass(SuperClass):
|
||||
super(AnyClass, self).__init__()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def foo(self):
|
||||
pass
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ class Boo(Foo):
|
||||
this is boo
|
||||
very long boo
|
||||
'''
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
|
||||
class Boo(Foo):
|
||||
def foo(self):
|
||||
print "rrrrr"
|
||||
@@ -8,7 +8,8 @@ class Parent(object):
|
||||
"""
|
||||
CLASS_VAR_2 = 2
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def method_2(self):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
|
||||
class Zope(Foo):
|
||||
def _mine(self):
|
||||
print "zope"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class A:
|
||||
pass
|
||||
|
||||
|
||||
class B(A):
|
||||
def meth_b1(self):
|
||||
pass
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
|
||||
class Boo(Foo):
|
||||
def boo(self):
|
||||
print "rrrrr"
|
||||
|
||||
Reference in New Issue
Block a user