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 package org.codehaus.groovy.ast;
47
48 import org.codehaus.groovy.ast.expr.*;
49
50 /***
51 * Represents a parameter on a constructor or method call. The type name is
52 * optional - it should be defaulted to java.lang.Object if unknown.
53 *
54 * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
55 * @version $Revision: 1.15 $
56 */
57 public class Parameter implements Variable {
58
59 public static final Parameter[] EMPTY_ARRAY = {
60 };
61
62 private ClassNode type;
63 private String name;
64 private boolean dynamicTyped;
65 private Expression defaultValue;
66 private boolean hasDefaultValue;
67 private boolean inStaticContext;
68
69 public Parameter(ClassNode type, String name) {
70 this.name = name;
71 this.setType(type);
72 this.hasDefaultValue = false;
73 }
74
75 public Parameter(ClassNode type, String name, Expression defaultValue) {
76 this(type,name);
77 this.defaultValue = defaultValue;
78 this.hasDefaultValue = true;
79 }
80
81 public String toString() {
82 return super.toString() + "[name:" + name + ((type == null) ? "" : " type: " + type.getName()) + ", hasDefaultValue: " + this.hasInitialExpression() + "]";
83 }
84
85 public String getName() {
86 return name;
87 }
88
89 public ClassNode getType() {
90 return type;
91 }
92
93 public void setType(ClassNode type) {
94 this.type = type;
95 dynamicTyped |= type==ClassHelper.DYNAMIC_TYPE;
96 }
97
98 public boolean hasInitialExpression() {
99 return this.hasDefaultValue;
100 }
101
102 /***
103 * @return the default value expression for this parameter or null if
104 * no default value is specified
105 */
106 public Expression getInitialExpression() {
107 return defaultValue;
108 }
109
110 public boolean isInStaticContext() {
111 return inStaticContext;
112 }
113
114 public void setInStaticContext(boolean inStaticContext) {
115 this.inStaticContext = inStaticContext;
116 }
117
118 public boolean isDynamicTyped() {
119 return dynamicTyped;
120 }
121 }