Examples of SourceModule


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

     * @return the module that is created by the given resource
     * @throws MisconfigurationException
     */
    protected SourceModule getSourceModule(IResource resource, IDocument document, IPythonNature nature)
            throws MisconfigurationException {
        SourceModule module = (SourceModule) memo.get(MODULE_CACHE + resource.getModificationStamp());
        if (module == null) {
            module = createSoureModule(resource, document, getModuleName(resource, nature));
            setModuleInCache(resource, module);
        }
        return module;
View Full Code Here

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

     * @return
     * @throws MisconfigurationException
     */
    protected SourceModule createSoureModule(IResource resource, IDocument document, String moduleName)
            throws MisconfigurationException {
        SourceModule module;
        PythonNature nature = PythonNature.getPythonNature(resource.getProject());
        IFile f = (IFile) resource;
        String file = f.getRawLocation().toOSString();
        module = (SourceModule) AbstractModule.createModuleFromDoc(moduleName, new File(file), document, nature, true);
        return module;
View Full Code Here

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

                }
            }

            if (module instanceof SourceModule) {
                //Support for __all__: filter things if __all__ is available.
                SourceModule sourceModule = (SourceModule) module;
                GlobalModelVisitor globalModelVisitorCache = sourceModule.getGlobalModelVisitorCache();
                if (globalModelVisitorCache != null) {
                    globalModelVisitorCache.filterAll(ret);
                }
            }
            return ret.toArray(new IToken[ret.size()]);
View Full Code Here

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

                if (modulesManager != null) {
                    String modName = modulesManager.resolveModule(FileUtils.getFileAbsolutePath(file));
                    if (modName != null) {
                        IModule module = modulesManager.getModule(modName, nature, true);
                        if (module instanceof ISourceModule) {
                            SourceModule iSourceModule = (SourceModule) module;
                            if (iSourceModule.parseError != null) {
                                throw iSourceModule.parseError;
                            }
                            return new ModuleAdapter(pythonModuleManager, ((ISourceModule) module), nature, doc);
                        }
View Full Code Here

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

                                        found = nature.getAstManager().findModule(
                                                foundFromImportStr,
                                                currentModule,
                                                state,
                                                new SourceModule(currentModule, edit.getEditorFile(), edit.getAST(),
                                                        null));
                                    } catch (Exception e) {
                                        Log.log(e);
                                    }
                                    break OUT;
                                }
                            }
                        }
                        break OUT;
                    }
                }

                boolean addOptionToCreateClassOrMethod = isImportFrom;

                if (found != null && found.o1 != null) {
                    //Ok, we found a module, now, it may be that we still have to create some intermediary modules
                    //or just create a class or method at the end.
                    if (found.o1 instanceof SourceModule) {

                        //if all was found, there's nothing left to create.
                        if (found.o2 != null && found.o2.length() > 0) {
                            SourceModule sourceModule = (SourceModule) found.o1;
                            File file = sourceModule.getFile();

                            if (found.o2.indexOf('.') != -1) {
                                //We have to create some intermediary structure.
                                if (!addOptionToCreateClassOrMethod) {

                                    //Cannot create class or method from the info (only the module structure).
                                    if (sourceModule.getName().endsWith(".__init__")) {
                                        File f = getFileStructure(file.getParentFile(), found.o2);
                                        addCreateModuleOption(ps, edit, props, markerContents, f);
                                    }

                                } else {
                                    //Ok, the leaf may be a class or method.
                                    if (sourceModule.getName().endsWith(".__init__")) {
                                        String moduleName = FullRepIterable.getWithoutLastPart(sourceModule.getName());
                                        String withoutLastPart = FullRepIterable.getWithoutLastPart(found.o2);
                                        moduleName += "." + withoutLastPart;

                                        String classOrMethodName = FullRepIterable.getLastPart(found.o2);

                                        File f = getFileStructure(file.getParentFile(), withoutLastPart);
                                        addCreateClassInNewModuleOption(ps, edit, props, classOrMethodName, moduleName,
                                                parametersAfterCall, f);
                                        addCreateMethodInNewModuleOption(ps, edit, props, classOrMethodName,
                                                moduleName, parametersAfterCall, f);
                                    }

                                }

                            } else {
                                //Ok, it's all there, we just have to create the leaf.
                                if (!addOptionToCreateClassOrMethod || sourceModule.getName().endsWith(".__init__")) {
                                    //Cannot create class or method from the info (only the module structure).
                                    if (sourceModule.getName().endsWith(".__init__")) {
                                        File f = new File(file.getParent(), found.o2
                                                + FileTypesPreferencesPage.getDefaultDottedPythonExtension());
                                        addCreateModuleOption(ps, edit, props, markerContents, f);
                                    }
                                } else {
View Full Code Here

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

        } catch (MisconfigurationException e) {
            throw new RuntimeException(e);
        }
        additionalInfo.addAstInfo(ast, new ModulesKey(modName, f), false);
        ModulesManager modulesManager = (ModulesManager) natureToAdd.getAstManager().getModulesManager();
        SourceModule mod = (SourceModule) AbstractModule.createModule(ast, f, modName);
        modulesManager.doAddSingleModule(new ModulesKey(modName, f), mod);
    }
View Full Code Here

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

    public void testAddInner() throws MisconfigurationException {
        String doc = "class Test:\n" +
                "    def m1(self):\n" +
                "        pass";
        SourceModule module = (SourceModule) AbstractModule.createModuleFromDoc("test", null, new Document(doc),
                nature, true);
        info.addAstInfo(module.getAst(), module.getModulesKey(), false);

        Collection<IInfo> tokensStartingWith = info.getTokensStartingWith("Tes", AbstractAdditionalTokensInfo.TOP_LEVEL
                | AbstractAdditionalTokensInfo.INNER);
        assertEquals(1, tokensStartingWith.size());
        assertIsIn("Test", tokensStartingWith);
View Full Code Here

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

                "    class Test2:\n"
                +
                "        def mmm(self):\n" +
                "            self.attr1 = 10";

        SourceModule module = (SourceModule) AbstractModule.createModuleFromDoc("test", null, new Document(doc),
                nature, true);
        info.addAstInfo(module.getAst(), module.getModulesKey(), false);

        Collection<IInfo> tokensStartingWith = null;
        IInfo i = null;

        tokensStartingWith = info.getTokensStartingWith("global", AbstractAdditionalTokensInfo.TOP_LEVEL
View Full Code Here

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

    public void testAddInner2() throws MisconfigurationException {
        String doc = "class Test:\n" +
                "    class Test2:\n" +
                "        def mmm(self):\n" +
                "            pass";
        SourceModule module = (SourceModule) AbstractModule.createModuleFromDoc("test", null, new Document(doc),
                nature, true);
        info.addAstInfo(module.getAst(), module.getModulesKey(), false);

        Collection<IInfo> tokensStartingWith = null;

        tokensStartingWith = info.getTokensStartingWith("m", AbstractAdditionalTokensInfo.TOP_LEVEL
                | AbstractAdditionalTokensInfo.INNER);
View Full Code Here

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

                +
                "            print mmm1";
        File tempFileAt = FileUtils.getTempFileAt(baseDir, "data_temporary_file_on_additional_interpreter_info_test", ".py");
        FileUtils.writeStrToFile(doc, tempFileAt);
        try {
            SourceModule module = (SourceModule) AbstractModule.createModuleFromDoc("test", tempFileAt, new Document(
                    doc), nature, true);
            info.addAstInfo(module.getAst(), new ModulesKey("test", tempFileAt), false);

            List<ModulesKey> modulesWithTokensStartingWith = null;

            modulesWithTokensStartingWith = info.getModulesWithToken("mmm", null);
            assertEquals(1, modulesWithTokensStartingWith.size());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.