01: /*
02: * Copyright 2006 Ethan Nicholas. All rights reserved.
03: * Use is subject to license terms.
04: */
05: package jaxx.compiler;
06:
07: /** Represents an argument to a <code>JavaMethod</code>.
08: *
09: *@see JavaMethod
10: */
11: public class JavaArgument {
12: private String name;
13: private String type;
14: private boolean isFinal;
15:
16: /** Creates a new <code>JavaArgument</code> with the specified name and type. For example, the method <code>main()</code>
17: * might have a <code>JavaArgument</code> with a name of <code>"arg"</code> and a type of <code>"java.lang.String[]"</code>.
18: *
19: *@param type the argument's type, as it would appear in Java source code
20: *@param name the argument's name
21: */
22: public JavaArgument(String type, String name) {
23: this (type, name, false);
24: }
25:
26: /** Creates a new <code>JavaArgument</code> with the specified name, type, and finality. For example, the method <code>main()</code>
27: * might have a <code>JavaArgument</code> with a name of <code>"arg"</code> and a type of <code>"java.lang.String[]"</code>. The
28: * <code>isFinal</code> parameter allows the presence of the <code>final</code> keyword on the argument to be controlled.
29: *
30: *@param type the argument's type, as it would appear in Java source code
31: *@param name the argument's name
32: *@param isFinal <code>true</code> if the argument should be marked final
33: */
34: public JavaArgument(String type, String name, boolean isFinal) {
35: this .type = type;
36: this .name = name;
37: this .isFinal = isFinal;
38: }
39:
40: /** Returns the argument's name.
41: *
42: *@return the name of the argument
43: */
44: public String getName() {
45: return name;
46: }
47:
48: /** Returns the argument's type as it would be represented in Java source code.
49: *
50: *@return the argument's type
51: */
52: public String getType() {
53: return type;
54: }
55:
56: /** Returns <code>true</code> if the <code>final</code> keyword should appear before the argument.
57: *
58: *@return <code>true</code> if the argument is final
59: */
60: public boolean isFinal() {
61: return isFinal;
62: }
63:
64: /** Returns the Java source code for this argument.
65: *
66: *@return the Java source code for this argument
67: */
68: public String toString() {
69: String result = type + ' ' + name;
70: if (isFinal)
71: return "final " + result;
72: else
73: return result;
74: }
75: }
|