summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/ConstructorDeclaration.java
blob: dacd01e062d771845e33779576ca36a32b9d4528 (plain)
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
229
230
231
/*
 * ConstructorDeclaration.java 1.0
 *
 *
 * Jun 20, 1997 by mich
 * Sep 29, 1997 by bv
 * Oct 10, 1997 by mich
 *
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @version 1.0 last updated:  Oct 10, 1997
 * @author  Michiaki Tatsubori
 */
package io.devnulllabs.openjava.ptree;

import java.util.Hashtable;

import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;

/**
 * The <code>ConstructorDeclaration</code> class represents
 * constructor declaration node of the parse tree.
 *
 * @see io.devnulllabs.openjava.ptree.NonLeaf
 * @see io.devnulllabs.openjava.ptree.MemberDeclaration
 * @see io.devnulllabs.openjava.ptree.ModifierList
 * @see io.devnulllabs.openjava.ptree.ParameterList
 * @see io.devnulllabs.openjava.ptree.TypeName
 * @see io.devnulllabs.openjava.ptree.ConstructorInvocation
 * @see io.devnulllabs.openjava.ptree.StatementList
 */
public class ConstructorDeclaration
    extends NonLeaf
    implements MemberDeclaration {

    private Hashtable suffixes = null;

    /**
     * Constructs new ConstructorDeclaration from its elements.
     *
     * @param  modiflist  modifier list, if it has no modifier list
     *                    then thes arg is set empty list.
     * @param  name  name of this constructor.
     * @param  params  parameter list
     * @param  throwlist  throw type list, if there is no throws
     *                    then this arg is set empty list
     * @param  scstmt  statement which calls another constructor
     *                 if this is null, it means no another constructor
     *                 call exists.
     * @param  stmtlist  statement list of this constructor body.
     *                   if this is null, it means method body is with
     *                   only semi colon.
     */
    public ConstructorDeclaration(
        ModifierList modiflist,
        String name,
        ParameterList params,
        TypeName[] throwlist,
        ConstructorInvocation scstmt,
        StatementList stmtlist) {
        super();
        if (modiflist == null)
            modiflist = new ModifierList();
        if (params == null)
            params = new ParameterList();
        if (throwlist == null)
            throwlist = new TypeName[0];
        set(modiflist, name, params, throwlist, scstmt, stmtlist);
    }

    /**
     * Constructs new ConstructorDeclaration from its elements.
     *
     * @param  modiflist  modifier list, if it has no modifier list
     *                    then thes arg is set empty list.
     * @param  name  name of this constructor.
     * @param  params  parameter list
     * @param  throwlist  throw type list, if there is no throws
     *                    then this arg is set empty list
     * @param  stmtlist  statement list of this constructor body.
     *                   if this is null, it means method body is with
     *                   only semi colon.
     */
    public ConstructorDeclaration(
        ModifierList modiflist,
        String name,
        ParameterList params,
        TypeName[] throwlist,
        StatementList stmtlist) {
        this(modiflist, name, params, throwlist, null, stmtlist);
    }

    /** for recursive copy */
    ConstructorDeclaration() {
        super();
    }

    /**
     * Gets modifier list.
     *
     * @return modifier list.
     */
    public ModifierList getModifiers() {
        return (ModifierList) elementAt(0);
    }

    /**
     * Sets modifier list.
     *
     * @param  modifs  modifier list.
     */
    public void setModifiers(ModifierList modifs) {
        if (modifs == null) {
            modifs = new ModifierList();
        }
        setElementAt(modifs, 0);
    }

    /**
     * Gets the name of this constructor node.
     *
     * @return constructor declarator node.
     */
    public String getName() {
        return (String) elementAt(1);
    }

    /**
     * Sets the name of this constructor node.
     *
     * @param  name  the name to be set.
     */
    public void setName(String name) {
        setElementAt(name, 1);
    }

    /**
     * Gets the parameter list.
     *
     * @return parameter list for constructor.
     */
    public ParameterList getParameters() {
        return (ParameterList) elementAt(2);
    }

    /**
     * Sets the parameter list.
     *
     * @param  params  parameterlist for constructor declarator node.
     */
    public void setParameters(ParameterList params) {
        if (params == null) {
            params = new ParameterList();
        }
        setElementAt(params, 2);
    }

    /**
     * Gets the class type list thrown by this constructor.
     *
     * @return class type list thrown by this constructor.
     */
    public TypeName[] getThrows() {
        return (TypeName[]) elementAt(3);
    }

    /**
     * Sets the class type list thrown by this constructor.
     *
     * @param  ctlist  class type list thrown by this constructor.
     */
    public void setThrows(TypeName[] ctlist) {
        if (ctlist == null) {
            ctlist = new TypeName[0];
        }
        setElementAt(ctlist, 3);
    }

    /**
     * Gets the special call statement.
     * Special call statement is like:
     * <br><blockquote><pre>
     *     super();
     * </pre></blockquote><br>
     *
     * @return  special call statement
     */
    public ConstructorInvocation getConstructorInvocation() {
        return (ConstructorInvocation) elementAt(4);
    }

    /**
     * Sets the special call statement.
     *
     * @param  scstmt  the special call statement to set
     * @see io.devnulllabs.openjava.ptree.ConstructorDeclaration#getConstructorInvocation()
     */
    public void setConstructorInvocation(ConstructorInvocation scstmt) {
        setElementAt(scstmt, 4);
    }

    /**
     * Gets the statement list of this constructor body.
     *
     * @return  the statement list of this constructor body.
     */
    public StatementList getBody() {
        return (StatementList) elementAt(5);
    }

    /**
     * Sets the statement list of this constructor body.
     *
     * @return  the statement list of this constructor body.
     */
    public void setBody(StatementList stmts) {
        setElementAt(stmts, 5);
    }

    public void setSuffixes(Hashtable suffixes) {
        this.suffixes = suffixes;
    }

    public Hashtable getSuffixes() {
        return this.suffixes;
    }

    public void accept(ParseTreeVisitor v) throws ParseTreeException {
        v.visit(this);
    }

}