summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/FieldDeclaration.java
blob: e629ef36dd9a09bd72d101ee24ace0411b3f5ac4 (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
/*
 * FieldDeclaration.java 1.0
 *
 * Jun 11, 1997
 *
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @version 1.0 last updated: Sep 4, 1997
 * @author  Michiaki Tatsubori
 */
package io.devnulllabs.openjava.ptree;

import java.util.Hashtable;

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

/**
 * The FieldDeclaration class presents for node of parse tree.
 * FieldDeclaration
 *   :=  ModifierList TypeName VariableDeclarator SEMI
 *
 */
public class FieldDeclaration extends NonLeaf implements MemberDeclaration {
    private Hashtable suffixes = null;

    /**
     * Allocates this object
     *
     */
    public FieldDeclaration(
        ModifierList e0,
        TypeName e1,
        VariableDeclarator e2) {
        super();
        set(e0, e1, e2);
    }

    public FieldDeclaration(
        ModifierList e0,
        TypeName e1,
        String e2,
        VariableInitializer e3) {
        super();
        VariableDeclarator vd = new VariableDeclarator(e2, e3);
        set(e0, e1, vd);
    }

    /**
     * Is needed for recursive copy.
     */
    FieldDeclaration() {
        super();
    }

    /**
     * Gets modifier list of this field.
     *
     * @return  modifier list. if there is no modifiers, this returns
     *          an empty list.
     */
    public ModifierList getModifiers() {
        return (ModifierList) elementAt(0);
    }

    /**
     * Sets modifier list of this field.
     *
     * @param  modifs  modifiers to set
     */
    public void setModifiers(ModifierList modifs) {
        setElementAt(modifs, 0);
    }

    /**
     * Gets type specifier of this field variable.
     * Any modification on obtained objects is never reflected on
     * this object.
     *
     * @return  the type specifier for this field.
     */
    public TypeName getTypeSpecifier() {
        TypeName result;
        TypeName tn = (TypeName) elementAt(1);
        VariableDeclarator vd = (VariableDeclarator) elementAt(2);
        result = (TypeName) tn.makeCopy();
        result.addDimension(vd.getDimension());
        return result;
    }

    /**
     * Sets type specifier of this field variable.
     *
     * @param  tspec  type specifier to set
     */
    public void setTypeSpecifier(TypeName tspec) {
        setElementAt(tspec, 1);
    }

    /**
     * Gets variable declarator of this field
     *
     * @return  variable declarator
     * @see io.devnulllabs.openjava.ptree.VariableDeclarator
     * @deprecate
     */
    public VariableDeclarator getVariableDeclarator() {
        return (VariableDeclarator) elementAt(2);
    }

    /**
     * Sets type specifier of this field variable.
     *
     * @param  vdeclr  variable declarator to set
     * @deprecate
     */
    public void setVariableDeclarator(VariableDeclarator vdeclr) {
        setElementAt(vdeclr, 2);
    }

    /**
     * Gets variable name of this field.
     *
     * @return  identifier of field variable
     */
    public String getVariable() {
        return (String) getVariableDeclarator().getVariable();
    }

    /**
     * Gets variable name of this field.
     *
     * @return  identifier of field variable
     * @deprecate
     */
    public String getName() {
        return (String) getVariableDeclarator().getVariable();
    }

    /**
     * Sets variable name of this field.
     *
     * @param  name  identifier of field variable
     */
    public void setVariable(String name) {
        getVariableDeclarator().setVariable(name);
    }

    /**
     * Gets variable initializer of this field.
     *
     * @return  variable initializer
     */
    public VariableInitializer getInitializer() {
        return (VariableInitializer) getVariableDeclarator().getInitializer();
    }

    /**
     * Gets variable initializer of this field.
     *
     * @return  variable initializer
     */
    public void setInitializer(VariableInitializer vinit) {
        getVariableDeclarator().setInitializer(vinit);
    }

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

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

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

}