Search in sources :

Example 61 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class TddTestWorkbench method checkCreateNewModule2.

private void checkCreateNewModule2() throws CoreException, BadLocationException, MisconfigurationException {
    String mod1Contents;
    TddCodeGenerationQuickFixParticipant quickFix;
    PySelection ps;
    List<ICompletionProposalHandle> props;
    IFile mod2 = initFile.getParent().getFile(new Path("pack2a/module_new.py"));
    final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
    ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {

        @Override
        public Object call(PyEdit obj) {
            pyEditCreated.add(obj);
            return null;
        }
    };
    PyEdit.onPyEditCreated.registerListener(listener);
    try {
        // give it a bit more time...
        goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
        mod1Contents = "" + "import pack1.pack2.pack2a.module_new";
        setContentsAndWaitReparseAndError(mod1Contents);
        quickFix = new TddCodeGenerationQuickFixParticipant();
        int offset = mod1Contents.length();
        ps = new PySelection(editor.getDocument(), offset);
        assertTrue(quickFix.isValid(ps, "", editor, offset));
        props = waitForQuickFixProps(quickFix, ps, offset);
        assertTrue(!mod2.exists());
        findCompletion(props, "Create pack1.pack2.pack2a.module_new module").apply(editor.getISourceViewer(), '\n', 0, offset);
        assertTrue(mod2.exists());
        assertEquals(1, pyEditCreated.size());
    } finally {
        for (PyEdit edit : pyEditCreated) {
            edit.close(false);
        }
        PyEdit.onPyEditCreated.unregisterListener(listener);
        mod2.delete(true, null);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) PySelection(org.python.pydev.core.docutils.PySelection) ICallbackListener(org.python.pydev.shared_core.callbacks.ICallbackListener) PyEdit(org.python.pydev.editor.PyEdit)

Example 62 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class TddTestWorkbench method checkCreateMethodAtOtherModule2.

private void checkCreateMethodAtOtherModule2() throws CoreException, BadLocationException, MisconfigurationException {
    String mod1Contents;
    TddCodeGenerationQuickFixParticipant quickFix;
    PySelection ps;
    IFile mod2 = initFile.getParent().getFile(new Path("other_module3.py"));
    String str = "" + "class Bar(object):\n" + "    pass\n" + "";
    mod2.create(new ByteArrayInputStream(str.getBytes()), true, null);
    PyEdit editor2 = (PyEdit) PyOpenEditor.doOpenEditor(mod2);
    try {
        // give it a bit more time...
        goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
        mod1Contents = "" + "import other_module3\n" + "other_module3.Bar.Foo(10, 20)";
        setContentsAndWaitReparseAndError(mod1Contents);
        quickFix = new TddCodeGenerationQuickFixParticipant();
        int offset = mod1Contents.length() - "o(a, b)".length();
        ps = new PySelection(editor.getDocument(), offset);
        assertTrue(quickFix.isValid(ps, "", editor, offset));
        waitForQuickFixProps(quickFix, ps, offset, "Create Foo classmethod at Bar in other_module3.py").apply(editor.getISourceViewer(), '\n', 0, offset);
        assertContentsEqual("" + "class Bar(object):\n" + "    \n" + "    \n" + "    @classmethod\n" + "    def Foo(cls, param1, param2):\n" + "        pass\n" + "    \n" + "    \n" + "\n" + "", editor2.getDocument().get());
    } finally {
        editor2.close(false);
        mod2.delete(true, null);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) PySelection(org.python.pydev.core.docutils.PySelection) PyEdit(org.python.pydev.editor.PyEdit)

Example 63 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class TddTestWorkbench method checkCreateNewModuleWithClass.

private void checkCreateNewModuleWithClass() throws CoreException, BadLocationException, MisconfigurationException {
    String mod1Contents;
    TddCodeGenerationQuickFixParticipant quickFix;
    PySelection ps;
    List<ICompletionProposalHandle> props;
    IFile mod2 = initFile.getParent().getFolder(new Path("pack3")).getFile(new Path("module_new2.py"));
    final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
    ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {

        @Override
        public Object call(PyEdit obj) {
            pyEditCreated.add(obj);
            return null;
        }
    };
    PyEdit.onPyEditCreated.registerListener(listener);
    try {
        // give it a bit more time...
        goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
        mod1Contents = "" + "from pack1.pack2.pack3.module_new2 import Foo";
        setContentsAndWaitReparseAndError(mod1Contents);
        quickFix = new TddCodeGenerationQuickFixParticipant();
        int offset = mod1Contents.length();
        ps = new PySelection(editor.getDocument(), offset);
        assertTrue(quickFix.isValid(ps, "", editor, offset));
        props = waitForQuickFixProps(quickFix, ps, offset);
        assertTrue(!mod2.exists());
        findCompletion(props, "Create Foo class at new module pack1.pack2.pack3.module_new2").apply(editor.getISourceViewer(), '\n', 0, offset);
        assertTrue(mod2.exists());
        assertEquals(1, pyEditCreated.size());
        assertContentsEqual("" + "class Foo(object):\n" + "    pass\n" + "\n" + "\n" + "", pyEditCreated.get(0).getDocument().get());
    } finally {
        for (PyEdit edit : pyEditCreated) {
            edit.close(false);
        }
        PyEdit.onPyEditCreated.unregisterListener(listener);
        mod2.delete(true, null);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) PySelection(org.python.pydev.core.docutils.PySelection) ICallbackListener(org.python.pydev.shared_core.callbacks.ICallbackListener) PyEdit(org.python.pydev.editor.PyEdit)

Example 64 with PyEdit

use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.

the class AbstractTddRefactorCompletion method forceReparseInBaseEditorAnd.

protected void forceReparseInBaseEditorAnd(PyEdit... others) {
    if (edit != null) {
        PyParser parser = edit.getParser();
        parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true));
    }
    for (PyEdit e : others) {
        PyParser parser = e.getParser();
        parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true));
    }
}
Also used : PyParser(org.python.pydev.parser.PyParser) PyEdit(org.python.pydev.editor.PyEdit)

Aggregations

PyEdit (org.python.pydev.editor.PyEdit)64 PySelection (org.python.pydev.core.docutils.PySelection)22 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)14 BadLocationException (org.eclipse.jface.text.BadLocationException)13 Path (org.eclipse.core.runtime.Path)12 IDocument (org.eclipse.jface.text.IDocument)12 MisconfigurationException (org.python.pydev.core.MisconfigurationException)9 ICompletionProposalHandle (org.python.pydev.shared_core.code_completion.ICompletionProposalHandle)9 IPythonNature (org.python.pydev.core.IPythonNature)8 File (java.io.File)7 ICallbackListener (org.python.pydev.shared_core.callbacks.ICallbackListener)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IRegion (org.eclipse.jface.text.IRegion)5 ITextSelection (org.eclipse.jface.text.ITextSelection)5 IEditorInput (org.eclipse.ui.IEditorInput)5 SimpleNode (org.python.pydev.parser.jython.SimpleNode)5 CoreException (org.eclipse.core.runtime.CoreException)4 RefactoringRequest (org.python.pydev.ast.refactoring.RefactoringRequest)4 IInterpreterManager (org.python.pydev.core.IInterpreterManager)4