Package org.python.pydev.core

Examples of org.python.pydev.core.ModulesKey


    private AbstractModule checkOverride(String name, IPythonNature nature, AbstractModule emptyModule) {
        return emptyModule;
    }

    private ModulesKey createModulesKey(String name, File f) {
        ModulesKey newEntry = new ModulesKey(name, f);
        synchronized (modulesKeysLock) {
            Entry<ModulesKey, ModulesKey> oldEntry = this.modulesKeys.getEntry(newEntry);
            if (oldEntry != null) {
                return oldEntry.getKey();
            } else {
View Full Code Here


        List<ModulesKey> toRem = new ArrayList<ModulesKey>();
        synchronized (modulesKeysLock) {

            for (Iterator<ModulesKey> iter = modulesKeys.keySet().iterator(); iter.hasNext();) {
                ModulesKey key = iter.next();
                if (key.file != null && key.file.equals(file)) {
                    toRem.add(key);
                }
            }
View Full Code Here

    public void rebuildModule(File f, ICallback0<IDocument> doc, final IProject project, IProgressMonitor monitor,
            IPythonNature nature) {
        final String m = pythonPathHelper.resolveModule(FileUtils.getFileAbsolutePath(f));
        if (m != null) {
            addModule(new ModulesKey(m, f));

        } else if (f != null) { //ok, remove the module that has a key with this file, as it can no longer be resolved
            synchronized (modulesKeysLock) {
                Set<ModulesKey> toRemove = new HashSet<ModulesKey>();
                for (Iterator<ModulesKey> iter = modulesKeys.keySet().iterator(); iter.hasNext();) {
                    ModulesKey key = iter.next();
                    if (key.file != null && key.file.equals(f)) {
                        toRemove.add(key);
                    }
                }
                removeThem(toRemove);
View Full Code Here

     */
    public ModulesKey getModulesKey() {
        if (zipFilePath != null && zipFilePath.length() > 0) {
            return new ModulesKeyForZip(name, file, zipFilePath, true);
        }
        return new ModulesKey(name, file);
    }
View Full Code Here

        synchronized (modulesKeysLock) {
            buf = new FastStringBuffer(this.modulesKeys.size() * 50);
            buf.append(MODULES_MANAGER_V2);

            for (Iterator<ModulesKey> iter = this.modulesKeys.keySet().iterator(); iter.hasNext();) {
                ModulesKey next = iter.next();
                buf.append(next.name);
                if (next.file != null) {
                    buf.append("|");
                    if (next instanceof ModulesKeyForZip) {
                        ModulesKeyForZip modulesKeyForZip = (ModulesKeyForZip) next;
View Full Code Here

                public boolean hasNext() {
                    return i < size;
                }

                public Object next() {
                    final ModulesKey next = lst.get(i);
                    i++;
                    return new Map.Entry() {

                        public Object getKey() {
                            return next;
View Full Code Here

    }

    private static void handleLineParts(ModulesManager modulesManager, HashMap<Integer, String> intToString,
            String[] split, int size, ArrayList<ModulesKey> lst) {
        if (size > 0 && split[0].length() > 0) { //Just making sure we have something there.
            ModulesKey key;
            if (size == 1) {
                key = new ModulesKey(split[0], null);
                //restore with empty modules.
                lst.add(key);

            } else if (size == 2) {
                key = new ModulesKey(split[0], new File(split[1]));
                //restore with empty modules.
                lst.add(key);

            } else if (size == 4) {
                try {
View Full Code Here

        ArrayList<ModulesKey> removedKeys = new ArrayList<ModulesKey>();
        Iterator<ModulesKey> it = keysFound.keySet().iterator();

        synchronized (modulesKeysLock) {
            while (it.hasNext()) {
                ModulesKey next = it.next();
                ModulesKey modulesKey = modulesKeys.get(next);
                if (modulesKey == null || modulesKey.getClass() != next.getClass()) {
                    //Check the class because ModulesKey and ModulesKeyForZip are equal considering only the name.
                    newKeys.add(next);
                }
            }

            it = modulesKeys.keySet().iterator();
            while (it.hasNext()) {
                ModulesKey next = it.next();
                ModulesKey modulesKey = modulesKeys.get(next);
                if (modulesKey == null || modulesKey.getClass() != next.getClass()) {
                    removedKeys.add(next);
                }
            }
        }
View Full Code Here

        //create the builtin modules
        String[] builtins = getBuiltins();
        if (builtins != null) {
            for (int i = 0; i < builtins.length; i++) {
                String name = builtins[i];
                final ModulesKey k = new ModulesKey(name, null);
                keys.put(k, k);
            }
        }
    }
View Full Code Here

            //still on startup
            return null;
        }

        //for temporary access (so that we don't generate many instances of it)
        ModulesKey keyForCacheAccess = new ModulesKey(null, null);

        //A different choice for users that want more complete information on the libraries they're dealing
        //with is using predefined modules. Those will
        File predefinedModule = this.info.getPredefinedModule(name);
        if (predefinedModule != null && predefinedModule.exists()) {
            keyForCacheAccess.name = name;
            keyForCacheAccess.file = predefinedModule;
            n = cache.getObj(keyForCacheAccess, this);
            if ((n instanceof PredefinedSourceModule)) {
                PredefinedSourceModule predefinedSourceModule = (PredefinedSourceModule) n;
                if (predefinedSourceModule.isSynched()) {
                    return n;
                }
                //otherwise (not PredefinedSourceModule or not synched), just keep going to create
                //it as a predefined source module
            }

            boolean tryToParse = true;
            Long lastModified = null;
            if (predefinedFilesNotParsedToTimestamp == null) {
                predefinedFilesNotParsedToTimestamp = new HashMap<File, Long>();
            } else {
                Long lastTimeChanged = predefinedFilesNotParsedToTimestamp.get(predefinedModule);
                if (lastTimeChanged != null) {
                    lastModified = predefinedModule.lastModified();
                    if (lastTimeChanged.equals(lastModified)) {
                        tryToParse = false;
                    } else {
                        predefinedFilesNotParsedToTimestamp.remove(predefinedModule);
                    }
                }
            }

            if (tryToParse) {
                IDocument doc;
                try {
                    doc = FileUtilsFileBuffer.getDocFromFile(predefinedModule);
                    IGrammarVersionProvider provider = new IGrammarVersionProvider() {

                        public int getGrammarVersion() throws MisconfigurationException {
                            return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_3_0; // Always Python 3.0 here
                        }
                    };
                    Tuple<SimpleNode, Throwable> obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, provider,
                            name, predefinedModule));
                    if (obj.o2 != null) {
                        if (lastModified == null) {
                            lastModified = predefinedModule.lastModified();
                        }
                        predefinedFilesNotParsedToTimestamp.put(predefinedModule, lastModified);
                        Log.log("Unable to parse: " + predefinedModule, obj.o2);

                    } else if (obj.o1 != null) {
                        n = new PredefinedSourceModule(name, predefinedModule, obj.o1, obj.o2);
                        doAddSingleModule(keyForCacheAccess, n);
                        return n;
                    }
                    //keep on going
                } catch (Throwable e) {
                    Log.log(e);
                }
            }
        }

        boolean foundStartingWithBuiltin = false;
        FastStringBuffer buffer = null;

        for (int i = 0; i < builtins.length; i++) {
            String forcedBuiltin = builtins[i];
            if (name.startsWith(forcedBuiltin)) {
                if (name.length() > forcedBuiltin.length() && name.charAt(forcedBuiltin.length()) == '.') {
                    foundStartingWithBuiltin = true;

                    keyForCacheAccess.name = name;
                    n = cache.getObj(keyForCacheAccess, this);

                    if (n == null && dontSearchInit == false) {
                        if (buffer == null) {
                            buffer = new FastStringBuffer();
                        } else {
                            buffer.clear();
                        }
                        keyForCacheAccess.name = buffer.append(name).append(".__init__").toString();
                        n = cache.getObj(keyForCacheAccess, this);
                    }

                    if (n instanceof EmptyModule || n instanceof SourceModule) {
                        //it is actually found as a source module, so, we have to 'coerce' it to a compiled module
                        n = new CompiledModule(name, this);
                        doAddSingleModule(new ModulesKey(n.getName(), null), n);
                        return n;
                    }
                }

                if (name.equals(forcedBuiltin)) {

                    keyForCacheAccess.name = name;
                    n = cache.getObj(keyForCacheAccess, this);

                    if (n == null || n instanceof EmptyModule || n instanceof SourceModule) {
                        //still not created or not defined as compiled module (as it should be)
                        n = new CompiledModule(name, this);
                        doAddSingleModule(new ModulesKey(n.getName(), null), n);
                        return n;
                    }
                }
                if (n instanceof CompiledModule) {
                    return n;
                }
            }
        }
        if (foundStartingWithBuiltin) {
            if (builtinsNotConsidered.getObj(name) != null) {
                return null;
            }

            //ok, just add it if it is some module that actually exists
            n = new CompiledModule(name, this);
            IToken[] globalTokens = n.getGlobalTokens();
            //if it does not contain the __file__, this means that it's not actually a module
            //(but may be a token from a compiled module, so, clients wanting it must get the module
            //first and only then go on to this token).
            //done: a cache with those tokens should be kept, so that we don't actually have to create
            //the module to see its return values (because that's slow)
            if (globalTokens.length > 0 && contains(globalTokens, "__file__")) {
                doAddSingleModule(new ModulesKey(name, null), n);
                return n;
            } else {
                builtinsNotConsidered.add(name, name);
                return null;
            }
View Full Code Here

TOP

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

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.