Examples of ICodeCompletionASTManager


Examples of org.python.pydev.core.ICodeCompletionASTManager

            return false;
        }
        IProject project = resource.getProject();
        PythonNature nature = PythonNature.getPythonNature(project);
        if (project != null && nature != null) {
            ICodeCompletionASTManager astManager = nature.getAstManager();
            if (astManager != null) {
                IModulesManager modulesManager = astManager.getModulesManager();
                return modulesManager.isInPythonPath(resource, project);
            }
        }

        return false;
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

            }
        }

        //not found... check as local imports
        List<IToken> localImportedModules = scopeVisitor.scope.getLocalImportedModules(line, col, this.name);
        ICodeCompletionASTManager astManager = nature.getAstManager();
        int lenImportedModules = localImportedModules.size();
        for (int i = 0; i < lenImportedModules; i++) {
            IToken tok = localImportedModules.get(i);
            String importRep = tok.getRepresentation();
            if (importRep.equals(actTok) || actTok.startsWith(importRep + ".")) {
                Tuple3<IModule, String, IToken> o = astManager.findOnImportedMods(new IToken[] { tok },
                        state.getCopyWithActTok(actTok), this.getName(), this);
                if (o != null && o.o1 instanceof SourceModule) {
                    ICompletionState copy = state.getCopy();
                    copy.setActivationToken(o.o2);

                    findDefinitionsFromModAndTok(nature, toRet, null, (SourceModule) o.o1, copy);
                }
                if (toRet.size() > 0) {
                    return (Definition[]) toRet.toArray(new Definition[0]);
                }
            }
        }

        //ok, not assign nor import, let's check if it is some self (we do not check for only 'self' because that would map to a
        //local (which has already been covered).
        if (actTok.startsWith("self.")) {
            //ok, it is some self, now, that is only valid if we are in some class definition
            ClassDef classDef = (ClassDef) scopeVisitor.scope.getClassDef();
            if (classDef != null) {
                //ok, we are in a class, so, let's get the self completions
                String classRep = NodeUtils.getRepresentationString(classDef);
                IToken[] globalTokens = getGlobalTokens(new CompletionState(line - 1, col - 1, classRep, nature, "",
                        state), //use the old state as the cache
                        astManager);

                String withoutSelf = actTok.substring(5);
                for (IToken token : globalTokens) {
                    if (token.getRepresentation().equals(withoutSelf)) {
                        String parentPackage = token.getParentPackage();
                        IModule module = astManager.getModule(parentPackage, nature, true);

                        if (token instanceof SourceToken
                                && (module != null || this.name == null || this.name.equals(parentPackage))) {
                            if (module == null) {
                                module = this;
                            }

                            SimpleNode ast2 = ((SourceToken) token).getAst();
                            Tuple<Integer, Integer> def = getLineColForDefinition(ast2);
                            FastStack<SimpleNode> stack = new FastStack<SimpleNode>(5);
                            if (module instanceof SourceModule) {
                                stack.push(((SourceModule) module).getAst());
                            }
                            stack.push(classDef);
                            ILocalScope scope = new LocalScope(stack);
                            return new Definition[] { new Definition(def.o1, def.o2, token.getRepresentation(), ast2,
                                    scope, module) };

                        } else {
                            return new Definition[0];
                        }
                    }
                }
            }
        }

        //ok, it is not an assign, so, let's search the global tokens (and imports)
        String tok = actTok;
        SourceModule mod = this;

        Tuple3<IModule, String, IToken> o = astManager.findOnImportedMods(state.getCopyWithActTok(actTok), this);

        if (o != null) {
            if (o.o1 instanceof SourceModule) {
                mod = (SourceModule) o.o1;
                tok = o.o2;
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            PythonNature nature = PythonNature.getPythonNature(projectHandle);
            Assert.isNotNull(nature);
            ICodeCompletionASTManager astManager = nature.getAstManager();
            Object sync = new Object();
            //Wait up to 10 seconds for it to be restored
            for (int i = 0; i < 100 && astManager == null; i++) {
                synchronized (sync) {
                    try {
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

            throws BadLocationException, CoreException {
        if (nature == null) {
            return;
        }

        ICodeCompletionASTManager astManager = nature.getAstManager();
        if (astManager == null) {
            return;
        }

        if (markerAnnotation.position == null) {
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

    public List<String> getGlobalVariableNames() {
        List<String> globalNames = new ArrayList<String>();
        if (this.sourceModule != null && nature != null) {
            try {
                ICodeCompletionASTManager astManager = nature.getAstManager();
                if (astManager != null) {
                    IToken[] tokens = astManager.getCompletionsForModule(this.sourceModule, new CompletionState(-1, -1,
                            "", nature, ""));
                    for (IToken token : tokens) {
                        globalNames.add(token.getRepresentation());
                    }
                }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

                String lookForInterface = tokenAndQual[1];
                List<IInfo> tokensEqualTo;
                try {
                    tokensEqualTo = AdditionalProjectInterpreterInfo.getTokensEqualTo(lookForInterface, request.nature,
                            AbstractAdditionalTokensInfo.TOP_LEVEL | AbstractAdditionalTokensInfo.INNER);
                    ICodeCompletionASTManager manager = request.nature.getAstManager();
                    if (manager == null) {
                        return new ItemPointer[0];
                    }
                    if (tokensEqualTo.size() > 50) {
                        //too many matches for that...
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

            return NodeUtils.getNodeDocString(this.ast);
        } else {
            if (this.value == null || this.value.trim().length() == 0) {
                return this.module.getDocString();
            } else if (nature != null) {
                ICodeCompletionASTManager manager = nature.getAstManager();
                //It's the identification for some token in a module, let's try to find it
                String[] headAndTail = FullRepIterable.headAndTail(value);
                String actToken = headAndTail[0];
                String qualifier = headAndTail[1];
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

    List<IPythonNature> natures = PythonNature.getAllPythonNatures();
    logger.debug("pre-loading python builtin completions...");
    for (IPythonNature nature : natures){
      ICompletionState completionState = CompletionStateFactory
        .getEmptyCompletionState(nature, new CompletionCache());
      ICodeCompletionASTManager manager = nature.getAstManager();
      if (manager != null){
        // this is the part that takes some time to complete
        manager.getBuiltinCompletions(completionState, new ArrayList<IToken>());
      }
    }
    logger.debug("finished loading python builtin completions.");
  }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

        String file = TestDependent.TEST_PYSRC_LOC +
                "testrec3/rec.py";
        String strDoc = "RuntimeError.";
        File f = new File(file);
        try {
            ICodeCompletionASTManager astManager = nature.getAstManager();
            ICompletionState state = CompletionStateFactory.getEmptyCompletionState("RuntimeError", nature,
                    new CompletionCache());
            IModule module = AbstractASTManager.createModule(f, new Document(FileUtils.getFileContents(f)), nature);
            astManager.getCompletionsForModule(module, state, true, true);
        } catch (CompletionRecursionException e) {
            //that's ok... we're asking for it here...
        }
        requestCompl(f, strDoc, strDoc.length(), -1, new String[] { "__doc__", "__getitem__()", "__init__()",
                "__str__()" });
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

        sDoc = "" + "from testrec.imp1 import * \n" + "                           \n";

        IToken[] comps = null;
        Document doc = new Document(sDoc);
        ICompletionState state = new CompletionState(line, col, token, nature, "");
        ICodeCompletionASTManager a = (ICodeCompletionASTManager) nature.getAstManager();
        comps = a.getCompletionsForToken(doc, state);
        assertFalse(comps.length == 0);

    }
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.