~vil/pydev/upstream

« back to all changes in this revision

Viewing changes to org.python.pydev.parser/src/org/python/pydev/parser/visitors/scope/EasyASTIteratorWithChildrenVisitor.java

  • Committer: Vladimír Lapáček
  • Date: 2006-08-30 18:38:44 UTC
  • Revision ID: vladimir.lapacek@gmail.com-20060830183844-f4d82c1239a7770a
Initial import of upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on Jun 10, 2006
 
3
 * @author Fabio
 
4
 */
 
5
package org.python.pydev.parser.visitors.scope;
 
6
 
 
7
import java.util.ArrayList;
 
8
 
 
9
public class EasyASTIteratorWithChildrenVisitor extends EasyAstIteratorBase{
 
10
 
 
11
    /**
 
12
     * Overriden because we deal only with the nodes with children in this iterator
 
13
     * 
 
14
     * @see org.python.pydev.parser.visitors.scope.EasyAstIteratorBase#createEntry()
 
15
     */
 
16
    @Override
 
17
    protected ASTEntry createEntry() {
 
18
        ASTEntry entry;
 
19
        if(parents.size() > 0){
 
20
            entry = new ASTEntryWithChildren((ASTEntryWithChildren) parents.peek());
 
21
        }else{
 
22
            entry = new ASTEntryWithChildren(null);
 
23
        }
 
24
        return entry;
 
25
    }
 
26
    
 
27
    /**
 
28
     * This implementation only adds it to the flattened list (nodes) if there is no parent.
 
29
     * Otherwise (if there is a parent), this implementation will add it to the parents children.
 
30
     * 
 
31
     * @see org.python.pydev.parser.visitors.scope.EasyAstIteratorBase#doAddNode(org.python.pydev.parser.visitors.scope.ASTEntry)
 
32
     */
 
33
    @Override
 
34
    protected void doAddNode(ASTEntry entry) {
 
35
        if(entry.parent == null){
 
36
            super.doAddNode(entry);
 
37
        }else{
 
38
            ASTEntryWithChildren parent = (ASTEntryWithChildren)entry.parent;
 
39
            if(parent.children == null){
 
40
                parent.children = new ArrayList<ASTEntryWithChildren>();
 
41
            }
 
42
            parent.children.add((ASTEntryWithChildren) entry);
 
43
        }
 
44
    }
 
45
}