Examples of ICodeCompletionASTManager


Examples of org.python.pydev.core.ICodeCompletionASTManager

            // if it's a file, we want to show the classes and methods
            PythonFile file = (PythonFile) wrappedResourceParent;
            if (PythonPathHelper.isValidSourceFile(file.getActualObject())) {

                if (nature != null) {
                    ICodeCompletionASTManager astManager = nature.getAstManager();
                    //the nature may still not be completely restored...
                    if (astManager != null) {
                        IModulesManager modulesManager = astManager.getModulesManager();

                        if (modulesManager instanceof IProjectModulesManager) {
                            IProjectModulesManager projectModulesManager = (IProjectModulesManager) modulesManager;
                            String moduleName = projectModulesManager.resolveModuleInDirectManager(file
                                    .getActualObject());
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

                    if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                        AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
                        IProject project = projectInterpreterInfo.getProject();
                        PythonNature nature = PythonNature.getPythonNature(project);
                        if (nature != null) {
                            ICodeCompletionASTManager astManager = nature.getAstManager();
                            if (astManager != null) {
                                modulesManager = astManager.getModulesManager();
                            }

                        }
                    } else if (additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                        AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additionalInfo;
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

            return;
        }
        if (nature == null) {
            return;
        }
        ICodeCompletionASTManager astManager = nature.getAstManager();
        if (astManager == null) {
            return;
        }

        if (markerAnnotation.position == null) {
            return;
        }
        int start = markerAnnotation.position.offset;
        int end = start + markerAnnotation.position.length;
        ps.setSelection(start, end);
        String markerContents = ps.getSelectedText();
        String fullRep = ps.getFullRepAfterSelection();

        ImageCache imageCache = PydevPlugin.getImageCache();
        Image packageImage = null;
        if (imageCache != null) { //making tests
            packageImage = imageCache.get(UIConstants.COMPLETION_PACKAGE_ICON);
        }
        IModulesManager projectModulesManager = astManager.getModulesManager();
        Set<String> allModules = projectModulesManager.getAllModuleNames(true, markerContents.toLowerCase());

        //when an undefined variable is found, we can:
        // - add an auto import (if it is a class or a method or some global attribute)
        // - declare it as a local or global variable
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

            IPythonNature nature = getPythonNature();
            if (nature == null) {
                lastModifiedTimeCached = 0;
                return "None";
            }
            ICodeCompletionASTManager astManager = nature.getAstManager();
            if (astManager == null) {
                lastModifiedTimeCached = 0;
                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 {
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

        boolean wasResolved = false;
        Tuple3<IModule, String, IToken> modTok = null;
        String checkForToken = "";
        if (token instanceof SourceToken) {

            ICodeCompletionASTManager astManager = nature.getAstManager();
            ICompletionState state = CompletionStateFactory.getEmptyCompletionState(token.getRepresentation(), nature,
                    completionCache);

            try {
                modTok = astManager.findOnImportedMods(new IToken[] { token }, state, moduleName, visitor.current);
            } catch (CompletionRecursionException e1) {
                modTok = null;//unable to resolve it
            }
            if (modTok != null && modTok.o1 != null) {
                checkForToken = modTok.o2;
                if (modTok.o2.length() == 0) {
                    wasResolved = true;

                } else {
                    try {
                        checkForToken = AbstractASTManager.getTokToSearchInOtherModule(modTok);
                        if (astManager.getRepInModule(modTok.o1, checkForToken, nature) != null) {
                            wasResolved = true;
                        }
                    } catch (CompletionRecursionException e) {
                        //not resolved...
                    }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

                                labelErrorSettings
                                        .setText("Please specify the name of the module (i.e.: myapp.settings)");
                                return;
                            }

                            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.",
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

        return true;
    }

    @Override
    protected void calculateChildren() throws MisconfigurationException {
        ICodeCompletionASTManager astManager = nature.getAstManager();
        if (astManager == null) {
            addLeaf("AST manager == null (should happen only in the plugin initialization) -- skipping other checks.");
            return;
        }

        IModulesManager projectModulesManager = astManager.getModulesManager();
        if (projectModulesManager == null) {
            addLeaf("Modules manager == null (should happen only in the plugin initialization) -- skipping other checks.");
            return;
        }
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

                List<ItemPointer> pointers = new ArrayList<ItemPointer>();

                CompletionCache completionCache = new CompletionCache();
                for (IPythonNature pythonNature : pythonNatures) {
                    //try to find in one of the natures...
                    ICodeCompletionASTManager astManager = pythonNature.getAstManager();
                    if (astManager == null) {
                        continue;
                    }
                    AnalysisPlugin.getDefinitionFromIInfo(pointers, astManager, pythonNature, entry, completionCache);
                    if (pointers.size() > 0) {
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

                                    state.setIsInCalltip(false);

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

                                    ICodeCompletionASTManager astManager = pythonNature.getAstManager();
                                    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) {
                                    //if we already have the args, there's also no reason to do it (that's what we'll do here)
                                    break;
                                }
                                ICompletionState s = state.getCopyForResolveImportWithActTok(token.getRepresentation());
                                s.checkFindResolveImportMemory(token);

                                ImmutableTuple<IModule, IToken> modTok = astManager.resolveImport(s, token, current);
                                IToken token2 = modTok.o2;
                                current = modTok.o1;
                                if (token2 != null && initialToken != token2) {
                                    String args = token2.getArgs();
                                    if (args.length() > 0) {
View Full Code Here

Examples of org.python.pydev.core.ICodeCompletionASTManager

                        if (d.bases[i] instanceof Name) {
                            Name n = (Name) d.bases[i];
                            state.setActivationToken(n.id);
                            IToken[] completions;
                            try {
                                ICodeCompletionASTManager astManager = request.nature.getAstManager();
                                IModule module = request.getModule();
                                if (module != null) {
                                    completions = astManager.getCompletionsForModule(module, state, true, true);
                                    for (int j = 0; j < completions.length; j++) {
                                        theList.add(completions[j]);
                                    }
                                }
                            } catch (CompletionRecursionException e) {
                                //ok...
                            }
                        }
                    }
                } else {
                    //ok, get the completions for the class, only thing we have to take care now is that we may
                    //not have only 'self' for completion, but something like self.foo.
                    //so, let's analyze our activation token to see what should we do.

                    String trimmed = request.activationToken.replace('.', ' ').trim();
                    String[] actTokStrs = trimmed.split(" ");
                    if (actTokStrs.length == 0 || (!actTokStrs[0].equals("self") && !actTokStrs[0].equals("cls"))) {
                        throw new AssertionError(
                                "We need to have at least one token (self or cls) for doing completions in the class.");
                    }

                    if (actTokStrs.length == 1) {
                        //ok, it's just really self, let's get on to get the completions
                        state.setActivationToken(NodeUtils.getNameFromNameTok((NameTok) d.name));
                        try {
                            ICodeCompletionASTManager astManager = request.nature.getAstManager();
                            IModule module = request.getModule();
                            IToken[] completions = astManager.getCompletionsForModule(module, state, true, true);
                            for (int j = 0; j < completions.length; j++) {
                                theList.add(completions[j]);
                            }
                        } catch (CompletionRecursionException e) {
                            //ok
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.