use of org.python.pydev.refactoring.core.base.RefactoringInfo in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethodGlobalParams.
public void testPyCreateMethodGlobalParams() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "MyMethod(a, b())";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, 0, 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT);
assertContentsEqual("" + "def MyMethod(${a}, ${b}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyMethod(a, b())" + "", document.get());
}
use of org.python.pydev.refactoring.core.base.RefactoringInfo in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethodInClass.
public void testPyCreateMethodInClass() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "" + "class A(object):\n" + " '''comment'''\n" + "\n" + "A.MyMethod(a, b())";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - "hod(a, b())".length(), 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.setCreateInClass("A");
pyCreateMethod.setCreateAs(PyCreateMethodOrField.CLASSMETHOD);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_END);
assertContentsEqual("" + "" + "class A(object):\n" + " '''comment'''\n" + "\n" + " \n" + " @classmethod\n" + " def MyMethod(cls, ${a}, ${b}):\n" + " ${pass}${cursor}\n" + " \n" + " \n" + "\n" + "A.MyMethod(a, b())" + "", document.get());
}
use of org.python.pydev.refactoring.core.base.RefactoringInfo in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethodWithTabs.
public void testPyCreateMethodWithTabs() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "" + "class A(object):\n" + "\n" + "\n" + "\n" + "\tdef m1(self):\n" + "\t\tself.m2()";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - "2()".length(), 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.setCreateInClass("A");
pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT);
String expected = "" + "class A(object):\n" + "\n" + "\n" + "\n" + "\tdef m2(self):\n" + "\t\t${pass}${cursor}\n" + "\t\n" + "\t\n" + "\tdef m1(self):\n" + "\t\tself.m2()";
assertContentsEqual(expected, document.get());
}
use of org.python.pydev.refactoring.core.base.RefactoringInfo in project Pydev by fabioz.
the class PyCreateMethodTest method testPyCreateMethod.
public void testPyCreateMethod() {
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
String source = "" + "class A(object):\n" + "\n" + "\n" + "\n" + " def m1(self):\n" + " self.m2()";
IDocument document = new Document(source);
ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - "2()".length(), 0);
RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
pyCreateMethod.setCreateInClass("A");
pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT);
String expected = "" + "class A(object):\n" + "\n" + "\n" + "\n" + " def m2(self):\n" + " ${pass}${cursor}\n" + " \n" + " \n" + " def m1(self):\n" + " self.m2()";
assertContentsEqual(expected, document.get());
}
use of org.python.pydev.refactoring.core.base.RefactoringInfo in project Pydev by fabioz.
the class AbstractPyCreateAction method run.
/*
* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
if (targetEditor == null) {
Status status = SharedCorePlugin.makeStatus(IStatus.ERROR, "Unable to do refactoring.", null);
ErrorDialog.openError(EditorUtils.getShell(), "Unable to do refactoring.", "Target editor is null (not PyEdit).", status);
return;
}
try {
RefactoringInfo refactoringInfo = new RefactoringInfo(targetEditor);
execute(refactoringInfo, LOCATION_STRATEGY_BEFORE_CURRENT);
} catch (Throwable e) {
Log.log(e);
Throwable initial = e;
while (e.getCause() != null) {
e = e.getCause();
}
// get the root cause
Status status = SharedCorePlugin.makeStatus(IStatus.ERROR, "Error making refactoring", initial);
ErrorDialog.openError(EditorUtils.getShell(), "Error making refactoring", e.getMessage(), status);
}
}
Aggregations