Package org.python.indexer.types

Examples of org.python.indexer.types.NModuleType


    }

    public void testClassTypeBuiltinAttrs() throws Exception {
        String file = "classtype_builtins.py";
        buildIndex(file);
        NModuleType module = (NModuleType)idx.moduleTable.lookupType(abspath(file));
        Scope mtable = module.getTable();
        assertTrue(mtable.lookupType("MyClass").isClassType());
        assertTrue(mtable.lookupType("MyClassNoDoc").isClassType());
        assertTrue(mtable.lookupType("MyClass").getTable().getParent() == mtable);
        assertEquals(NBinding.Kind.CLASS, mtable.lookup("MyClass").getKind());
        Scope t = mtable.lookupType("MyClass").getTable();
View Full Code Here


    /**
     * Generate an anchorless URL linking to another file in the index.
     */
    private String toModuleUrl(NBinding nb) {
        NModuleType mtype = nb.getType().follow().asModuleType();
        String path = mtype.getFile();
        if (!path.startsWith(rootPath)) {
            return "file://" + path;  // can't find file => punt & load it directly
        }
        String relpath = path.substring(rootPath.length());
        return Util.joinPath(outDir.getAbsolutePath(), relpath) + ".html";
View Full Code Here

     */
    public NModuleType getModuleForFile(String file) throws Exception {
        if (failedModules.contains(file)) {
            return null;
        }
        NModuleType m = getCachedModule(file);
        if (m != null) {
            return m;
        }
        return loadFile(file);
    }
View Full Code Here

     * Idempotent:  looks in the module cache first. Used for simple unit tests.
     * @param path a path for reporting/caching purposes.  The filename
     *        component is used to construct the module qualified name.
     */
    public NModuleType loadString(String path, String contents) throws Exception {
        NModuleType module = getCachedModule(path);
        if (module != null) {
            finer("\nusing cached module " + path + " [succeeded]");
            return module;
        }
        return parseAndResolve(path, contents);
View Full Code Here

        if (!f.canRead()) {
            finer("\nfile not not found or cannot be read: " + path);
            return null;
        }

        NModuleType module = getCachedModule(path);
        if (module != null) {
            finer("\nusing cached module " + path + " [succeeded]");
            return module;
        }
View Full Code Here

     *        file contents from disk.
     */
    @SuppressWarnings("unchecked")
    private NModuleType parseAndResolve(String file, String contents) throws Exception {
        // Avoid infinite recursion if any caller forgets this check.  (Has happened.)
        NModuleType nmt = (NModuleType)moduleTable.lookupType(file);
        if (nmt != null) {
            return nmt;
        }

        // Put it in the cache now to prevent circular import from recursing.
        NModuleType mod = new NModuleType(Util.moduleNameFor(file), file, globaltable);
        moduleTable.put(file, new NUrl("file://" + file), mod, NBinding.Kind.MODULE);

        try {
            NModule ast = null;
            if (contents != null) {
View Full Code Here

    public NModuleType loadModule(String modname) throws Exception {
        if (failedModules.contains(modname)) {
            return null;
        }

        NModuleType cached = getCachedModule(modname); // builtin file-less modules
        if (cached != null) {
            finer("\nusing cached module " + modname);
            return cached;
        }

        NModuleType mt = getBuiltinModule(modname);
        if (mt != null) {
            return mt;
        }

        finer("looking for module " + modname);

        if (modname.endsWith(".py")) {
            modname = modname.substring(0, modname.length() - 3);
        }
        String modpath = modname.replace('.', '/');

        // A nasty hack to avoid e.g. python2.5 becoming python2/5.
        // Should generalize this for directory components containing '.'.
        modpath = modpath.replaceFirst("(/python[23])/([0-9]/)", "$1.$2");

        List<String> loadPath = getLoadPath();

        for (String p : loadPath) {
            String dirname = p + modpath;
            String pyname = dirname + ".py";
            String initname = Util.joinPath(dirname, "__init__.py").getAbsolutePath();
            String name;

            // foo/bar has priority over foo/bar.py
            // http://www.python.org/doc/essays/packages.html
            if (Util.isReadableFile(initname)) {
                name = initname;
            } else if (Util.isReadableFile(pyname)) {
                name = pyname;
            } else {
                continue;
            }

            name = Util.canonicalize(name);
            NModuleType m = loadFile(name);
            if (m != null) {
                finer("load of module " + modname + "[succeeded]");
                return m;
            }
        }
View Full Code Here

            return;
        }
        if (!qname.getType().isModuleType()) {
            return;
        }
        NModuleType mt = qname.getType().asModuleType();

        String modQname = mt.getTable().getPath();
        NBinding mb = Indexer.idx.lookupQname(modQname);
        if (mb == null) {
            mb = Indexer.idx.moduleTable.lookup(modQname);
        }
View Full Code Here

    @Override
    public NType resolve(Scope s) throws Exception {
        NBinding mb = Indexer.idx.moduleTable.lookupLocal(file);
        if (mb == null ) {
            Indexer.idx.reportFailedAssertion("No module for " + name + ": " + file);
            setType(new NModuleType(name, file, s));
        } else {
            setType(mb.getType());
        }

        resolveExpr(body, getTable());
View Full Code Here

    /**
     * If the module defines an {@code __all__} variable, resolve references
     * to each of the elements.
     */
    private void resolveExportedNames() throws Exception {
        NModuleType mtype = null;
        NType thisType = getType();
        if (thisType.isModuleType()) {
            mtype = thisType.asModuleType();
        } else if (thisType.isUnionType()) {
            for (NType u : thisType.asUnionType().getTypes()) {
                if (u.isModuleType()) {
                    mtype = u.asModuleType();
                    break;
                }
            }
        }

        if (mtype == null) {
            Indexer.idx.reportFailedAssertion("Found non-module type for "
                                              + this + " in " + getFile() + ": " + thisType);
            return;
        }

        Scope table = mtype.getTable();
        for (NStr nstr : getExportedNameNodes()) {
            String name = nstr.n.toString();
            NBinding b = table.lookupLocal(name);
            if (b != null) {
                Indexer.idx.putLocation(nstr, b);
View Full Code Here

TOP

Related Classes of org.python.indexer.types.NModuleType

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.