Search in sources :

Example 1 with RefactoringInfo

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());
}
Also used : CoreTextSelection(org.python.pydev.shared_core.string.CoreTextSelection) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) RefactoringInfo(org.python.pydev.refactoring.core.base.RefactoringInfo) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with RefactoringInfo

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());
}
Also used : CoreTextSelection(org.python.pydev.shared_core.string.CoreTextSelection) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) RefactoringInfo(org.python.pydev.refactoring.core.base.RefactoringInfo) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with RefactoringInfo

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());
}
Also used : CoreTextSelection(org.python.pydev.shared_core.string.CoreTextSelection) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) RefactoringInfo(org.python.pydev.refactoring.core.base.RefactoringInfo) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with RefactoringInfo

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());
}
Also used : CoreTextSelection(org.python.pydev.shared_core.string.CoreTextSelection) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) RefactoringInfo(org.python.pydev.refactoring.core.base.RefactoringInfo) ICoreTextSelection(org.python.pydev.shared_core.string.ICoreTextSelection) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with RefactoringInfo

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);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringInfo(org.python.pydev.refactoring.core.base.RefactoringInfo)

Aggregations

RefactoringInfo (org.python.pydev.refactoring.core.base.RefactoringInfo)27 Document (org.eclipse.jface.text.Document)23 IDocument (org.eclipse.jface.text.IDocument)23 CoreTextSelection (org.python.pydev.shared_core.string.CoreTextSelection)23 ICoreTextSelection (org.python.pydev.shared_core.string.ICoreTextSelection)23 IGrammarVersionProvider (org.python.pydev.core.IGrammarVersionProvider)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Change (org.eclipse.ltk.core.refactoring.Change)3 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)3 MisconfigurationException (org.python.pydev.core.MisconfigurationException)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ArrayList (java.util.ArrayList)1 Module (org.python.pydev.parser.jython.ast.Module)1 ModuleAdapter (org.python.pydev.refactoring.ast.adapters.ModuleAdapter)1 ExtractLocalRefactoring (org.python.pydev.refactoring.coderefactoring.extractlocal.ExtractLocalRefactoring)1 ExtractLocalRequestProcessor (org.python.pydev.refactoring.coderefactoring.extractlocal.ExtractLocalRequestProcessor)1 InlineLocalRefactoring (org.python.pydev.refactoring.coderefactoring.inlinelocal.InlineLocalRefactoring)1 PythonNatureStub (org.python.pydev.refactoring.tests.adapter.PythonNatureStub)1 PythonRefactoringWizard (org.python.pydev.refactoring.ui.core.PythonRefactoringWizard)1