Search in sources :

Example 1 with CoreTextSelection

use of org.python.pydev.shared_core.string.CoreTextSelection 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 CoreTextSelection

use of org.python.pydev.shared_core.string.CoreTextSelection 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 CoreTextSelection

use of org.python.pydev.shared_core.string.CoreTextSelection 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 CoreTextSelection

use of org.python.pydev.shared_core.string.CoreTextSelection 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 CoreTextSelection

use of org.python.pydev.shared_core.string.CoreTextSelection in project Pydev by fabioz.

the class PyCreateClassTest method testPyCreateClassInSameModule5.

public void testPyCreateClassInSameModule5() throws Exception {
    PyCreateClass pyCreateClass = new PyCreateClass();
    String source = "" + "a = 10\n" + "#=============\n" + "#Comment\n" + "#=============\n" + "class Existing(object):\n" + "    pass\n" + "\n" + "MyClass()";
    IDocument document = new Document(source);
    ICoreTextSelection selection = new CoreTextSelection(document, document.getLength() - 5, 0);
    RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER);
    pyCreateClass.execute(info, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT);
    assertContentsEqual("" + "a = 10\n" + "#=============\n" + "#Comment\n" + "#=============\n" + "class Existing(object):\n" + "    pass\n" + "\n" + "\n" + "class MyClass(${object}):\n" + "    ${pass}${cursor}\n" + "\n" + "\n" + "MyClass()" + "", 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)

Aggregations

CoreTextSelection (org.python.pydev.shared_core.string.CoreTextSelection)41 ICoreTextSelection (org.python.pydev.shared_core.string.ICoreTextSelection)32 IDocument (org.eclipse.jface.text.IDocument)29 Document (org.eclipse.jface.text.Document)27 RefactoringInfo (org.python.pydev.refactoring.core.base.RefactoringInfo)23 BadLocationException (org.eclipse.jface.text.BadLocationException)7 PySelection (org.python.pydev.core.docutils.PySelection)6 ITextSelection (org.eclipse.jface.text.ITextSelection)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 IGrammarVersionProvider (org.python.pydev.core.IGrammarVersionProvider)4 Change (org.eclipse.ltk.core.refactoring.Change)3 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)3 TextSelectionUtils (org.python.pydev.shared_core.string.TextSelectionUtils)3 ArrayList (java.util.ArrayList)2 MisconfigurationException (org.python.pydev.core.MisconfigurationException)2 SimpleNode (org.python.pydev.parser.jython.SimpleNode)2 Module (org.python.pydev.parser.jython.ast.Module)2 ScopeSelectionAction (org.python.pydev.shared_ui.actions.ScopeSelectionAction)2 Comparator (java.util.Comparator)1 TreeSet (java.util.TreeSet)1