Examples of ILocalScope


Examples of org.python.pydev.core.ILocalScope

            try {
                FindScopeVisitor scopeVisitor = new FindScopeVisitor(startLineIndexInASTCoords,
                        selection.getCursorColumn() + 1);
                module.accept(scopeVisitor);
                ILocalScope scope = scopeVisitor.scope;
                FastStack scopeStack = scope.getScopeStack();
                currentScope = (SimpleNode) scopeStack.peek(); //at least the module should be there if we don't have anything.
            } catch (Exception e1) {
                Log.log(e1);
            }
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

            log("internalGenerateGetCompletionsForModule", module, state);
        }

        ArrayList<IToken> importedModules = new ArrayList<IToken>();

        ILocalScope localScope = null;
        int line = state.getLine();
        int col = state.getCol();

        if (state.getLocalImportsGotten() == false) {
            //in the first analyzed module, we have to get the local imports too.
            state.setLocalImportsGotten(true);
            if (module != null && line >= 0) {
                localScope = module.getLocalScope(line, col);
                if (localScope != null) {
                    importedModules.addAll(localScope.getLocalImportedModules(line + 1, col + 1, module.getName()));
                }
            }
        }

        IToken[] builtinsCompletions = getBuiltinsCompletions(state);
        if (builtinsCompletions != null) {
            return builtinsCompletions;
        }

        String act = state.getActivationToken();
        int parI = act.indexOf('(');
        if (parI != -1) {
            state.setFullActivationToken(act);
            act = act.substring(0, parI);
            state.setActivationToken(act);
            state.setLookingFor(ICompletionState.LOOKING_FOR_INSTANCED_VARIABLE);
        }

        if (module != null) {

            //get the tokens (global, imported and wild imported)
            IToken[] globalTokens = module.getGlobalTokens();

            List<IToken> tokenImportedModules = Arrays.asList(module.getTokenImportedModules());
            importedModules.addAll(tokenImportedModules);
            state.setTokenImportedModules(importedModules);
            IToken[] wildImportedModules = module.getWildImportedModules();

            //now, lets check if this is actually a module that is an __init__ (if so, we have to get all
            //the other .py files as modules that are in the same level as the __init__)
            Set<IToken> initial = new HashSet<IToken>();
            if (searchSameLevelMods) {
                //now, we have to ask for the module if it's a 'package' (folders that have __init__.py for python
                //or only folders -- not classes -- in java).
                if (module.isPackage()) {
                    HashSet<IToken> gotten = new HashSet<IToken>();
                    //the module also decides how to get its submodules
                    getAbsoluteImportTokens(module.getPackageFolderName(), gotten, IToken.TYPE_IMPORT, true, null,
                            false);
                    for (IToken token : gotten) {
                        if (token.getRepresentation().equals("__init__") == false) {
                            initial.add(token);
                        }
                    }
                }
            }

            if (state.getActivationToken().length() == 0) {

                List<IToken> completions = getGlobalCompletions(globalTokens,
                        importedModules.toArray(EMPTY_ITOKEN_ARRAY), wildImportedModules, state, module);

                //now find the locals for the module
                if (line >= 0) {
                    IToken[] localTokens = module.getLocalTokens(line, col, localScope);
                    for (int i = 0; i < localTokens.length; i++) {
                        completions.add(localTokens[i]);
                    }
                }
                completions.addAll(initial); //just add all that are in the same level if it was an __init__

                return completions.toArray(EMPTY_ITOKEN_ARRAY);

            } else { //ok, we have a token, find it and get its completions.

                //first check if the token is a module... if it is, get the completions for that module.
                IToken[] tokens = findTokensOnImportedMods(importedModules.toArray(EMPTY_ITOKEN_ARRAY), state, module);
                if (tokens != null && tokens.length > 0) {
                    return decorateWithLocal(tokens, localScope, state);
                }

                //if it is an __init__, modules on the same level are treated as local tokens
                if (searchSameLevelMods) {
                    tokens = searchOnSameLevelMods(initial, state);
                    if (tokens != null && tokens.length > 0) {
                        return decorateWithLocal(tokens, localScope, state);
                    }
                }

                //for wild imports, we must get the global completions with __all__ filtered
                //wild imports: recursively go and get those completions and see if any matches it.
                for (int i = 0; i < wildImportedModules.length; i++) {

                    IToken name = wildImportedModules[i];
                    IModule mod = getModule(name.getAsRelativeImport(module.getName()), state.getNature(), false); //relative (for wild imports this is ok... only a module can be used in wild imports)

                    if (mod == null) {
                        mod = getModule(name.getOriginalRep(), state.getNature(), false); //absolute
                    }

                    if (mod != null) {
                        state.checkFindModuleCompletionsMemory(mod, state.getActivationToken());
                        IToken[] completionsForModule = getCompletionsForModule(mod, state);
                        if (completionsForModule.length > 0)
                            return decorateWithLocal(completionsForModule, localScope, state);
                    } else {
                        //"Module not found:" + name.getRepresentation()
                    }
                }

                //it was not a module (would have returned already), so, try to get the completions for a global token defined.
                tokens = module.getGlobalTokens(state, this);
                if (tokens.length > 0) {
                    return decorateWithLocal(tokens, localScope, state);
                }

                //If it was still not found, go to builtins.
                IModule builtinsMod = getBuiltinMod(state.getNature());
                if (builtinsMod != null && builtinsMod != module) {
                    tokens = getCompletionsForModule(builtinsMod, state);
                    if (tokens.length > 0) {
                        if (tokens[0].getRepresentation().equals("ERROR:") == false) {
                            return decorateWithLocal(tokens, localScope, state);
                        }
                    }
                }

                if (lookForArgumentCompletion && localScope != null) {

                    //now, if we have to look for arguments and search things in the local scope, let's also
                    //check for assert (isinstance...) in this scope with the given variable.
                    List<String> lookForClass = localScope.getPossibleClassesForActivationToken(state
                            .getActivationToken());
                    if (lookForClass.size() > 0) {
                        HashSet<IToken> hashSet = new HashSet<IToken>();

                        getCompletionsForClassInLocalScope(module, state, searchSameLevelMods,
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

                            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];
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

        String rep = NodeUtils.getRepresentationString(name);
        if (rep.equals(tokenToFind) && line == name.beginLine && col >= name.beginColumn
                && col <= name.beginColumn + rep.length()) {
            foundAsDefinition = true;
            // if it is found as a definition it is an 'exact' match, so, erase all the others.
            ILocalScope scope = new LocalScope(this.defsStack);
            for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) {
                Definition d = it.next();
                if (!d.scope.equals(scope)) {
                    it.remove();
                }
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

                String rep = NodeUtils.getRepresentationString(node);

                if (PySelection.isInside(col, node.beginColumn, rep.length())) {
                    foundAsDefinition = true;
                    // if it is found as a definition it is an 'exact' match, so, erase all the others.
                    ILocalScope scope = new LocalScope(this.defsStack);
                    for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) {
                        Definition d = it.next();
                        if (!d.scope.equals(scope)) {
                            it.remove();
                        }
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

        if (rep.equals(tokenToFind)
                && ((line == -1 && col == -1) || (line == name.beginLine && col >= name.beginColumn && col <= name.beginColumn
                        + rep.length()))) {
            foundAsDefinition = true;
            // if it is found as a definition it is an 'exact' match, so, erase all the others.
            ILocalScope scope = new LocalScope(this.defsStack);
            for (Iterator<Definition> it = definitions.iterator(); it.hasNext();) {
                Definition d = it.next();
                if (!d.scope.equals(scope)) {
                    it.remove();
                }
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

    /**
     * @see org.python.pydev.parser.jython.ast.VisitorBase#visitAssign(org.python.pydev.parser.jython.ast.Assign)
     */
    public Object visitAssign(Assign node) throws Exception {
        ILocalScope scope = new LocalScope(this.defsStack);
        if (foundAsDefinition && !scope.equals(definitionFound.scope)) { //if it is found as a definition it is an 'exact' match, so, we do not keep checking it
            return null;
        }

        for (int i = 0; i < node.targets.length; i++) {
            exprType target = node.targets[i];
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

                ast.accept(scopeVisitor);
            } catch (Exception e) {
                Log.log(e);
            }
        }
        ILocalScope localScope = scopeVisitor.scope;
        return localScope;
    }
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

                +
                "      pass\n" +
                "    \n" +
                "\n" +
                "";
        ILocalScope localScope = findLocalScope(s, 8, 3);
        assertTrue(localScope.getClassDef() != null);
    }
View Full Code Here

Examples of org.python.pydev.core.ILocalScope

    public void testFindAssertInLocalScope() throws Exception {
        String s = "def m1(a):\n" +
                "    assert isinstance(a, str)\n" +
                "    ";

        ILocalScope localScope = findLocalScope(s, 2, 1);
        List<String> found = localScope.getPossibleClassesForActivationToken("a");
        assertEquals(1, found.size());
        assertEquals("str", found.get(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.