Package org.python.pydev.core.docutils

Examples of org.python.pydev.core.docutils.PySelection$DocIterator


                return;
            }

            PyEdit pyEdit = getPyEdit();

            PySelection ps = new PySelection(pyEdit);
            String endLineDelim = ps.getEndLineDelim();
            final IDocument doc = ps.getDoc();
            DocumentRewriteSession session = null;

            try {
                if (ps.getStartLineIndex() == ps.getEndLineIndex()) {
                    //let's see if someone wants to make a better implementation in another plugin...
                    List<IOrganizeImports> participants = ExtensionHelper
                            .getParticipants(ExtensionHelper.PYDEV_ORGANIZE_IMPORTS);

                    for (IOrganizeImports organizeImports : participants) {
                        if (!organizeImports.beforePerformArrangeImports(ps, pyEdit)) {
                            return;
                        }
                    }

                    session = startWrite(doc);

                    performArrangeImports(doc, endLineDelim, pyEdit.getIndentPrefs().getIndentationString());

                    for (IOrganizeImports organizeImports : participants) {
                        organizeImports.afterPerformArrangeImports(ps, pyEdit);
                    }
                } else {
                    session = startWrite(doc);
                    performSimpleSort(doc, endLineDelim, ps.getStartLineIndex(), ps.getEndLineIndex());
                }
            } finally {
                if (session != null) {
                    endWrite(doc, session);
                }
View Full Code Here


            if (!canModifyEditor()) {
                return;
            }

            // Select from text editor
            PySelection ps = new PySelection(getTextEditor());

            // Put cursor at the first area of the selection
            getTextEditor().selectAndReveal(perform(ps), 0);
        } catch (Exception e) {
            beep(e);
View Full Code Here

     * Checks preconditions... if
     */
    public void run(final IAction action) {
        // Select from text editor
        request = null; //clear the cache from previous runs
        ps = new PySelection(getTextEditor());

        RefactoringRequest req;
        try {
            req = getRefactoringRequest();
        } catch (MisconfigurationException e2) {
View Full Code Here

    public void testShiftLeft1() throws Exception {
        Document doc = new Document("    def a(aa):\n" +
                "        pass\n" +
                "    \n");
        PySelection ps = new PySelection(doc, 0, 0, doc.getLength());
        new PyShiftLeft().perform(ps, new TestIndentPrefs(true, 4));

        String expected = "def a(aa):\n" +
                "    pass\n" +
                "\n";
View Full Code Here

    public void testShiftLeft2() throws Exception {
        Document doc = new Document("   def a(aa):\n" +
                "        pass\n" +
                "    \n");
        PySelection ps = new PySelection(doc, 0, 0, doc.getLength());
        new PyShiftLeft().perform(ps, new TestIndentPrefs(true, 4));

        String expected = "def a(aa):\n" +
                "     pass\n" +
                " \n";
View Full Code Here

    public void testShiftLeft3() throws Exception {
        Document doc = new Document("   def a(aa):\n" +
                "        pass\n" +
                "    bb\n");
        PySelection ps = new PySelection(doc, 0, 3, doc.getLength() - 2 - 3);
        new PyShiftLeft().perform(ps, new TestIndentPrefs(true, 4));

        String expected = "def a(aa):\n" +
                "     pass\n" +
                " bb\n";
View Full Code Here

                try {
                    TddPossibleMatches possibleMatch = entry.getValue();
                    String callWithoutParens = entry.getKey();

                    ItemPointer[] pointers = null;
                    PySelection callPs = null;
                    TddPossibleMatches lastPossibleMatchNotFound = possibleMatch;
                    String lastCallWithoutParensNotFound = callWithoutParens;

                    for (int i = 0; i < 10; i++) { //more than 10 attribute accesses in a line? No way!

                        lastPossibleMatchNotFound = possibleMatch;
                        lastCallWithoutParensNotFound = callWithoutParens;
                        if (i > 0) {
                            //We have to take 1 level out of the match... i.e.: if it was self.foo.get(), search now for self.foo.
                            String line = FullRepIterable.getWithoutLastPart(possibleMatch.full);
                            List<TddPossibleMatches> tddPossibleMatchesAtLine = ps.getTddPossibleMatchesAtLine(line);
                            if (tddPossibleMatchesAtLine.size() > 0) {
                                possibleMatch = tddPossibleMatchesAtLine.get(0);
                                callWithoutParens = possibleMatch.initialPart + possibleMatch.secondPart;
                            } else {
                                continue CONTINUE_FOR;
                            }
                        }
                        String full = possibleMatch.full;
                        int indexOf = lineContents.indexOf(full);
                        if (indexOf < 0) {
                            Log.log("Did not expect index < 0.");
                            continue CONTINUE_FOR;
                        }
                        callPs = new PySelection(ps.getDoc(), ps.getLineOffset() + indexOf + callWithoutParens.length());

                        RefactoringRequest request = new RefactoringRequest(f, callPs, null, nature, edit);
                        //Don't look in additional info.
                        request.setAdditionalInfo(
                                AstEntryRefactorerRequestConstants.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
                        pointers = pyRefactoring.findDefinition(request);

                        if (((pointers != null && pointers.length > 0) || StringUtils.count(possibleMatch.full, '.') <= 1)) {
                            break;
                        }
                    }

                    if (pointers == null || callPs == null) {
                        continue CONTINUE_FOR;
                    }

                    if (lastPossibleMatchNotFound != null && lastPossibleMatchNotFound != possibleMatch
                            && pointers.length >= 1) {
                        //Ok, as we were analyzing a string as self.bar.foo, we didn't find something in a pass
                        //i.e.: self.bar.foo, but we found it in a second pass
                        //as self.bar, so, this means we have to open the chance to create the 'foo' in self.bar.
                        String methodToCreate = FullRepIterable.getLastPart(lastPossibleMatchNotFound.secondPart);
                        int absoluteCursorOffset = callPs.getAbsoluteCursorOffset();
                        absoluteCursorOffset = absoluteCursorOffset - (1 + methodToCreate.length()); //+1 for the dot removed too.
                        PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset);

                        checkCreationBasedOnFoundPointers(edit, callPs, ret, possibleMatch, pointers, methodToCreate,
                                newSelection, nature);
                        continue CONTINUE_FOR;
                    }
View Full Code Here

                return true;
            }

            int absoluteCursorOffset = callPs.getAbsoluteCursorOffset();
            absoluteCursorOffset = absoluteCursorOffset - (1 + methodToCreate.length()); //+1 for the dot removed too.
            PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset);
            request = new RefactoringRequest(f, newSelection, null, nature, edit);
            //Don't look in additional info.
            request.setAdditionalInfo(AstEntryRefactorerRequestConstants.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
            pointers = pyRefactoring.findDefinition(request);
            if (pointers.length == 1) {
View Full Code Here

    }

    public void testUncommentBlock() throws Exception {
        doc = new Document("#a\n" +
                "#b");
        ps = new PySelection(doc, 0, 0, 0);
        new PyRemoveBlockComment().perform(ps);

        expected = "a\n" +
                "b";
        assertEquals(expected, doc.get());

        doc = new Document("#----\n" +
                "#a\n" +
                "#b\n" +
                "#----");
        ps = new PySelection(doc, 0, 0, 0);
        new PyRemoveBlockComment().perform(ps);

        expected = "a\n" +
                "b\n";
        assertEquals(expected, doc.get());
View Full Code Here

    public void test2() throws Exception {

        doc = new Document("#---- aa\n" +
                "#---- b\n" +
                "#---- c");
        ps = new PySelection(doc, 0, 0, 0);
        new PyRemoveBlockComment().perform(ps);

        expected = "aa\n" +
                "b\n" +
                "c";
View Full Code Here

TOP

Related Classes of org.python.pydev.core.docutils.PySelection$DocIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.