Search in sources :

Example 1 with PyLinkedModeCompletionProposal

use of org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal in project Pydev by fabioz.

the class PythonCompletionWithoutBuiltinsTest method testReturn5.

public void testReturn5() throws Exception {
    String s = "import unittest\n" + "\n" + "\n" + "class Test(unittest.TestCase):\n" + "        \n" + "    def Compute(self):\n" + "        return Test()\n" + "\n" + "    def BB(self):\n" + "        self.Compute()." + "";
    ICompletionProposalHandle[] requestCompl = requestCompl(s, s.length(), -1, new String[] { "BB()", "assertEquals(first, second, msg)" });
    boolean found = false;
    for (ICompletionProposalHandle p : requestCompl) {
        if (p.getDisplayString().equals("assertEquals(first, second, msg)")) {
            IToken element = ((PyLinkedModeCompletionProposal) p).getElement();
            assertEquals(element.getType(), IToken.TYPE_FUNCTION);
            found = true;
        }
    }
    assertTrue(found);
}
Also used : IToken(org.python.pydev.core.IToken) ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) PyLinkedModeCompletionProposal(org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal)

Example 2 with PyLinkedModeCompletionProposal

use of org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal in project Pydev by fabioz.

the class PythonCompletionCalltipsTest method testCalltips8a.

public void testCalltips8a() throws Exception {
    String s0 = "class TestCase(object):\n" + "    def __init__(self, param1, param2):\n" + "        pass\n" + "    \n" + "TestCase(param1=10, para%s=20)";
    String s = StringUtils.format(s0, "m3");
    ICompletionProposalHandle[] proposals = requestCompl(s, s.length() - 7, -1, new String[] {});
    assertEquals(2, proposals.length);
    PyLinkedModeCompletionProposal paramProposal = (PyLinkedModeCompletionProposal) assertContains("param1=", proposals);
    paramProposal = (PyLinkedModeCompletionProposal) assertContains("param2=", proposals);
    Document document = new Document(s);
    // only the 'm3'
    paramProposal.setLen(2);
    paramProposal.applyOnDoc(paramProposal.getReplacementOffset() + 4, true, document, 4, '\0');
    assertEquals(StringUtils.format(s0, "m2"), document.get());
}
Also used : ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) Document(org.eclipse.jface.text.Document) PyLinkedModeCompletionProposal(org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal)

Example 3 with PyLinkedModeCompletionProposal

use of org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal in project Pydev by fabioz.

the class PythonApplyCompletionsTest method testApply3.

public void testApply3() throws Exception {
    String s = "class XX:\n" + "    def method1(self, a, b):\n" + "        return 1\n" + "    def foo(self):\n" + "        self.metho";
    int offset = s.length() - 1;
    ICompletionProposalHandle[] proposals = requestCompl(s, offset, -1, new String[] {});
    assertEquals(1, proposals.length);
    PyLinkedModeCompletionProposal p = (PyLinkedModeCompletionProposal) proposals[0];
    p.fLen = 1;
    Document d = new Document(s);
    p.applyOnDoc(offset, true, d, "meth".length(), '\n');
    // System.out.println(d.get());
    assertEquals(s + "d1", d.get());
    assertEquals(new Point(d.getLength(), 0), p.getSelection(d));
}
Also used : ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) Point(org.eclipse.swt.graphics.Point) Document(org.eclipse.jface.text.Document) Point(org.eclipse.swt.graphics.Point) PyLinkedModeCompletionProposal(org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal)

Example 4 with PyLinkedModeCompletionProposal

use of org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal in project Pydev by fabioz.

the class PythonApplyCompletionsTest method testApply6.

public void testApply6() throws Exception {
    String s = "class XX:\n" + "    def method1(self, a, b):\n" + "        return 1\n" + "    def foo(self):\n" + "        self.meth";
    int offset = s.length();
    ICompletionProposalHandle[] proposals = requestCompl(s, offset, -1, new String[] {});
    assertEquals(1, proposals.length);
    PyLinkedModeCompletionProposal p = (PyLinkedModeCompletionProposal) proposals[0];
    Document d = new Document(s);
    p.applyOnDoc(offset, false, d, 4, ')');
    // System.out.println(d.get());
    assertEquals(s + "od1(a, b)", d.get());
    assertEquals(new Point(d.getLength() - "a, b)".length(), 0), p.getSelection(d));
}
Also used : ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) Point(org.eclipse.swt.graphics.Point) Document(org.eclipse.jface.text.Document) Point(org.eclipse.swt.graphics.Point) PyLinkedModeCompletionProposal(org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal)

Example 5 with PyLinkedModeCompletionProposal

use of org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal in project Pydev by fabioz.

the class PythonApplyCompletionsTest method testApply5.

public void testApply5() throws Exception {
    String s = "class XX:\n" + "    def method1(self, a, b):\n" + "        return 1\n" + "    def foo(self):\n" + "        self.meth";
    int offset = s.length();
    ICompletionProposalHandle[] proposals = requestCompl(s, offset, -1, new String[] {});
    assertEquals(1, proposals.length);
    PyLinkedModeCompletionProposal p = (PyLinkedModeCompletionProposal) proposals[0];
    Document d = new Document(s);
    p.applyOnDoc(offset, false, d, 4, '(');
    // System.out.println(d.get());
    assertEquals(s + "od1()", d.get());
    assertEquals(new Point(d.getLength() - 1, 0), p.getSelection(d));
}
Also used : ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) Point(org.eclipse.swt.graphics.Point) Document(org.eclipse.jface.text.Document) Point(org.eclipse.swt.graphics.Point) PyLinkedModeCompletionProposal(org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal)

Aggregations

PyLinkedModeCompletionProposal (org.python.pydev.editor.codecompletion.proposals.PyLinkedModeCompletionProposal)9 ICompletionProposalHandle (org.python.pydev.shared_core.code_completion.ICompletionProposalHandle)8 Document (org.eclipse.jface.text.Document)7 Point (org.eclipse.swt.graphics.Point)6 Flake8Preferences (com.python.pydev.analysis.flake8.Flake8Preferences)1 MypyPreferences (com.python.pydev.analysis.mypy.MypyPreferences)1 PyLintPreferences (com.python.pydev.analysis.pylint.PyLintPreferences)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IPath (org.eclipse.core.runtime.IPath)1