Search in sources :

Example 1 with ICoreTextSelection

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

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

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

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

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

ICoreTextSelection (org.python.pydev.shared_core.string.ICoreTextSelection)46 CoreTextSelection (org.python.pydev.shared_core.string.CoreTextSelection)31 Document (org.eclipse.jface.text.Document)26 IDocument (org.eclipse.jface.text.IDocument)26 RefactoringInfo (org.python.pydev.refactoring.core.base.RefactoringInfo)23 BadLocationException (org.eclipse.jface.text.BadLocationException)7 Tuple (org.python.pydev.shared_core.structure.Tuple)6 IRegion (org.eclipse.jface.text.IRegion)5 SimpleNode (org.python.pydev.parser.jython.SimpleNode)5 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 Module (org.python.pydev.parser.jython.ast.Module)3 ModuleAdapter (org.python.pydev.refactoring.ast.adapters.ModuleAdapter)3 ArrayList (java.util.ArrayList)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 PySelection (org.python.pydev.core.docutils.PySelection)2 PythonPairMatcher (org.python.pydev.core.docutils.PythonPairMatcher)2