Examples of ImportInfo


Examples of org.python.pydev.core.ICodeCompletionASTManager.ImportInfo

    IPyCodeCompletion completion;

    public void doTest(String s, String expected) {
        Document doc = new Document(s);
        int length = s.length();
        ImportInfo importsTipperStr = ImportsSelection.getImportsTipperStr(doc, length);
        String tipperStr = importsTipperStr.importsTipperStr;
        assertEquals(expected, tipperStr);
        if (tipperStr.length() > 0) {
            assertEquals(s.indexOf("from") != -1, importsTipperStr.hasFromSubstring);
            assertEquals(s.indexOf("import") != -1, importsTipperStr.hasImportSubstring);
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager.ImportInfo

    public static ImportInfo getImportsTipperStr(String trimmedLine, boolean returnEvenEmpty) {
        String importMsg = "";

        if (!trimmedLine.startsWith("from") && !trimmedLine.startsWith("import")) {

            return new ImportInfo("", false, false); // it is not an import
        }

        int fromIndex = trimmedLine.indexOf("from");
        int importIndex = trimmedLine.indexOf("import");
        boolean foundImportOnArray = false;
        boolean foundFromOnArray = false;

        // check if we have a from or an import.
        if (fromIndex != -1 || importIndex != -1) {
            trimmedLine = trimmedLine.replaceAll("#.*", ""); // remove comments
            String[] strings = trimmedLine.split(" ");

            if (fromIndex != -1 && importIndex == -1) {
                if (strings.length > 2) {
                    // user has spaces as in 'from xxx uuu'
                    return new ImportInfo("", foundImportOnArray, foundFromOnArray);
                }
            }

            for (int i = 0; i < strings.length; i++) {
                if (strings[i].equals("import")) {
                    foundImportOnArray = true;
                }
                if (strings[i].equals("from")) {
                    foundFromOnArray = true;
                }

                if (strings[i].equals("from") == false && strings[i].equals("import") == false) {
                    if (importMsg.length() != 0) {
                        importMsg += '.';
                    }
                    importMsg += strings[i];
                }
                // now, if we have a from xxx import something, we'll always
                // want to return only the xxx
                if (fromIndex != -1 && importIndex == -1 && (foundImportOnArray || i == strings.length - 1)) {
                    if (importMsg.length() == 0) {
                        return ImportsSelection.doExistingOrEmptyReturn(returnEvenEmpty, importMsg, foundImportOnArray,
                                foundFromOnArray);
                    }
                    if (importMsg.startsWith(".")) {
                        return new ImportInfo(importMsg, foundImportOnArray, foundFromOnArray);
                    }
                    if (importMsg.indexOf(".") == -1) {
                        return ImportsSelection.doExistingOrEmptyReturn(returnEvenEmpty, importMsg, foundImportOnArray,
                                foundFromOnArray);
                    }
                    return new ImportInfo(importMsg.substring(0, importMsg.lastIndexOf(".") + 1), foundImportOnArray,
                            foundFromOnArray);

                }
            }

            if (fromIndex != -1 && importIndex != -1) {
                if (strings.length == 3) {
                    importMsg += '.';
                }
            }
        } else {
            return new ImportInfo("", foundImportOnArray, foundFromOnArray);
        }
        if (importMsg.indexOf(".") == -1) {
            // we have only import fff or from iii (so, we're going for all
            // imports).
            return ImportsSelection.doExistingOrEmptyReturn(returnEvenEmpty, importMsg, foundImportOnArray,
                    foundFromOnArray);
        }

        if (fromIndex == -1 && importMsg.indexOf(',') != -1) {
            // we have something like import xxx, yyy, ...
            importMsg = importMsg.substring(importMsg.lastIndexOf(',') + 1, importMsg.length());
            if (importMsg.startsWith(".")) {
                importMsg = importMsg.substring(1);
            }

            int j = importMsg.lastIndexOf('.');
            if (j != -1) {
                importMsg = importMsg.substring(0, j);
                return new ImportInfo(importMsg, foundImportOnArray, foundFromOnArray);
            } else {
                return ImportsSelection.doExistingOrEmptyReturn(returnEvenEmpty, importMsg, foundImportOnArray,
                        foundFromOnArray);
            }

        } else {
            // now, we may still have something like 'unittest.test,' or
            // 'unittest.test.,'
            // so, we have to remove this comma (s).
            int i;
            boolean removed = false;
            while ((i = importMsg.indexOf(',')) != -1) {
                if (importMsg.charAt(i - 1) == '.') {
                    int j = importMsg.lastIndexOf('.');
                    importMsg = importMsg.substring(0, j);
                }

                int j = importMsg.lastIndexOf('.');
                importMsg = importMsg.substring(0, j);
                removed = true;
            }

            // if it is something like aaa.sss.bb : removes the bb because it is
            // the qualifier
            // if it is something like aaa.sss. : removes only the last point
            if (!removed && importMsg.length() > 0 && importMsg.indexOf('.') != -1) {
                importMsg = importMsg.substring(0, importMsg.lastIndexOf('.'));
            }

            return new ImportInfo(importMsg, foundImportOnArray, foundFromOnArray);
        }
    }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager.ImportInfo

                buffer.insert(0, line);
            }
        }

        if (!found) {
            return new ImportInfo("", false, false); // it is not an import
        }

        return getImportsTipperStr(buffer.toString(), true);
    }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager.ImportInfo

    }

    private static ImportInfo doExistingOrEmptyReturn(final boolean returnEvenEmpty, final String importMsg,
            final boolean foundImportOnArray, final boolean foundFromOnArray) {
        if (returnEvenEmpty || importMsg.trim().length() > 0) {
            return new ImportInfo(" ", foundImportOnArray, foundFromOnArray);
        } else {
            return new ImportInfo("", foundImportOnArray, foundFromOnArray);
        }
    }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager.ImportInfo

                }

                if (firstNonCommentLine == -1) {
                    firstNonCommentLine = line;
                }
                ImportInfo importInfo = ImportsSelection.getImportsTipperStr(str, false);
                //Don't check with trim (importInfo.importsTipperStr.trim().length()) because the string
                //will be " " in an import without a 'from'
                if (importInfo != null && importInfo.importsTipperStr != null
                        && importInfo.importsTipperStr.length() > 0) {
                    if ((i = str.indexOf('(')) != -1) {
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager.ImportInfo

        final String text = commandLine.substring(0, position);
        ActivationTokenAndQual tokenAndQual = PySelection.getActivationTokenAndQual(new Document(text), text.length(),
                true, false);

        //Code-completion for imports
        ImportInfo importsTipper = ImportsSelection.getImportsTipperStr(text, false);
        if (importsTipper.importsTipperStr.length() != 0) {
            importsTipper.importsTipperStr = importsTipper.importsTipperStr.trim();
            Set<IToken> tokens = new TreeSet<IToken>();
            boolean onlyGetDirectModules = false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.