File: SimpleNode.java

package info (click to toggle)
doctorj 5.0.0-5
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 6,164 kB
  • ctags: 3,453
  • sloc: java: 30,027; xml: 331; makefile: 81; sh: 61
file content (228 lines) | stat: -rw-r--r-- 6,319 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* Generated By:JJTree: Do not edit this line. SimpleNode.java */

package org.incava.java;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.incava.log.Log;


public class SimpleNode implements Node {
    protected Node parent;
    protected Node[] children;
    protected int id;
    protected JavaParser parser;

    protected Token first, last;
    protected JavadocNode javadoc;
    protected boolean javadocParsed;

    public SimpleNode(int i) {
        id = i;
        javadocParsed = false;
        javadoc = null;
    }

    public SimpleNode(JavaParser p, int i) {
        this(i);
        parser = p;
    }

    public JavadocNode getJavadoc()
    {
        if (!javadocParsed) {
            javadocParsed = true;

            Token st = first.specialToken;
            while (javadoc == null && st != null) {
                javadoc = JavadocNode.parse(st.image, st.beginLine, st.beginColumn);
                st = st.specialToken;
            }
        }
        return javadoc;
    }

    public void jjtOpen() {
        first = parser.getToken(1);	// new
    }

    public void jjtClose() {
        last = parser.getToken(0);	// new
    }

    public Token getFirstToken() { return first; } // new
    public Token getLastToken() { return last; }   // new
  
    public void jjtSetParent(Node n) { parent = n; }
    public Node jjtGetParent() { return parent; }

    public void jjtAddChild(Node n, int i) {
        if (children == null) {
            children = new Node[i + 1];
        } else if (i >= children.length) {
            Node c[] = new Node[i + 1];
            System.arraycopy(children, 0, c, 0, children.length);
            children = c;
        }
        children[i] = n;
    }

    public Node jjtGetChild(int i) {
        return children[i];
    }

    public int jjtGetNumChildren() {
        return (children == null) ? 0 : children.length;
    }

    /** Accept the visitor. **/
    public Object jjtAccept(JavaParserVisitor visitor, Object data) {
        return visitor.visit(this, data);
    }

    /** Accept the visitor. **/
    public Object childrenAccept(JavaParserVisitor visitor, Object data) {
        if (children != null) {
            for (int i = 0; i < children.length; ++i) {
                children[i].jjtAccept(visitor, data);
            }
        }
        return data;
    }

    /* You can override these two methods in subclasses of SimpleNode to
       customize the way the node appears when the tree is dumped.  If
       your output uses more than one line you should override
       toString(String), otherwise overriding toString() is probably all
       you need to do. */

    public String toString() { 
        return Java14ParserTreeConstants.jjtNodeName[id];
    }
    
    public void dump() 
    {
        dump("");
    }

    /**
     * Returns a list of children, both nodes and tokens.
     */
    public List getChildren() 
    {
        List list = new ArrayList();
        Token t1 = getFirstToken();
        Token t = new Token();
        t.next = t1;
        
        SimpleNode n;
        for (int ord = 0; ord < jjtGetNumChildren(); ord++) {
            n = (SimpleNode)jjtGetChild(ord);
            while (true) {
                t = t.next;
                if (t == n.getFirstToken()) 
                    break;
                list.add(t);
            }
            list.add(n);
            t = n.getLastToken();
        }

        while (t != getLastToken()) {
            t = t.next;
            list.add(t);
        }
        return list;
    }

    /**
     * Override this method if you want to customize how the node dumps out its
     * children.
     */
    protected void dump(String prefix) 
    {
        Token t1 = getFirstToken();
        Token t = new Token();
        t.next = t1;

        System.out.println(prefix + "<" + toString() + ">" + "[" + first.beginLine + ":" + first.beginColumn + ":" + last.endLine + ":" + last.endColumn + "] ");
        List children = getChildren();
        Iterator it = children.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof Token) {
                print(prefix, (Token)obj);
            }
            else {
                ((SimpleNode)obj).dump(prefix + "    ");
            }
        }
    }  
  
    protected void print(String prefix, Token t) 
    {
        Token st = t.specialToken;
        if (st != null) {
            while (st.specialToken != null) {
                st = st.specialToken;
            }
            
            while (st != null) {
                String s = st.toString().replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r");
                System.out.println(prefix + "    s[" + st.beginLine + ":" + st.beginColumn + ":" + st.endLine + ":" + st.endColumn + "] \"" + s + "\"");
                st = st.next;
            }
        }
        System.out.println(prefix + "    t[" + t.beginLine + ":" + t.beginColumn + ":" + t.endLine + ":" + t.endColumn + "] \"" + t + "\" (" + parser.getTokenKind(t) + ")");
    }

    public boolean hasPublicAccess()
    {
        return hasLeadingToken(Java14ParserConstants.PUBLIC);
    }

    public boolean isAbstract()
    {
        return hasLeadingToken(Java14ParserConstants.ABSTRACT);
    }

    public boolean hasProtectedAccess()
    {
        return hasLeadingToken(Java14ParserConstants.PROTECTED);
    }

    public boolean hasPackageAccess()
    {
        return !hasPublicAccess() && !hasProtectedAccess() && !hasPrivateAccess();
    }

    public boolean hasPrivateAccess()
    {
        return hasLeadingToken(Java14ParserConstants.PRIVATE);
    }

    /**
     * Returns whether this node has a matching token, occurring prior to any
     * non-tokens (i.e., before any child nodes).
     */
    public boolean hasLeadingToken(int tokenType)
    {
        List     children = getChildren();
        Iterator cit      = children.iterator();
        
        while (cit.hasNext()) {
            Object childObj = cit.next();
            if (childObj instanceof Token) {
                if (((Token)childObj).kind == tokenType) {
                    return true;
                }
            }
            else {
                break;
            }
        }
        return false;
    }

}