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

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


     * real generic way of discovering it (actually, even by looking at the class definition this is very obscure),
     * so, the solution found is creating the objects by decorating the module with that info.
     */
    private AbstractModule decorateModule(AbstractModule n, IPythonNature nature) {
        if (n instanceof SourceModule && "django.db.models.base".equals(n.getName())) {
            SourceModule sourceModule = (SourceModule) n;
            SimpleNode ast = sourceModule.getAst();
            for (SimpleNode node : ((Module) ast).body) {
                if (node instanceof ClassDef && "Model".equals(NodeUtils.getRepresentationString(node))) {
                    Object[][] metaclassAttrs = new Object[][] {
                            { "objects", NodeUtils.makeAttribute("django.db.models.manager.Manager()") },
                            { "DoesNotExist", new Name("Exception", Name.Load, false) },
View Full Code Here


    public AssignCompletionInfo getAssignCompletions(ICodeCompletionASTManager manager, IModule module,
            ICompletionState state) {
        ArrayList<IToken> ret = new ArrayList<IToken>();
        Definition[] defs = new Definition[0];
        if (module instanceof SourceModule) {
            SourceModule s = (SourceModule) module;

            try {
                defs = s.findDefinition(state, state.getLine() + 1, state.getCol() + 1, state.getNature());
                for (int i = 0; i < defs.length; i++) {
                    //go through all definitions found and make a merge of it...
                    Definition definition = defs[i];

                    if (state.getLine() == definition.line && state.getCol() == definition.col) {
View Full Code Here

                        if (editorFile != null) {
                            String moduleName = pythonNature.resolveModule(editorFile);
                            if (moduleName != null) {
                                synchronized (lockHandle) {
                                    releaseCurrentHandle();
                                    int modHandle = modulesManager.pushTemporaryModule(moduleName, new SourceModule(
                                            moduleName, editorFile, ast, null));

                                    this.handle = new Tuple3<Integer, IModulesManager, String>(modHandle,
                                            modulesManager, moduleName);
                                }
View Full Code Here

        }

        if (modName == null) {
            if (mod.getName() == null) {
                if (mod instanceof SourceModule) {
                    SourceModule m = (SourceModule) mod;
                    modName = "__module_not_in_the_pythonpath__";
                    m.setName(modName);
                }
            }
            if (modName == null) {
                Log.logInfo("Unable to resolve module for find definition request (modName == null).");
                return null;
View Full Code Here

     * @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

     * @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

                }
            }

            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

                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

                                        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

        } 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

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.