Package org.python.pydev.core

Examples of org.python.pydev.core.IModule


        if (lookInGlobals) {
            state.setActivationToken(initialActivationToken);

            //Ok, looking for a token in globals.
            IModule module = request.getModule();
            if (module != null) {
                IToken[] comps = astManager.getCompletionsForModule(module, state, true, true);
                for (int i = 0; i < comps.length; i++) {
                    tokensList.add(comps[i]);
                }
View Full Code Here


     */
    @SuppressWarnings("unchecked")
    public static boolean getSelfOrClsCompletions(CompletionRequest request, List theList, ICompletionState state,
            boolean getOnlySupers, boolean checkIfInCorrectScope, String lookForRep) throws MisconfigurationException {

        IModule module = request.getModule();
        SimpleNode s = null;
        if (module instanceof SourceModule) {
            SourceModule sourceModule = (SourceModule) module;
            s = sourceModule.getAst();
        }
View Full Code Here

                            Name n = (Name) d.bases[i];
                            state.setActivationToken(n.id);
                            IToken[] completions;
                            try {
                                ICodeCompletionASTManager astManager = request.nature.getAstManager();
                                IModule module = request.getModule();
                                if (module != null) {
                                    completions = astManager.getCompletionsForModule(module, state, true, true);
                                    for (int j = 0; j < completions.length; j++) {
                                        theList.add(completions[j]);
                                    }
                                }
                            } catch (CompletionRecursionException e) {
                                //ok...
                            }
                        }
                    }
                } else {
                    //ok, get the completions for the class, only thing we have to take care now is that we may
                    //not have only 'self' for completion, but something like self.foo.
                    //so, let's analyze our activation token to see what should we do.

                    String trimmed = request.activationToken.replace('.', ' ').trim();
                    String[] actTokStrs = trimmed.split(" ");
                    if (actTokStrs.length == 0 || (!actTokStrs[0].equals("self") && !actTokStrs[0].equals("cls"))) {
                        throw new AssertionError(
                                "We need to have at least one token (self or cls) for doing completions in the class.");
                    }

                    if (actTokStrs.length == 1) {
                        //ok, it's just really self, let's get on to get the completions
                        state.setActivationToken(NodeUtils.getNameFromNameTok((NameTok) d.name));
                        try {
                            ICodeCompletionASTManager astManager = request.nature.getAstManager();
                            IModule module = request.getModule();
                            IToken[] completions = astManager.getCompletionsForModule(module, state, true, true);
                            for (int j = 0; j < completions.length; j++) {
                                theList.add(completions[j]);
                            }
                        } catch (CompletionRecursionException e) {
                            //ok
                        }

                    } else {
                        //it's not only self, so, first we have to get the definition of the token
                        //the first one is self, so, just discard it, and go on, token by token to know what is the last
                        //one we are completing (e.g.: self.foo.bar)
                        int line = request.doc.getLineOfOffset(request.documentOffset);
                        IRegion region = request.doc.getLineInformationOfOffset(request.documentOffset);
                        int col = request.documentOffset - region.getOffset();

                        //ok, try our best shot at getting the module name of the current buffer used in the request.
                        IModule module = request.getModule();

                        AbstractASTManager astMan = ((AbstractASTManager) request.nature.getAstManager());
                        theList.addAll(new AssignAnalysis().getAssignCompletions(astMan, module, new CompletionState(
                                line, col, request.activationToken, request.nature, request.qualifier)).completions);
                    }
View Full Code Here

                    //ok, we found it
                    SimpleNode a = ((SourceToken) token).getAst();
                    Tuple<Integer, Integer> def = getLineColForDefinition(a);

                    String parentPackage = token.getParentPackage();
                    IModule module = this;
                    if (nature != null) {
                        IModule mod = nature.getAstManager().getModule(parentPackage, nature, true);
                        if (mod != null) {
                            module = mod;
                        }
                    }

                    if (module instanceof SourceModule) {
                        //this is just to get its scope...
                        SourceModule m = (SourceModule) module;
                        FindScopeVisitor scopeVisitor = m.getScopeVisitor(a.beginLine, a.beginColumn);
                        return new Definition(def.o1, def.o2, rep, a, scopeVisitor.scope, module);
                    } else {
                        //line, col
                        return new Definition(def.o1, def.o2, rep, a, new LocalScope(new FastStack<SimpleNode>(5)),
                                module);
                    }
                } else if (token instanceof ConcreteToken) {
                    //a contrete token represents a module
                    String modName = token.getParentPackage();
                    if (modName.length() > 0) {
                        modName += ".";
                    }
                    modName += token.getRepresentation();
                    IModule module = nature.getAstManager().getModule(modName, nature, true);
                    if (module == null) {
                        return null;
                    } else {
                        return new Definition(0 + 1, 0 + 1, "", null, null, module); // it is the module itself
                    }

                } else if (token instanceof CompiledToken) {
                    String parentPackage = token.getParentPackage();
                    FullRepIterable iterable = new FullRepIterable(parentPackage, true);

                    IModule module = null;
                    for (String modName : iterable) {
                        module = nature.getAstManager().getModule(modName, nature, true);
                        if (module != null) {
                            break;
                        }
                    }
                    if (module == null) {
                        return null;
                    }

                    int length = module.getName().length();
                    String finalRep = "";
                    if (parentPackage.length() > length) {
                        finalRep = parentPackage.substring(length + 1) + '.';
                    }
                    finalRep += token.getRepresentation();

                    try {
                        IDefinition[] definitions = module.findDefinition(state.getCopyWithActTok(finalRep), -1, -1,
                                nature);
                        if (definitions.length > 0) {
                            return (Definition) definitions[0];
                        }
                    } catch (Exception e) {
View Full Code Here

        //try to see if that's a java class from a package... to do that, we must go iterating through the name found
        //to check if we're able to find modules with that name. If a module with that name is found, that means that
        //we actually have a java class.
        List<String> splitted = StringUtils.dotSplit(state.getActivationToken());
        FastStringBuffer modNameBuf = new FastStringBuffer(this.getName(), 128);
        IModule validModule = null;
        IModule module = null;
        int i = 0; //so that we know what will result in the tok
        for (String s : splitted) {
            modNameBuf.append(".");
            modNameBuf.append(s);
            module = nature.getAstManager().getModule(modNameBuf.toString(), nature, true, false);
View Full Code Here

                return; //may happen if the return we're seeing is a return without anything
            }
            copy.setActivationToken(act);
            copy.setLine(return1.value.beginLine - 1);
            copy.setCol(return1.value.beginColumn - 1);
            IModule module = definition.module;

            state.checkDefinitionMemory(module, definition);

            IToken[] tks = manager.getCompletionsForModule(module, copy);
            if (tks.length > 0) {
View Full Code Here

     * @param assignDefinition may be null if it was not actually found as an assign
     */
    private void addNonFunctionDefCompletionsFromAssign(ICodeCompletionASTManager manager, ICompletionState state,
            ArrayList<IToken> ret, SourceModule sourceModule, Definition definition, AssignDefinition assignDefinition)
            throws CompletionRecursionException {
        IModule module;
        if (definition.ast instanceof ClassDef) {
            state.setLookingFor(ICompletionState.LOOKING_FOR_UNBOUND_VARIABLE);
            ret.addAll(((SourceModule) definition.module).getClassToks(state, manager, definition.ast));

        } else {
View Full Code Here

        return super.getModule(name, nature, dontSearchInit);
    }

    public Tuple<IModule, IModulesManager> getModuleAndRelatedModulesManager(String name, IPythonNature nature,
            boolean checkSystemManager, boolean dontSearchInit) {
        IModule module = this.getModule(name, nature, checkSystemManager, dontSearchInit);
        if (module != null) {
            return new Tuple<IModule, IModulesManager>(module, this);
        }
        return null;
    }
View Full Code Here

        }

        IToken[] toks = this.builtinCompletions.get(projectInterpreterName);

        if (toks == null || toks.length == 0) {
            IModule builtMod = getBuiltinMod(projectInterpreterName);
            if (builtMod != null) {
                toks = builtMod.getGlobalTokens();
                this.builtinCompletions.put(projectInterpreterName, toks);
            }
        }
        return this.builtinCompletions.get(projectInterpreterName);
    }
View Full Code Here

        //Cache with the internal name.
        projectInterpreterName = getInternalName(projectInterpreterName);
        if (projectInterpreterName == null) {
            return null;
        }
        IModule mod = builtinMod.get(projectInterpreterName);
        if (mod != null) {
            return mod;
        }

        try {
View Full Code Here

TOP

Related Classes of org.python.pydev.core.IModule

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.