summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/ClassDeclaration.java
blob: d5894f9d1bb8f3e461639bdc8b2422b253462690 (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
/*
 * ClassDeclaration.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 ClassDeclaration class presents class declaraton node of parse tree.
 * 
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @see io.devnulllabs.openjava.ptree.NonLeaf
 * @see io.devnulllabs.openjava.ptree.TypeDeclaration
 */
public class ClassDeclaration extends NonLeaf implements Statement, MemberDeclaration, ParseTree {
    private String[] metaclazz = null;
    private Hashtable suffixes = null;
    private boolean _isInterface = false;

    /**
     * Constructs ClassDeclaration from its elements.
     * 
     * @param modiflist
     *            modifier list
     * @param name
     *            class name
     * @param zuper
     *            arg zuper is null means class decl has no super class
     * @param interfacelist
     *            if class decl has no implemants, arg interfacelist should be
     *            set an empty list
     * @param fieldlist
     *            field declaration list (body of new class)
     */
    public ClassDeclaration(ModifierList modiflist, String name, TypeName[] baseclasses, TypeName[] ifaces,
            MemberDeclarationList fieldlist) {
        this(modiflist, name, baseclasses, ifaces, fieldlist, true);
    }

    public ClassDeclaration(ModifierList modiflist, String name, TypeName[] baseclasses, TypeName[] ifaces,
            MemberDeclarationList fieldlist, boolean is_class) {
        super();
        baseclasses = (baseclasses == null) ? new TypeName[0] : baseclasses;
        ifaces = (ifaces == null) ? new TypeName[0] : ifaces;
        set(modiflist, name, baseclasses, ifaces, fieldlist);
        this._isInterface = (!is_class);
    }

    public boolean isInterface() {
        return this._isInterface;
    }

    public void beInterface(boolean isInterface) {
        this._isInterface = isInterface;
    }

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

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

    /**
     * Gets the class name.
     * 
     * @return class name
     */
    public String getName() {
        return (String) elementAt(1);
    }

    /**
     * Sets a class name in extends clause.
     * 
     * @param name
     *            name to set
     */
    public void setName(String name) {
        setElementAt(name, 1);
    }

    /**
     * Gets the classes in 'extends' clause. This causes
     * 
     * @return if class decl has no extends, this returns null otherwise returns
     *         the name of the super class.
     */
    public TypeName[] getBaseclasses() {
        return (TypeName[]) elementAt(2);
    }

    /**
     * Gets base classes in 'extends' clause.
     * 
     * @return if class decl has no extends, this returns null otherwise returns
     *         the name of the super class.
     */
    public TypeName getBaseclass() {
        TypeName[] bases = getBaseclasses();
        if (bases.length == 0)
            return null;
        return bases[0];
    }

    /**
     * Sets super class name
     * 
     * @param ctypes
     *            class types to set
     */
    public void setBaseclasses(TypeName[] ctypes) {
        setElementAt(ctypes, 2);
    }

    /**
     * Sets super class name
     * 
     * @param ctype
     *            class type to set
     */
    public void setBaseclass(TypeName ctype) {
        setElementAt(new TypeName[] { ctype }, 2);
    }

    /**
     * Gets interface name list
     * 
     * @return there is no implemented class, getInterfaceList returns an empty
     *         list
     */
    public TypeName[] getInterfaces() {
        return (TypeName[]) elementAt(3);
    }

    /**
     * Sets interface name list
     * 
     * @param ctlist
     *            class type list to set
     */
    public void setInterfaces(TypeName[] ctlist) {
        setElementAt(ctlist, 3);
    }

    /**
     * Gets class body
     * 
     * @return return an field declaration list as this class body.
     */
    public MemberDeclarationList getBody() {
        return (MemberDeclarationList) elementAt(4);
    }

    /**
     * Sets class body
     * 
     * @param body
     *            member declaration list to set as this class body.
     */
    public void setBody(MemberDeclarationList mdlist) {
        setElementAt(mdlist, 4);
    }

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

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

    public void setMetaclass(String metaclazz) {
        this.metaclazz = new String[] { metaclazz };
    }

    public void setMetaclass(String[] metaclazz) {
        this.metaclazz = metaclazz;
    }

    public String getMetaclass() {
        if (metaclazz == null || metaclazz.length == 0)
            return null;
        return this.metaclazz[0];
    }

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