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

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


        String tokForSearchInOtherModule = tok;

        if (tok.length() > 0) {
            IToken sourceToken = modTok.o3;
            if (sourceToken instanceof SourceToken) {
                SourceToken sourceToken2 = (SourceToken) sourceToken;
                if (sourceToken2.getAst() instanceof ImportFrom) {
                    ImportFrom importFrom = (ImportFrom) sourceToken2.getAst();
                    if (importFrom.names.length > 0 && importFrom.names[0].asname != null) {
                        String originalRep = sourceToken.getOriginalRep();
                        tokForSearchInOtherModule = FullRepIterable.getLastPart(originalRep);
                    }
                }
View Full Code Here


        IModule mod = null;

        //ok, check if it is a token for the new import
        IPythonNature nature = state.getNature();
        if (importedModule instanceof SourceToken) {
            SourceToken token = (SourceToken) importedModule;

            if (token.isImportFrom()) {
                ImportFrom importFrom = (ImportFrom) token.getAst();
                int level = importFrom.level;
                if (level > 0) {
                    //ok, it must be treated as a relative import
                    //ok, it is the import added on python 2.5 (from .. import xxx)

                    String parentPackage = token.getParentPackage();
                    List<String> moduleParts = StringUtils.dotSplit(parentPackage);
                    String relative = null;
                    if (moduleParts.size() > level) {
                        relative = FullRepIterable.joinParts(moduleParts, moduleParts.size() - level);
                    }
View Full Code Here

    public GlobalModelVisitor(int visitWhat, String moduleName, boolean onlyAllowTokensIn__all__,
            boolean lookingInLocalContext) {
        this.visitWhat = visitWhat;
        this.moduleName = moduleName;
        this.onlyAllowTokensIn__all__ = onlyAllowTokensIn__all__;
        this.tokens.add(new SourceToken(new Name("__dict__", Name.Load, false), "__dict__", "", "", moduleName));
        if (moduleName != null && moduleName.endsWith("__init__")) {
            this.tokens.add(new SourceToken(new Name("__path__", Name.Load, false), "__path__", "", "", moduleName));
        }
        if (!lookingInLocalContext && ((this.visitWhat & GLOBAL_TOKENS) != 0)) {
            //__file__ is always available for any module
            this.tokens.add(new SourceToken(new Name("__file__", Name.Load, false), "__file__", "", "", moduleName));
            this.tokens.add(new SourceToken(new Name("__name__", Name.Load, false), "__name__", "", "", moduleName));
        }
    }
View Full Code Here

        }
    }

    @Override
    protected SourceToken addToken(SimpleNode node) {
        SourceToken tok = super.addToken(node);
        if (tok.getArgs().length() > 0) {
            this.repToTokenWithArgs.put(tok.getRepresentation(), tok);
        }
        return tok;
    }
View Full Code Here

     */
    public Object visitName(Name node) throws Exception {
        //when visiting the global namespace, we don't go into any inner scope.
        if ((this.visitWhat & GLOBAL_TOKENS) != 0) {
            if (node.ctx == Name.Store) {
                SourceToken added = addToken(node);
                if (lastAssign.size() > 0) {
                    Assign last = lastAssign.peek();
                    if (added.getRepresentation().equals("__all__") && __all__Assign == null) {
                        __all__ = added;
                        __all__Assign = last;
                        __all__AssignTargets = last.targets;
                    } else {
                        if (last.value != null && !(last.value instanceof Call)) {
                            //Checking if it's a Call, because we don't want to enter in the use-case:
                            //def method(a, b):
                            //   ...
                            //other = method()

                            String rep = NodeUtils.getRepresentationString(last.value);
                            if (rep != null) {
                                SourceToken methodTok = repToTokenWithArgs.get(rep);
                                if (methodTok != null) {
                                    //The use case is the following: we have a method and an assign to it:
                                    //def method(a, b):
                                    //   ...
                                    //other = method
View Full Code Here

    /**
     * @see org.python.pydev.parser.jython.ast.VisitorBase#visitStr(org.python.pydev.parser.jython.ast.Str)
     */
    public Object visitStr(Str node) throws Exception {
        if ((this.visitWhat & MODULE_DOCSTRING) != 0) {
            this.tokens.add(new SourceToken(node, node.s, "", "", moduleName));
        }
        return null;
    }
View Full Code Here

    private final Map<String, SourceToken> repToTokenWithArgs = new HashMap<String, SourceToken>();

    @Override
    protected SourceToken addToken(SimpleNode node) {
        SourceToken tok = super.addToken(node);
        if (tok.getArgs().length() > 0) {
            this.repToTokenWithArgs.put(tok.getRepresentation(), tok);
        }
        return tok;
    }
View Full Code Here

                FunctionDef f = (FunctionDef) element;
                final argumentsType args = f.args;

                for (int i = 0; i < args.args.length; i++) {
                    String s = NodeUtils.getRepresentationString(args.args[i]);
                    comps.add(new SourceToken(args.args[i], s, "", "", "", IToken.TYPE_PARAM));
                }
                if (args.vararg != null) {
                    String s = NodeUtils.getRepresentationString(args.vararg);
                    comps.add(new SourceToken(args.vararg, s, "", "", "", IToken.TYPE_PARAM));
                }

                if (args.kwarg != null) {
                    String s = NodeUtils.getRepresentationString(args.kwarg);
                    comps.add(new SourceToken(args.kwarg, s, "", "", "", IToken.TYPE_PARAM));
                }
                if (args.kwonlyargs != null) {
                    for (int i = 0; i < args.kwonlyargs.length; i++) {
                        String s = NodeUtils.getRepresentationString(args.kwonlyargs[i]);
                        comps.add(new SourceToken(args.kwonlyargs[i], s, "", "", "", IToken.TYPE_PARAM));
                    }
                }

                if (onlyArgs) {
                    continue;
                }
                body = f.body;
            }

            else if (element instanceof ClassDef && !iter.hasNext()) {
                ClassDef classDef = (ClassDef) element;
                body = classDef.body;
            }

            if (body != null) {
                try {
                    for (int i = 0; i < body.length; i++) {
                        GlobalModelVisitor visitor = new GlobalModelVisitor(GlobalModelVisitor.GLOBAL_TOKENS, "",
                                false, true);
                        stmtType stmt = body[i];
                        if (stmt == null) {
                            continue;
                        }
                        stmt.accept(visitor);
                        List<IToken> t = visitor.tokens;
                        for (Iterator<IToken> iterator = t.iterator(); iterator.hasNext();) {
                            SourceToken tok = (SourceToken) iterator.next();

                            //if it is found here, it is a local type
                            tok.type = IToken.TYPE_LOCAL;
                            if (tok.getAst().beginLine <= endLine) {
                                comps.add(tok);
                            }

                        }
                    }
View Full Code Here

            if (entry.node instanceof Attribute) {
                String rep = NodeUtils.getFullRepresentationString(entry.node);
                if (rep.startsWith(dottedActTok)) {
                    rep = rep.substring(dottedActTok.length());
                    if (NodeUtils.isValidNameRepresentation(rep)) { //that'd be something that can happen when trying to recreate the parsing
                        comps.add(new SourceToken(entry.node, FullRepIterable.getFirstPart(rep), "", "", "",
                                IToken.TYPE_OBJECT_FOUND_INTERFACE));
                    }
                }
            } else if (entry.node instanceof Call) {
                Call call = (Call) entry.node;
                if ("hasattr".equals(NodeUtils.getFullRepresentationString(call.func)) && call.args != null
                        && call.args.length == 2) {
                    String rep = NodeUtils.getFullRepresentationString(call.args[0]);
                    if (rep.equals(activationToken)) {
                        exprType node = call.args[1];
                        if (node instanceof Str) {
                            Str str = (Str) node;
                            String attrName = str.s;
                            if (NodeUtils.isValidNameRepresentation(attrName)) {
                                comps.add(new SourceToken(node, attrName, "", "", "",
                                        IToken.TYPE_OBJECT_FOUND_INTERFACE));
                            }
                        }
                    }
                }
View Full Code Here

            Map<String, List<IToken>> map = new HashMap<String, List<IToken>>();
            Set<ClassDef> classDefAsts = new HashSet<ClassDef>();

            for (IToken tok : ret) {
                if (tok instanceof SourceToken) {
                    SourceToken token = (SourceToken) tok;
                    SimpleNode ast = token.getAst();
                    if (ast instanceof ClassDef || ast instanceof FunctionDef) {
                        if (ast.parent instanceof ClassDef) {
                            ClassDef classDefAst = (ClassDef) ast.parent;
                            if (!alreadyTreated.contains(classDefAst)) {
                                classDefAsts.add(classDefAst);
                                alreadyTreated.add(classDefAst);
                            }
                        }
                    }

                } else if (tok instanceof CompiledToken) {
                    CompiledToken token = (CompiledToken) tok;
                    List<IToken> toks = map.get(token.getParentPackage());
                    if (toks == null) {
                        toks = new ArrayList<IToken>();
                        map.put(token.getParentPackage(), toks);
                    }
                    toks.add(token);
                } else {
                    throw new RuntimeException("Unexpected token:" + tok.getClass());
                }
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.