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

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


            // we have to check if this is a name we should ignore
            if (startsWithNamesToIgnore(g)) {
                int type = IAnalysisPreferences.TYPE_UNUSED_VARIABLE;

                if (g.tok instanceof SourceToken) {
                    SourceToken t = (SourceToken) g.tok;
                    SimpleNode ast = t.getAst();
                    if (ast instanceof NameTok) {
                        NameTok n = (NameTok) ast;
                        if (n.ctx == NameTok.KwArg || n.ctx == NameTok.VarArg || n.ctx == NameTok.KeywordName) {
                            type = IAnalysisPreferences.TYPE_UNUSED_PARAMETER;
                        }
View Full Code Here


    }

    private void calculateArgumentsWithParens() {
        if (argumentsWithParens == null) {
            if (token instanceof SourceToken) {
                SourceToken sourceToken = (SourceToken) token;
                SimpleNode ast = sourceToken.getAst();
                String fullArgs = NodeUtils.getFullArgs(ast);
                if (fullArgs.length() == 0) {
                    argumentsWithParens = null;
                } else {
                    argumentsWithParens = fullArgs;
View Full Code Here

            return computedInfo;
        }

        if (element != null) {
            if (element instanceof SourceToken) {
                SourceToken sourceToken = (SourceToken) element;
                SimpleNode ast = sourceToken.getAst();
                if (ast != null && (ast instanceof FunctionDef || ast instanceof ClassDef)) {
                    computedInfo = PyTextHover.printAst(null, ast);
                }
                if (computedInfo != null) {
                    return computedInfo;
View Full Code Here

                            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) {
                                        //put it into the map (may override previous if it didn't have args)
                                        initialToken.setArgs(args);
                                        initialToken.setDocStr(token2.getDocStr());
                                        if (initialToken instanceof SourceToken && token2 instanceof SourceToken) {
                                            SourceToken initialSourceToken = (SourceToken) initialToken;
                                            SourceToken token2SourceToken = (SourceToken) token2;
                                            initialSourceToken.setAst(token2SourceToken.getAst());
                                        }
                                        break;
                                    }
                                    if (token2 == null
                                            || (token2.equals(token) && token2.getArgs().equals(token.getArgs()) && token2
View Full Code Here

                            if (ignore.contains(nextToken)) {
                                continue;
                            }
                            String kwParam = nextToken + "=";
                            SimpleNode node = new NameTok(kwParam, NameTok.KwArg);
                            SourceToken sourceToken = new SourceToken(node, kwParam, "", "", "", IToken.TYPE_LOCAL);
                            sourceToken.setDocStr(fullArgs);
                            alreadyChecked.put(kwParam, sourceToken);
                        }
                    }
                }
            }
View Full Code Here

                new String[] {});

        Import importTok = new Import(new aliasType[] { new aliasType(new NameTok("unittest", NameTok.ImportModule),
                null) });
        this.imports = new ArrayList<IToken>();
        this.imports.add(new SourceToken(importTok, "unittest", "", "", ""));

        requestCompl("import unittest\nunittest", new String[] {}); //none because the import for unittest is already there
        requestCompl("import unittest\nunittes", new String[] {}); //the local import for unittest (won't actually show anything because we're only exercising the participant test)
        this.imports = null;
    }
View Full Code Here

            throws CompletionRecursionException {
        throw new RuntimeException("Not implemented");
    }

    public IToken[] getCompletionsForModule(IModule module, ICompletionState state) throws CompletionRecursionException {
        return new IToken[] { new SourceToken(new Name("True", Name.Store, true), "True", "", "", "__builtin__"),
                new SourceToken(new Name("False", Name.Store, true), "False", "", "", "__builtin__"), };
    }
View Full Code Here

                    //it may be declared as a global with a class defined in the local scope
                    IToken[] allLocalTokens = assignDefinition.scope.getAllLocalTokens();
                    for (IToken token : allLocalTokens) {
                        if (token.getRepresentation().equals(assignDefinition.value)) {
                            if (token instanceof SourceToken) {
                                SourceToken srcToken = (SourceToken) token;
                                if (srcToken.getAst() instanceof ClassDef) {
                                    List<IToken> classToks = ((SourceModule) assignDefinition.module).getClassToks(
                                            state, manager, srcToken.getAst());
                                    if (classToks.size() > 0) {
                                        lookForAssign = false;
                                        ret.addAll(classToks);
                                        break;
                                    }
View Full Code Here

            } catch (MisconfigurationException e) {
                Log.log(e);
                return ret;
            }
            for (IInfo info : tokensStartingWith) {
                ret.add(new SourceToken(null, info.getName(), null, null, info.getDeclaringModuleName(), info.getType()));
            }

        }
        return ret;
    }
View Full Code Here

        return new int[] { UNDEFINED, UNDEFINED };
    }

    public static boolean isClassDef(IToken element) {
        if (element instanceof SourceToken) {
            SourceToken token = (SourceToken) element;
            SimpleNode ast = token.getAst();
            if (ast instanceof ClassDef) {
                return true;
            }
        }
        return false;
View Full Code Here

TOP

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

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.