Package org.python.pydev.core

Examples of org.python.pydev.core.IModule


            callingBoundMethod = true;
            if (initNode == null) {
                String className = ((NameTok) classDef.name).id;

                Definition foundDef = sourceToken.getDefinition();
                IModule mod = this.current;
                if (foundDef != null) {
                    mod = foundDef.module;
                }
                SimpleNode n = NodeUtils.getNodeFromPath(classDef, "__init__");
                if (n instanceof FunctionDef) {
                    initNode = n;

                } else {
                    IDefinition[] definition = mod.findDefinition(CompletionStateFactory.getEmptyCompletionState(
                            className + ".__init__", this.nature, this.completionCache), -1, -1, this.nature);
                    for (IDefinition iDefinition : definition) {
                        Definition d = (Definition) iDefinition;
                        if (d.ast instanceof FunctionDef) {
                            initNode = d.ast;
View Full Code Here


                        if (modulesManager instanceof IProjectModulesManager) {
                            IProjectModulesManager projectModulesManager = (IProjectModulesManager) modulesManager;
                            String moduleName = projectModulesManager.resolveModuleInDirectManager(file
                                    .getActualObject());
                            if (moduleName != null) {
                                IModule module = projectModulesManager.getModuleInDirectManager(moduleName, nature,
                                        true);
                                if (module == null) {
                                    //ok, something strange happened... it shouldn't be null... maybe empty, but not null at this point
                                    //so, if it exists, let's try to create it...
                                    //TODO: This should be moved to somewhere else.
View Full Code Here

                    IProject project = workspaceFile.getProject();
                    if (project != null && project.exists()) {
                        PythonNature nature = PythonNature.getPythonNature(project);
                        String moduleName = nature.resolveModule(file);
                        if (moduleName != null) {
                            IModule mod = nature.getAstManager().getModule(moduleName, nature, true);
                            if (mod != null) {
                                ICompletionCache completionCache = new CompletionCache();
                                IDefinition[] definitions = mod.findDefinition(CompletionStateFactory
                                        .getEmptyCompletionState(testPath, nature, completionCache), -1, -1, nature);

                                if (definitions != null && definitions.length > 0) {
                                    List<ItemPointer> pointers = new ArrayList<ItemPointer>();
                                    PyRefactoringFindDefinition.getAsPointers(pointers, (Definition[]) definitions);
View Full Code Here

            }
            if (moduleName == null) {
                continue;
            }
            AnalysisBuilderVisitor.setModuleNameInCache(visitor.memo, f, moduleName);
            IModule module = nature.getAstManager().getModule(moduleName, nature, true);
            if (module == null) {
                Log.log(IStatus.WARNING, "Unable to get module: " + moduleName + " for resource: " + f, null);
                continue;
            }
            visitor.doVisitChangedResource(nature, f, doc, null, module, new NullProgressMonitor(), true,
View Full Code Here

                    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 {
View Full Code Here

    private void analyze(ChangedParserInfoForObservers info, SimpleNode root, IFile fileAdapter, boolean force,
            IPythonNature nature) {
        if (!nature.startRequests()) {
            return;
        }
        IModule module;
        try {
            //we visit external because we must index them
            String moduleName = nature.resolveModuleOnlyInProjectSources(fileAdapter, true);
            if (moduleName == null) {
                AnalysisRunner.deleteMarkers(fileAdapter);
View Full Code Here

                            }

                            ICodeCompletionASTManager astManager = nature.getAstManager();
                            ProjectModulesManager modulesManager = (ProjectModulesManager) astManager
                                    .getModulesManager();
                            IModule moduleInDirectManager = modulesManager.getModuleInDirectManager(moduleName, nature,
                                    true);
                            if (moduleInDirectManager == null) {
                                labelErrorSettings.setText(com.aptana.shared_core.string.StringUtils.format("Module: %s could not be found.",
                                        moduleName));
                            } else {
View Full Code Here

     * @param nature the nature to be used
     * @param info the info that we are looking for
     */
    public static void getDefinitionFromIInfo(List<ItemPointer> pointers, ICodeCompletionASTManager manager,
            IPythonNature nature, IInfo info, ICompletionCache completionCache) {
        IModule mod;
        String tok;
        mod = manager.getModule(info.getDeclaringModuleName(), nature, true);
        if (mod != null) {
            if (info.getType() == IInfo.MOD_IMPORT_TYPE) {
                Definition definition = new Definition(1, 1, "", null, null, mod);
                PyRefactoringFindDefinition.getAsPointers(pointers, new Definition[] { definition });
                return;
            }
            //ok, now that we found the module, we have to get the actual definition
            tok = "";
            String path = info.getPath();

            if (path != null && path.length() > 0) {
                tok = path + ".";
            }
            tok += info.getName();
            try {
                IDefinition[] definitions = mod.findDefinition(
                        CompletionStateFactory.getEmptyCompletionState(tok, nature, completionCache), -1, -1, nature);

                if ((definitions == null || definitions.length == 0) && path != null && path.length() > 0) {
                    //this can happen if we have something as an attribute in the path:

                    //class Bar(object):
                    //    def __init__(self):
                    //        self.xxx = 10
                    //
                    //so, we'de get a find definition for Bar.__init__.xxx which is something we won't find
                    //for now, let's simply return a match in the correct context (although the correct way of doing
                    //it would be analyzing that context to find the match)
                    definitions = mod.findDefinition(
                            CompletionStateFactory.getEmptyCompletionState(path, nature, completionCache), -1, -1,
                            nature);

                }
                PyRefactoringFindDefinition.getAsPointers(pointers, (Definition[]) definitions);
View Full Code Here

                                    if (astManager == null) {
                                        //we're probably still loading it.
                                        return ret;
                                    }
                                    //Ok, looking for a token in globals.
                                    IModule module = request.getModule();
                                    if (module == null) {
                                        continue;
                                    }
                                    IToken[] comps = astManager.getCompletionsForModule(module, state, true, true);
                                    for (int i = 0; i < comps.length; i++) {
                                        IToken iToken = comps[i];
                                        String representation = iToken.getRepresentation();
                                        ImmutableTuple<IToken, String> curr = map.get(representation);
                                        if (curr != null && curr.o1 instanceof SourceToken) {
                                            continue; //source tokens are never reset!
                                        }

                                        int type = iToken.getType();
                                        if (iToken instanceof SourceToken
                                                && ((SourceToken) iToken).getAst() instanceof FunctionDef) {
                                            map.put(representation, new ImmutableTuple<IToken, String>(iToken,
                                                    baseClass));

                                        } else if (type == IToken.TYPE_FUNCTION || type == IToken.TYPE_UNKNOWN
                                                || type == IToken.TYPE_BUILTIN) {
                                            map.put(representation, new ImmutableTuple<IToken, String>(iToken,
                                                    baseClass));

                                        }
                                    }
                                } catch (Exception e) {
                                    Log.log(e);
                                }
                            }

                            for (ImmutableTuple<IToken, String> tokenAndBaseClass : map.values()) {
                                FunctionDef functionDef = null;

                                //No checkings needed for type (we already did that above).
                                if (tokenAndBaseClass.o1 instanceof SourceToken) {
                                    SourceToken sourceToken = (SourceToken) tokenAndBaseClass.o1;
                                    SimpleNode ast = sourceToken.getAst();
                                    if (ast instanceof FunctionDef) {
                                        functionDef = (FunctionDef) ast;
                                    } else {
                                        functionDef = sourceToken.getAliased().createCopy();
                                        NameTok t = (NameTok) functionDef.name;
                                        t.id = sourceToken.getRepresentation();
                                    }
                                } else {
                                    //unfortunately, for builtins we usually cannot trust the parameters.
                                    String representation = tokenAndBaseClass.o1.getRepresentation();
                                    PyAstFactory factory = new PyAstFactory(new AdapterPrefs(ps.getEndLineDelim(),
                                            request.nature));
                                    functionDef = factory.createFunctionDef(representation);
                                    functionDef.args = factory.createArguments(true);
                                    functionDef.args.vararg = new NameTok("args", NameTok.VarArg);
                                    functionDef.args.kwarg = new NameTok("kwargs", NameTok.KwArg);
                                    if (!representation.equals("__init__")) {
                                        functionDef.body = new stmtType[] { new Return(null) }; //signal that the return should be added
                                    }
                                }

                                if (functionDef != null) {
                                    ret.add(new OverrideMethodCompletionProposal(ps.getAbsoluteCursorOffset(), 0, 0,
                                            imageOverride, functionDef, tokenAndBaseClass.o2, //baseClass
                                            className));
                                }
                            }

                        }
                    }
                }
            }
            request.showTemplates = false;
            return ret;
        }

        try {
            IPythonNature pythonNature = request.nature;
            checkPythonNature(pythonNature);

            ICodeCompletionASTManager astManager = pythonNature.getAstManager();
            if (astManager == null) {
                //we're probably still loading it.
                return ret;
            }

            //list of Object[], IToken or ICompletionProposal
            List<Object> tokensList = new ArrayList<Object>();
            lazyStartShell(request);
            String trimmed = request.activationToken.replace('.', ' ').trim();

            ImportInfo importsTipper = getImportsTipperStr(request);

            int line = request.doc.getLineOfOffset(request.documentOffset);
            IRegion region = request.doc.getLineInformation(line);

            ICompletionState state = new CompletionState(line, request.documentOffset - region.getOffset(), null,
                    request.nature, request.qualifier);
            state.setIsInCalltip(request.isInCalltip);

            Map<String, IToken> alreadyChecked = new HashMap<String, IToken>();

            boolean importsTip = false;

            if (importsTipper.importsTipperStr.length() != 0) {
                //code completion in imports
                request.isInCalltip = false; //if found after (, but in an import, it is not a calltip!
                request.isInMethodKeywordParam = false; //if found after (, but in an import, it is not a calltip!
                importsTip = doImportCompletion(request, astManager, tokensList, importsTipper);

            } else if (trimmed.length() > 0 && request.activationToken.indexOf('.') != -1) {
                //code completion for a token
                doTokenCompletion(request, astManager, tokensList, trimmed, state);
                handleKeywordParam(request, line, alreadyChecked);

            } else {
                //go to globals
                doGlobalsCompletion(request, astManager, tokensList, state);

                //At this point, after doing the globals completion, we may also need to check if we need to show
                //keyword parameters to the user.
                handleKeywordParam(request, line, alreadyChecked);
            }

            String lowerCaseQual = request.qualifier.toLowerCase();
            if (lowerCaseQual.length() >= PyCodeCompletionPreferencesPage.getArgumentsDeepAnalysisNChars()) {
                //this can take some time on the analysis, so, let's let the user choose on how many chars does he
                //want to do the analysis...
                state.pushFindResolveImportMemoryCtx();
                try {
                    for (Iterator<Object> it = tokensList.listIterator(); it.hasNext();) {
                        Object o = it.next();
                        if (o instanceof IToken) {
                            it.remove(); // always remove the tokens from the list (they'll be re-added later once they are filtered)

                            IToken initialToken = (IToken) o;

                            IToken token = initialToken;
                            String strRep = token.getRepresentation();
                            IToken prev = alreadyChecked.get(strRep);

                            if (prev != null) {
                                if (prev.getArgs().length() != 0) {
                                    continue; // we already have a version with args... just keep going
                                }
                            }

                            if (!strRep.toLowerCase().startsWith(lowerCaseQual)) {
                                //just re-add it if we're going to actually use it (depending on the qualifier)
                                continue;
                            }

                            IModule current = request.getModule();

                            while (token.isImportFrom()) {
                                //we'll only add it here if it is an import from (so, set the flag to false for the outer add)

                                if (token.getArgs().length() > 0) {
View Full Code Here

        if (DebugSettings.DEBUG_CODE_COMPLETION) {
            Log.toLogFile(this, "astManager.getCompletionsForToken");
            Log.addLogLevel();
        }

        IModule module = request.getModule();
        if (module == null) {
            Log.remLogLevel();
            Log.toLogFile(this, "END astManager.getCompletionsForToken: null module");
            return;
        }
View Full Code Here

TOP

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

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.