Package org.python.pydev.parser.visitors.scope

Examples of org.python.pydev.parser.visitors.scope.SequencialASTIteratorVisitor


        SimpleNode element = it.next();

        String dottedActTok = activationToken + '.';
        //ok, that's the scope we have to analyze
        SequencialASTIteratorVisitor visitor = SequencialASTIteratorVisitor.create(element);

        ArrayList<Class> classes = new ArrayList<Class>(2);
        if (addAttributeAccess) {
            classes.add(Attribute.class);

        }
        if (addLocalsFromHasAttr) {
            classes.add(Call.class);
        }
        Iterator<ASTEntry> iterator = visitor.getIterator(classes.toArray(new Class[classes.size()]));

        while (iterator.hasNext()) {
            ASTEntry entry = iterator.next();
            if (entry.node instanceof Attribute) {
                String rep = NodeUtils.getFullRepresentationString(entry.node);
View Full Code Here


            return ret;
        }
        SimpleNode element = it.next();

        //ok, that's the scope we have to analyze
        SequencialASTIteratorVisitor visitor = SequencialASTIteratorVisitor.create(element);
        Iterator<ASTEntry> iterator = visitor.getIterator(Assert.class);

        while (iterator.hasNext()) {
            ASTEntry entry = iterator.next();
            Assert ass = (Assert) entry.node;
            if (ass.test instanceof Call) {
View Full Code Here

     * @return a list of ast entries that are found inside strings.
     */
    public static List<ASTEntry> getStringOccurrences(final String occurencesFor, SimpleNode simpleNode) {
        final List<ASTEntry> ret = new ArrayList<ASTEntry>();

        SequencialASTIteratorVisitor visitor = new SequencialASTIteratorVisitor() {
            @Override
            public Object visitStr(Str node) throws Exception {
                String str = NodeUtils.getStringToPrint(node);
                List<Name> names = checkSimpleNodeForTokenMatch(occurencesFor, new ArrayList<Name>(), node, str);
                for (Name name : names) {
View Full Code Here

     * @return a list of ast entries that are found inside comments.
     */
    public static List<ASTEntry> getCommentOccurrences(final String occurencesFor, SimpleNode simpleNode) {
        final List<ASTEntry> ret = new ArrayList<ASTEntry>();

        SequencialASTIteratorVisitor visitor = new SequencialASTIteratorVisitor() {
            @Override
            protected Object unhandled_node(SimpleNode node) throws Exception {
                Object r = super.unhandled_node(node);
                //now, we have to check it for occurrences in comments and strings too... (and create
                //names for those)
View Full Code Here

     */
    public static List<ASTEntry> getLocalOccurrences(final String occurencesFor, SimpleNode simpleNode,
            final boolean onlyFirstAttribPart) {
        List<ASTEntry> ret = new ArrayList<ASTEntry>();

        SequencialASTIteratorVisitor visitor = new SequencialASTIteratorVisitor() {

            @Override
            public Object visitAttribute(Attribute node) throws Exception {
                if (onlyFirstAttribPart) {
                    //this will visit the attribute parts if call, subscript, etc.
                    AbstractScopeAnalyzerVisitor.visitNeededAttributeParts(node, this);

                    List<SimpleNode> attributeParts = NodeUtils.getAttributeParts(node);
                    atomic(attributeParts.get(0)); //an attribute should always have many parts
                    traverse(attributeParts.get(0));
                    return null;
                } else {
                    return super.visitAttribute(node);
                }
            }
        };
        if (simpleNode instanceof FunctionDef) {
            //all that because we don't want to visit the name of the function if we've started in a function scope
            FunctionDef d = (FunctionDef) simpleNode;
            try {
                //decorators
                if (d.decs != null) {
                    for (decoratorsType dec : d.decs) {
                        if (dec != null) {
                            dec.accept(visitor);
                        }
                    }
                }

                //don't do d.args directly because we don't want to check the 'defaults'
                if (d.args != null) {
                    if (d.args.args != null) {
                        for (exprType arg : d.args.args) {
                            arg.accept(visitor);
                        }
                    }
                    if (d.args.vararg != null) {
                        d.args.vararg.accept(visitor);
                    }
                    if (d.args.kwarg != null) {
                        d.args.kwarg.accept(visitor);
                    }
                    //visit keyword only args
                    if (d.args.kwonlyargs != null) {
                        for (exprType expr : d.args.kwonlyargs) {
                            expr.accept(visitor);
                        }
                    }

                }

                //and at last... the body
                if (d.body != null) {
                    for (stmtType exp : d.body) {
                        if (exp != null) {
                            exp.accept(visitor);
                        }
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {

            try {
                simpleNode.accept(visitor);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        Iterator<ASTEntry> iterator = visitor.getNamesIterator();
        while (iterator.hasNext()) {
            ASTEntry entry = iterator.next();
            //SimpleNode nameNode = entry.getNameNode();
            //if(!occurencesFor.isParamRename){
            //    if(nameNode instanceof NameTok){
View Full Code Here

     * we will return the one correspondent to self.aa)
     */
    public static List<ASTEntry> getAttributeOccurrences(String occurencesFor, SimpleNode simpleNode) {
        List<ASTEntry> ret = new ArrayList<ASTEntry>();

        SequencialASTIteratorVisitor visitor = SequencialASTIteratorVisitor.create(simpleNode);
        Iterator<ASTEntry> iterator = visitor.getIterator(Attribute.class);

        while (iterator.hasNext()) {
            ASTEntry entry = iterator.next();
            String rep = NodeUtils.getFullRepresentationString(entry.node, true);
            if (rep.equals(occurencesFor)) {
View Full Code Here

    /**
     * @param simpleNode this is the module with the AST that has the function definition
     * @return the function definition that matches the original definition as an ASTEntry
     */
    private ASTEntry getOriginalClassDefInAst(SimpleNode simpleNode) {
        SequencialASTIteratorVisitor visitor = SequencialASTIteratorVisitor.create(simpleNode);
        Iterator<ASTEntry> it = visitor.getIterator(ClassDef.class);
        ASTEntry classDefEntry = null;
        while (it.hasNext()) {
            classDefEntry = it.next();

            if (classDefEntry.node.beginLine == this.definition.ast.beginLine
View Full Code Here

        node = (Module) parseLegalDocStr("a.b.c.d()");
        exprType callAttr = NodeUtils.makeAttribute("a.b.c.d()");
        assertEquals(((Expr) node.body[0]).value.toString(), callAttr.toString());

        SequencialASTIteratorVisitor visitor = SequencialASTIteratorVisitor
                .create(parseLegalDocStr("print a.b.c().d.__class__"));

        Iterator<ASTEntry> iterator = visitor.getIterator();
        iterator.next(); //Module
        iterator.next(); //Print
        ASTEntry entry = iterator.next(); //Attribute
        assertEquals("a.b.c", NodeUtils.getFullRepresentationString(entry.node));

        visitor = SequencialASTIteratorVisitor.create(parseLegalDocStr("'r.a.s.b'.join('a')"));
        iterator = visitor.getIterator();
        iterator.next(); //Module
        iterator.next(); //Expr
        entry = iterator.next(); //Attribute
        assertEquals("str.join", NodeUtils.getFullRepresentationString(entry.node));

        visitor = SequencialASTIteratorVisitor.create(parseLegalDocStr("print aa.bbb.cccc[comp.id].hasSimulate"));
        iterator = visitor.getIterator();
        iterator.next(); //Module
        iterator.next(); //Expr
        entry = iterator.next(); //Attribute
        assertEquals("aa.bbb.cccc", NodeUtils.getFullRepresentationString(entry.node));
    }
View Full Code Here

            long curr = System.currentTimeMillis();
            SimpleNode node = parseLegalDocStr(s);

            //uncomment line below to see the time for parsing
            //System.out.println(StringUtils.format("Took: %s secs", (System.currentTimeMillis()-curr)/1000.0));
            SequencialASTIteratorVisitor visitor = SequencialASTIteratorVisitor.create(node);

            ASTEntry entry = visitor.getAsList(Str.class).get(0);
            String s0 = ((Str) entry.node).s;
            assertEquals(42, entry.node.beginLine);
            assertEquals(8, entry.node.beginColumn);
            assertTrue("Expecting big string. Received" + s0, s0.length() > 100);
View Full Code Here

                //ok, we're in a class, the first thing is to add the reference to the function just gotten
                ret.add(new ASTEntry(functionDefEntry, ((FunctionDef) functionDefEntry.node).name));

                //get the entry for the self.xxx that access that attribute in the class
                SequencialASTIteratorVisitor classVisitor = SequencialASTIteratorVisitor.create(parentNode);
                Iterator<ASTEntry> it = classVisitor.getIterator(Attribute.class);
                while (it.hasNext()) {
                    ASTEntry entry = it.next();
                    List<SimpleNode> parts = NodeUtils.getAttributeParts((Attribute) entry.node);
                    if (!(parts.get(1) instanceof Attribute)) {
                        final String rep0 = NodeUtils.getRepresentationString(parts.get(0));
View Full Code Here

TOP

Related Classes of org.python.pydev.parser.visitors.scope.SequencialASTIteratorVisitor

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.