summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/Parameter.java
blob: 71637a7de4d5c79b1edeb4ab76b9cf139e432659 (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
/*
 * Parameter.java 1.0
 *
 * This interface is made to type ptree-node into
 * the parameter in the body of class.
 *
 * 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:  Sep 29, 1997
 * @author  Michiaki Tatsubori
 */
package io.devnulllabs.openjava.ptree;

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

/**
 * The Parameter class represents parameter node of parse tree.
 * Modifiers of parameter are supported from JDK 1.1.
 * The code like:
 * <br><blockquote><pre>
 *     void test( final int i ){
 *         ....
 *     }
 * </pre></blockquote><br>
 * is allowed from JDK 1.1.
 *
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @see io.devnulllabs.openjava.ptree.NonLeaf
 * @see io.devnulllabs.openjava.ptree.ModifierList
 */
public class Parameter extends NonLeaf {

    /**
     * Allocates a new object.
     *
     * @param  modfiers  modifier list of the new parameter
     * @param  type_specifier  type specifier includes array dimension info
     * @param  declname  the parameter's name, including no array dim.
     */
    public Parameter(
        ModifierList modiflist,
        TypeName type_specifier,
        String declname) {
        super();
        if (modiflist == null) {
            modiflist = new ModifierList();
        }
        set(modiflist, type_specifier, declname);
    }

    /**
     * Allocates a new object.
     *
     *
     * @param type_specifier type specifier includes array dimension info
     * @param declname the parameter's name, also includes array dim
     *        arg modfier is null means parameter has no modifier
     */
    public Parameter(TypeName type_specifier, String declname) {
        this(new ModifierList(), type_specifier, declname);
    }

    /**
     * Gets the modifiers of this parameter.
     *
     * @return the modfiers.
     */
    public ModifierList getModifiers() {
        return (ModifierList) elementAt(0);
    }

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

    /**
     * Gets the type specifier of this parameter.
     *
     * @return the type specifier.
     */
    public TypeName getTypeSpecifier() {
        return (TypeName) elementAt(1);
    }

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

    /**
     * Gets the variable name of this parameter.
     *
     * @return the variable name.
     */
    public String getVariable() {
        return (String) elementAt(2);
    }

    /**
     * Sets the variable name of this parameter.
     *
     * @param  varname  the variable name to set.
     */
    public void setVariable(String varname) {
        setElementAt(varname, 2);
    }

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

}