Package org.python.pydev.core

Examples of org.python.pydev.core.IModule


     * @return a tuple with the IModule requested and the IModulesManager that contained that module.
     */
    public Tuple<IModule, IModulesManager> getModuleAndRelatedModulesManager(String name, IPythonNature nature,
            boolean checkSystemManager, boolean dontSearchInit) {

        IModule module = null;

        IModulesManager[] managersInvolved = this.getManagersInvolved(true); //only get the system manager here (to avoid recursion)

        for (IModulesManager m : managersInvolved) {
            if (m instanceof ISystemModulesManager) {
View Full Code Here


            }
            File f = new File(fPath);
            String foundModName = nature.resolveModule(f);
            String foundAs = def.o1[1];

            IModule mod;
            if (foundModName == null) {
                //this can happen in a case where we have a definition that's found from a compiled file which actually
                //maps to a file that's outside of the pythonpath known by Pydev.
                String n = FullRepIterable.getFirstPart(f.getName());
                mod = AbstractModule.createModule(n, f, nature, true);
            } else {
                mod = nature.getAstManager().getModule(foundModName, nature, true);
            }

            if (TRACE_COMPILED_MODULES) {
                System.out.println("CompiledModule.findDefinition: found at:" + mod.getName());
            }
            int foundLine = def.o2[0];
            if (foundLine == 0 && foundAs != null && foundAs.length() > 0 && mod != null
                    && state.canStillCheckFindSourceFromCompiled(mod, foundAs)) {
                //TODO: The nature (and so the grammar to be used) must be defined by the file we'll parse
                //(so, we need to know the system modules manager that actually created it to know the actual nature)
                IModule sourceMod = AbstractModule.createModuleFromDoc(mod.getName(), f,
                        new Document(FileUtils.getPyFileContents(f)), nature, true);
                if (sourceMod instanceof SourceModule) {
                    Definition[] definitions = (Definition[]) sourceMod.findDefinition(
                            state.getCopyWithActTok(foundAs), -1, -1, nature);
                    if (definitions.length > 0) {
                        this.definitionsFoundCache.add(token, definitions);
                        return definitions;
                    }
View Full Code Here

            moduleName = projModulesManager.resolveModule(FileUtils.getFileAbsolutePath(file));
        }
        if (moduleName == null) {
            moduleName = MODULE_NAME_WHEN_FILE_IS_UNDEFINED;
        }
        IModule module = createModuleFromDoc(moduleName, file, doc, pythonNature, false);
        return module;
    }
View Full Code Here

    /**
     * @return the ast for the current module
     */
    public SimpleNode getAST() {
        IModule mod = getModule();
        if (mod instanceof SourceModule) {
            return ((SourceModule) mod).getAst();
        }
        return null;
    }
View Full Code Here

        } catch (MisconfigurationException e) {
            Log.log(e);
        }
        if (!isAbsoluteImportEnabled) {
            //Let's check in Python 2.x if the from __future__ import absolute_import is there.
            IModule module = request.getModule();
            if (module != null) {
                isAbsoluteImportEnabled = module.hasFutureImportAbsoluteImportDeclared();
            }
        }
        return isAbsoluteImportEnabled;
    }
View Full Code Here

            if (original.endsWith(".")) {
                original = original.substring(0, original.length() - 1);
            }

            Tuple<IModule, String> modTok = findModuleFromPath(original, nature, false, null); //the current module name is not used as it is not relative
            IModule m = modTok.o1;
            String tok = modTok.o2;

            if (m == null) {
                //we were unable to find it with the given path, so, there's nothing else to do here...
                return;
            }

            IToken[] globalTokens;
            if (tok != null && tok.length() > 0) {
                CompletionState state2 = new CompletionState(-1, -1, tok, nature, "");
                state2.setBuiltinsGotten(true); //we don't want to get builtins here
                globalTokens = m.getGlobalTokens(state2, this);
            } else {
                CompletionState state2 = new CompletionState(-1, -1, "", nature, "");
                state2.setBuiltinsGotten(true); //we don't want to get builtins here
                globalTokens = getCompletionsForModule(m, state2);
            }
View Full Code Here

        IToken[] completionsForModule;
        try {
            Tuple<SimpleNode, Throwable> obj = PyParser
                    .reparseDocument(new PyParser.ParserInfo(doc, state.getNature()));
            SimpleNode n = obj.o1;
            IModule module = AbstractModule.createModule(n);

            completionsForModule = getCompletionsForModule(module, state, true, true);

        } catch (Exception e) {
            String message = e.getMessage();
View Full Code Here

        //check for the builtin types.
        state2.setActivationToken(NodeUtils.getBuiltinType(act));

        if (state2.getActivationToken() != null) {
            IModule m = getBuiltinMod(state.getNature());
            if (m != null) {
                return m.getGlobalTokens(state2, this);
            }
        }

        if (act.equals("__builtins__") || act.startsWith("__builtins__.")) {
            act = act.substring(12);
            if (act.startsWith(".")) {
                act = act.substring(1);
            }
            IModule m = getBuiltinMod(state.getNature());
            ICompletionState state3 = state.getCopy();
            state3.setActivationToken(act);
            return m.getGlobalTokens(state3, this);
        }
        return null;
    }
View Full Code Here

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

            if (state.getActivationToken().startsWith(rep)) {
                String absoluteImport = token.getAsAbsoluteImport();
                modUsed = modulesManager.getModuleAndRelatedModulesManager(absoluteImport, state.getNature(), true,
                        false);

                IModule sameLevelMod = null;
                if (modUsed != null) {
                    sameLevelMod = modUsed.o1;
                }

                if (sameLevelMod == null) {
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.