Package org.python.pydev.editor.codecompletion.revisited.modules

Examples of org.python.pydev.editor.codecompletion.revisited.modules.SourceModule


                                                    true);
                                        }
                                    }
                                }
                                if (module instanceof SourceModule) {
                                    SourceModule sourceModule = (SourceModule) module;

                                    OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(sourceModule.getAst());
                                    ParsedItem root = new ParsedItem(visitor.getAll().toArray(
                                            new ASTEntryWithChildren[0]), null);
                                    childrenToReturn = getChildrenFromParsedItem(wrappedResourceParent, root, file);
                                }
                            }
View Full Code Here


                try {
                    AbstractModule mod = AbstractModule.createModule(key.name, key.file, info.nature, true);
                    if (!(mod instanceof SourceModule)) {
                        continue;
                    }
                    SourceModule module = (SourceModule) mod;
                    if (module == null || module.getAst() == null) {
                        buffer.append(com.aptana.shared_core.string.StringUtils.format(
                                "Warning: cannot parse: %s - %s (so, it's ok not having additional info on it)\n",
                                key.name, key.file));
                    } else {
                        try {
                            Iterator<ASTEntry> innerEntriesForAST = AbstractAdditionalDependencyInfo
                                    .getInnerEntriesForAST(module.getAst()).o2;
                            if (innerEntriesForAST.hasNext()) {
                                info.allOk = false;
                                info.moduleNotInAdditionalInfo.add(module);
                                buffer.append(com.aptana.shared_core.string.StringUtils.format(
                                        "The additional info index of the module: %s is not updated.\n", key.name));
View Full Code Here

        }

        //Put things from the memo to final variables as we might need them later on and we cannot get them from
        //the memo later.
        final String moduleName;
        final SourceModule module;
        final IDocument doc;
        try {
            doc = document.call();
            if (doc == null) {
                return;
            }

            moduleName = getModuleName(resource, nature);
            module = getSourceModule(resource, doc, nature);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }

        //depending on the level of analysis we have to do, we'll decide whether we want
        //to make the full parse (slower) or the definitions parse (faster but only with info
        //related to the definitions)
        ICallback<IModule, Integer> moduleCallback = new ICallback<IModule, Integer>() {

            public IModule call(Integer arg) {

                //Note: we cannot get anything from the memo at this point because it'll be called later on from a thread
                //and the memo might have changed already (E.g: moduleName and module)

                if (arg == IAnalysisBuilderRunnable.FULL_MODULE) {
                    if (module != null) {
                        return module;
                    } else {
                        try {
                            return createSoureModule(resource, doc, moduleName);
                        } catch (MisconfigurationException e) {
                            throw new RuntimeException(e);
                        }
                    }

                } else if (arg == IAnalysisBuilderRunnable.DEFINITIONS_MODULE) {
                    if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
                        Log.toLogFile(this, "PyDevBuilderPrefPage.getAnalyzeOnlyActiveEditor()");
                    }
                    IFile f = (IFile) resource;
                    String file = f.getRawLocation().toOSString();
                    return new SourceModule(moduleName, new File(file), FastDefinitionsParser.parse(doc.get(),
                            moduleName), null);

                } else {
                    throw new RuntimeException("Unexpected parameter: " + arg);
                }
View Full Code Here

                return "None";
            }
            //Only mark it as found if we were able to get the python nature (otherwise, this could change later
            //if requesting during a setup)
            if (nature.startRequests()) { //start requests, as we'll ask for resolve and get module.
                SourceModule sourceModule = null;
                try {
                    String modName = nature.resolveModule(fileStr);
                    if (modName != null) {
                        //when all is set up, this is the most likely path we're going to use
                        //so, we shouldn't have delays when the module is changed, as it's already
                        //ok for use.
                        IModule module = astManager.getModule(modName, nature, true);
                        if (module instanceof SourceModule) {
                            sourceModule = (SourceModule) module;
                        }
                    }
                } finally {
                    nature.endRequests();
                }
                lastModifiedTimeCached = file.lastModified();

                if (sourceModule == null) {
                    //the text for the breakpoint requires the function name, and it may be requested before
                    //the ast manager is actually restored (so, modName is None, and we have little alternative
                    //but making a parse to get the function name)
                    IDocument doc = getDocument();
                    sourceModule = (SourceModule) AbstractModule.createModuleFromDoc("", null, doc, nature, true);
                }

                int lineToUse = getLineNumber() - 1;

                if (sourceModule == null || sourceModule.getAst() == null || lineToUse < 0) {
                    functionName = "None";
                    return functionName;
                }

                SimpleNode ast = sourceModule.getAst();

                functionName = NodeUtils.getContextName(lineToUse, ast);
                if (functionName == null) {
                    functionName = ""; //global context
                }
View Full Code Here

                try {
                    AbstractModule mod = AbstractModule.createModule(key.name, key.file, info.nature, true);
                    if (!(mod instanceof SourceModule)) {
                        continue;
                    }
                    SourceModule module = (SourceModule) mod;
                    if (module == null || module.getAst() == null) {
                        addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                                "Warning: cannot parse: %s - %s (so, it's ok not having additional info on it)",
                                key.name, key.file)));
                    } else {
                        try {
                            Iterator<ASTEntry> innerEntriesForAST = AbstractAdditionalDependencyInfo
                                    .getInnerEntriesForAST(module.getAst()).o2;
                            if (innerEntriesForAST.hasNext()) {
                                info.moduleNotInAdditionalInfo.add(module);
                                addChild(new LeafElement(this, com.aptana.shared_core.string.StringUtils.format(
                                        "The additional info index of the module: %s is not updated.", key.name)));
                            }
View Full Code Here

                moduleRequest = FULL_MODULE;
            }

            //get the module for the analysis
            checkStop();
            SourceModule module = (SourceModule) this.module.call(moduleRequest);

            checkStop();
            //recreate the ctx insensitive info
            recreateCtxInsensitiveInfo(info, module, nature, r);
View Full Code Here

        PyEdit pyEdit = (PyEdit) part;
        SimpleNode ast = pyEdit.getAST();
        if (ast == null) {
            IDocument doc = pyEdit.getDocument();
            SourceModule sourceModule;
            IPythonNature nature = null;
            try {
                nature = pyEdit.getPythonNature();
            } catch (MisconfigurationException e) {
                // Let's try to find a suitable nature
                File editorFile = pyEdit.getEditorFile();
                if (editorFile == null || !editorFile.exists()) {
                    Log.log(e);
                    return false;
                }
                nature = PydevPlugin.getInfoForFile(editorFile).o1;
            }

            if (nature == null) {
                Log.log("Unable to determine nature!");
                return false;
            }

            try {
                sourceModule = (SourceModule) AbstractModule.createModuleFromDoc("", null, doc, nature, true);
            } catch (MisconfigurationException e) {
                Log.log(e);
                return false;
            }
            ast = sourceModule.getAst();
        }

        if (ast == null) {
            Log.log("Cannot determine context to run to.");
            return false;
View Full Code Here

        PyEdit pyEdit = (PyEdit) part;
        SimpleNode ast = pyEdit.getAST();
        if (ast == null) {
            IDocument doc = pyEdit.getDocument();
            SourceModule sourceModule;
            IPythonNature nature = null;
            try {
                nature = pyEdit.getPythonNature();
            } catch (MisconfigurationException e) {
                //Let's try to find a suitable nature
                File editorFile = pyEdit.getEditorFile();
                if (editorFile == null || !editorFile.exists()) {
                    Log.log(e);
                    return;
                }
                nature = PydevPlugin.getInfoForFile(editorFile).o1;
            }

            if (nature == null) {
                Log.log("Unable to determine nature!");
                return;
            }

            try {
                sourceModule = (SourceModule) AbstractModule.createModuleFromDoc("", null, doc, nature, true);
            } catch (MisconfigurationException e) {
                Log.log(e);
                return;
            }
            ast = sourceModule.getAst();
        }

        if (ast == null) {
            Log.log("Cannot determine context to run to.");
            return;
View Full Code Here

            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();
        }
        if (s != null) {
            FindScopeVisitor visitor = new FindScopeVisitor(state.getLine(), 0);
            try {
                s.accept(visitor);
View Full Code Here

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

        if (n instanceof SourceModule) {
            //ok, module exists, let's check if it is synched with the filesystem version...
            SourceModule s = (SourceModule) n;
            if (!s.isSynched()) {
                //change it for an empty and proceed as usual.
                n = (AbstractModule) addModule(createModulesKey(s.getName(), s.getFile()));
            }
        }

        if (n instanceof EmptyModule) {
            EmptyModule e = (EmptyModule) n;

            boolean found = false;

            if (!found && e.f != null) {

                if (!e.f.exists()) {
                    //if the file does not exist anymore, just remove it.
                    keyForCacheAccess.name = name;
                    keyForCacheAccess.file = e.f;
                    doRemoveSingleModule(keyForCacheAccess);
                    n = null;

                } else {
                    //file exists
                    n = checkOverride(name, nature, n);

                    if (n instanceof EmptyModule) {
                        //ok, handle case where the file is actually from a zip file...
                        if (e instanceof EmptyModuleForZip) {
                            EmptyModuleForZip emptyModuleForZip = (EmptyModuleForZip) e;

                            if (emptyModuleForZip.pathInZip.endsWith(".class") || !emptyModuleForZip.isFile) {
                                //handle java class... (if it's a class or a folder in a jar)
                                n = JythonModulesManagerUtils.createModuleFromJar(emptyModuleForZip);
                                n = decorateModule(n, nature);

                            } else if (FileTypesPreferencesPage.isValidDll(emptyModuleForZip.pathInZip)) {
                                //.pyd
                                n = new CompiledModule(name, this);
                                n = decorateModule(n, nature);

                            } else if (PythonPathHelper.isValidSourceFile(emptyModuleForZip.pathInZip)) {
                                //handle python file from zip... we have to create it getting the contents from the zip file
                                try {
                                    IDocument doc = FileUtilsFileBuffer.getDocFromZip(emptyModuleForZip.f,
                                            emptyModuleForZip.pathInZip);
                                    //NOTE: The nature (and so the grammar to be used) must be defined by this modules
                                    //manager (and not by the initial caller)!!
                                    n = AbstractModule.createModuleFromDoc(name, emptyModuleForZip.f, doc,
                                            this.getNature(), false);
                                    SourceModule zipModule = (SourceModule) n;
                                    zipModule.zipFilePath = emptyModuleForZip.pathInZip;
                                    n = decorateModule(n, nature);
                                } catch (Exception exc1) {
                                    Log.log(exc1);
                                    n = null;
                                }
                            }

                        } else {
                            //regular case... just go on and create it.
                            try {
                                //NOTE: The nature (and so the grammar to be used) must be defined by this modules
                                //manager (and not by the initial caller)!!
                                n = AbstractModule.createModule(name, e.f, this.getNature(), true);
                                n = decorateModule(n, nature);
                            } catch (IOException exc) {
                                keyForCacheAccess.name = name;
                                keyForCacheAccess.file = e.f;
                                doRemoveSingleModule(keyForCacheAccess);
                                n = null;
                            } catch (MisconfigurationException exc) {
                                Log.log(exc);
                                n = null;
                            }
                        }
                    }

                }

            } else { //ok, it does not have a file associated, so, we treat it as a builtin (this can happen in java jars)
                n = checkOverride(name, nature, n);
                if (n instanceof EmptyModule) {
                    if (acceptCompiledModule) {
                        n = new CompiledModule(name, this);
                        n = decorateModule(n, nature);
                    } else {
                        return null;
                    }
                }
            }

            if (n != null) {
                doAddSingleModule(createModulesKey(name, e.f), n);
            } else {
                Log.log(("The module " + name + " could not be found nor created!"));
            }
        }

        if (n instanceof EmptyModule) {
            throw new RuntimeException("Should not be an empty module anymore: " + n);
        }
        if (n instanceof SourceModule) {
            SourceModule sourceModule = (SourceModule) n;
            //now, here's a catch... it may be a bootstrap module...
            if (sourceModule.isBootstrapModule()) {
                //if it's a bootstrap module, we must replace it for the related compiled module.
                n = new CompiledModule(name, this);
                n = decorateModule(n, nature);
            }
        }
View Full Code Here

TOP

Related Classes of org.python.pydev.editor.codecompletion.revisited.modules.SourceModule

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.