Examples of ICompletionState


Examples of org.python.pydev.core.ICompletionState

        String tok = o.o2;
        String tokForSearchInOtherModule = getTokToSearchInOtherModule(o);

        if (tok.length() == 0) {
            //the activation token corresponds to an imported module. We have to get its global tokens and return them.
            ICompletionState copy = state.getCopy();
            copy.setActivationToken("");
            copy.setBuiltinsGotten(true); //we don't want builtins...
            return getCompletionsForModule(mod, copy);
        } else if (mod != null) {
            ICompletionState copy = state.getCopy();
            copy.setActivationToken(tokForSearchInOtherModule);
            copy.setCol(-1);
            copy.setLine(-1);
            copy.raiseNFindTokensOnImportedModsCalled(mod, tokForSearchInOtherModule);

            String parentPackage = o.o3.getParentPackage();
            if (parentPackage.trim().length() > 0 && parentPackage.equals(current.getName())
                    && state.getActivationToken().equals(tok) && !parentPackage.endsWith("__init__")) {
                String name = mod.getName();
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

     */
    public static void findActualDefinition(IProgressMonitor monitor, IModule mod, String tok,
            ArrayList<IDefinition> selected, int beginLine, int beginCol, IPythonNature pythonNature,
            ICompletionCache completionCache) throws Exception, CompletionRecursionException {

        ICompletionState completionState = CompletionStateFactory.getEmptyCompletionState(tok, pythonNature,
                beginLine - 1, beginCol - 1, completionCache);
        IDefinition[] definitions = mod.findDefinition(completionState, beginLine, beginCol, pythonNature);

        if (monitor != null) {
            monitor.setTaskName("Found:" + definitions.length + " definitions");
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

     * @throws CompletionRecursionException
     */
    private IToken[] getValueCompletions(ICompletionState initialState, ICodeCompletionASTManager manager,
            String value, IModule module) throws CompletionRecursionException {
        initialState.checkFindMemory(this, value);
        ICompletionState copy = initialState.getCopy();
        copy.setActivationToken(value);
        IToken[] completionsForModule = manager.getCompletionsForModule(module, copy);
        return completionsForModule;
    }
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

        List<IToken> modToks = GlobalModelVisitor.getTokens(ast, GlobalModelVisitor.INNER_DEFS, name, initialState,
                false);//name = moduleName

        try {
            //COMPLETION: get the completions for the whole hierarchy if this is a class!!
            ICompletionState state;
            if (ast instanceof ClassDef) {
                ClassDef c = (ClassDef) ast;
                for (int j = 0; j < c.bases.length; j++) {
                    if (c.bases[j] instanceof Name) {
                        Name n = (Name) c.bases[j];
                        String base = n.id;
                        //An error in the programming might result in an error.
                        //
                        //e.g. The case below results in a loop.
                        //
                        //class A(B):
                        //   
                        //    def a(self):
                        //        pass
                        //       
                        //class B(A):
                        //   
                        //    def b(self):
                        //        pass
                        state = initialState.getCopy();
                        state.setActivationToken(base);

                        state.checkMemory(this, base);

                        final IToken[] comps = manager.getCompletionsForModule(this, state);
                        modToks.addAll(Arrays.asList(comps));
                    } else if (c.bases[j] instanceof Attribute) {
                        Attribute attr = (Attribute) c.bases[j];
                        String s = NodeUtils.getFullRepresentationString(attr);

                        state = initialState.getCopy();
                        state.setActivationToken(s);
                        final IToken[] comps = manager.getCompletionsForModule(this, state);
                        modToks.addAll(Arrays.asList(comps));
                    }
                }
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

                //class B:           
                //    def met2(self):
                //        c = C()    
                //        c.met1
                state.checkFindLocalDefinedDefinitionMemory(this, tokenRep);
                ICompletionState copyWithActTok = state.getCopyWithActTok(tokenRep);

                Definition[] definitions = this.findDefinition(copyWithActTok, tok.getLineDefinition(),
                        tok.getColDefinition(), nature, innerFindPaths);
                ArrayList<Definition> ret = new ArrayList<Definition>();
                for (Definition definition : definitions) {
                    if (definition.module != null) {
                        if (definition.value.length() == 0) {
                            continue;
                        }
                        String checkFor = definition.value + actTok.substring(tokenRepLen);
                        if (this.equals(definition.module)) {
                            //no point in finding the starting point
                            if (actTok.equals(definition.value)) {
                                continue;
                            }
                            if (checkFor.equals(actTok)) {
                                continue;
                            }
                            if (checkFor.startsWith(actTok + '.')) {
                                //This means that to find some symbol we have a construct such as:
                                //a = a.strip().rjust()
                                //So, if we look for a.strip, and we resolve a as a.strip.rjust, we'll try to find:
                                //a.strip.rjust.strip, in which case we'd recurse.
                                continue;
                            }
                        }

                        //Note: I couldn't really reproduce this case, so, this fix is just a theoretical
                        //workaround. Hopefully sometime someone will provide some code to reproduce this.
                        //see: http://sourceforge.net/tracker/?func=detail&aid=2992629&group_id=85796&atid=577329
                        int dotsFound = StringUtils.count(checkFor, '.');
                        if (dotsFound > 15) {
                            throw new CompletionRecursionException("Trying to go to deep to find definition.\n"
                                    + "We probably started entering a recursion.\n" + "Module: "
                                    + definition.module.getName() + "\n" + "Token: " + checkFor);
                        }

                        Definition[] realDefinitions;
                        if (definition.module instanceof SourceModule) {
                            SourceModule sourceModule = (SourceModule) definition.module;
                            realDefinitions = (Definition[]) sourceModule.findDefinition(
                                    state.getCopyWithActTok(checkFor), definition.line, definition.col, nature,
                                    innerFindPaths);

                        } else {
                            realDefinitions = (Definition[]) definition.module.findDefinition(
                                    state.getCopyWithActTok(checkFor), definition.line, definition.col, nature);

                        }
                        for (Definition realDefinition : realDefinitions) {
                            ret.add(realDefinition);
                        }
                    }
                }
                return ret.toArray(new Definition[ret.size()]);
            }
        }

        //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;

            } else if (o.o1 instanceof CompiledModule) {
                //ok, we have to check the compiled module
                tok = o.o2;
                if (tok == null || tok.length() == 0) {
                    return new Definition[] { new Definition(1, 1, "", null, null, o.o1) };
                } else {
                    state.checkFindDefinitionMemory(o.o1, tok);
                    return (Definition[]) o.o1.findDefinition(state.getCopyWithActTok(tok), -1, -1, nature);
                }

            } else if (o.o1 instanceof AbstractJavaClassModule) {
                tok = o.o2;
                state.checkFindDefinitionMemory(o.o1, tok);
                return (Definition[]) o.o1.findDefinition(state.getCopyWithActTok(tok), -1, -1, nature);

            } else {
                throw new RuntimeException("Unexpected module found in imports: " + o);
            }
        }

        //mod == this if we are now checking the globals (or maybe not)...heheheh
        ICompletionState copy = state.getCopy();
        copy.setActivationToken(tok);
        try {
            state.checkFindDefinitionMemory(mod, tok);
            findDefinitionsFromModAndTok(nature, toRet, visitor.moduleImported, mod, copy);
        } catch (CompletionRecursionException e) {
            //ignore (will return what we've got so far)
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

                                        //if fromImportStr == null, it's not a from xxx import yyy (i.e.: simple import)
                                        foundFromImportStr = imported;
                                    }
                                    try {
                                        String currentModule = nature.resolveModule(edit.getEditorFile());
                                        ICompletionState state = CompletionStateFactory.getEmptyCompletionState(nature,
                                                new CompletionCache());

                                        found = nature.getAstManager().findModule(
                                                foundFromImportStr,
                                                currentModule,
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

        }

        IDocument doc = new Document(strDoc);
        CompletionRequest request = new CompletionRequest(file, nature, doc, documentOffset, codeCompletion);

        ICompletionState state = CompletionStateFactory.getEmptyCompletionState(nature, new CompletionCache());
        state.setTokenImportedModules(imports);
        List<Object> props = new ArrayList<Object>(participant.getGlobalCompletions(request, state));
        ICompletionProposal[] codeCompletionProposals = PyCodeCompletionUtils.onlyValidSorted(props, request.qualifier,
                request.isInCalltip);

        for (int i = 0; i < retCompl.length; i++) {
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

        } catch (MisconfigurationException e1) {
            throw new RuntimeException(e1);
        }

        for (String baseName : importedBase) {
            ICompletionState state = new CompletionState(-1, -1, baseName, nature, "", completionCache);
            IToken[] ret = null;
            try {
                ret = nature.getAstManager().getCompletionsForModule(module, state);
            } catch (CompletionRecursionException e) {
                throw new RuntimeException(e);
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

    // pre-init the builtin completions for the python natures so that users
    // don't have to wait on this on the first save
    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>());
View Full Code Here

Examples of org.python.pydev.core.ICompletionState

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