Package org.python.pydev.core.docutils.PySelection

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


                return;
            }

            String initial = request.qualifier;

            DocIterator iterator = new DocIterator(false, ps);
            while (iterator.hasNext()) {
                String line = iterator.next().trim();
                if (line.startsWith("def ")) {
                    int currentLine = iterator.getCurrentLine() + 1;
                    PySelection selection = new PySelection(request.doc, currentLine, 0);
                    if (selection.isInFunctionLine(true)) {
                        Tuple<List<String>, Integer> insideParentesisToks = selection.getInsideParentesisToks(false);
                        for (String str : insideParentesisToks.o1) {
                            if (str.startsWith(initial)) {
View Full Code Here


            createFoldingEntries((ASTEntryWithChildren) entry, ret);
        }

        //and at last, get the comments
        if (prefs.getBoolean(PyDevCodeFoldingPrefPage.FOLD_COMMENTS)) {
            DocIterator it = new PySelection.DocIterator(true, new PySelection(doc, 0));
            while (it.hasNext()) {
                String string = it.next();
                if (string.trim().startsWith("#")) {
                    int l = it.getCurrentLine() - 1;
                    addFoldingEntry(ret, new FoldingEntry(FoldingEntry.TYPE_COMMENT, l, l + 1, new ASTEntry(null,
                            new commentType(string))));
                }
            }
        }
View Full Code Here

    }

    private List<stmtType> parse() {
        List<stmtType> body = new ArrayList<stmtType>();
        PySelection ps = new PySelection(doc);
        DocIterator it = new PySelection.DocIterator(forward, ps, currentLine, false);

        Matcher functionMatcher = FUNCTION_PATTERN.matcher("");
        List<Matcher> cythonMatchers = null;
        if (this.cythonParse) {
            cythonMatchers = new ArrayList<Matcher>();
            cythonMatchers.add(FUNCTION_PATTERN_CYTHON.matcher(""));
            cythonMatchers.add(FUNCTION_PATTERN_CYTHON2.matcher(""));
        }

        Matcher classMatcher = CLASS_PATTERN.matcher("");

        while (it.hasNext()) {
            Matcher functionFound = null;
            String line = it.next();

            //we don't care about empty lines
            if (line.trim().length() == 0) {
                continue;
            }

            if (findGloballyAccessiblePath) {
                int currentFirstCharCol = PySelection.getFirstCharPosition(line);
                if (firstCharCol == -1) {
                    firstCharCol = currentFirstCharCol;
                } else {
                    //We must validate if this is a line we can accept based on the initial indentation
                    //E.g.:
                    //
                    //def m1():
                    //    def m2():
                    //        pass
                    //    pass <- If we're here, m2() should not be considered when getting the path
                    //            to the global scope.
                    if (firstCharCol <= currentFirstCharCol) {
                        continue; // don't check this line as it's not valid in the current context.
                    }
                }
            }

            functionMatcher.reset(line);
            if (functionMatcher.find()) {
                functionFound = functionMatcher;
            } else if (cythonMatchers != null) {
                for (Matcher matcher : cythonMatchers) {
                    matcher.reset(line);
                    if (matcher.find()) {
                        functionFound = matcher;
                        break;
                    }
                }
            }

            if (functionFound != null) {
                int lastReturnedLine = it.getLastReturnedLine();
                NameTok nameTok = createNameTok(functionFound, lastReturnedLine, NameTok.FunctionName, ps);

                if (nameTok != null) {
                    FunctionDef functionDef = createFunctionDef(lastReturnedLine, nameTok,
                            PySelection.getFirstCharPosition(line));

                    if (!addStatement(body, functionDef)) {
                        return body;
                    }

                    if (stopOnFirstMatch) {
                        return body;
                    }
                }
                continue;
            }

            classMatcher.reset(line);

            if (classMatcher.find()) {
                int lastReturnedLine = it.getLastReturnedLine();

                NameTok nameTok = createNameTok(classMatcher, lastReturnedLine, NameTok.ClassName, ps);

                if (nameTok != null) {
                    ClassDef classDef = createClassDef(lastReturnedLine, nameTok,
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.