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.17 $
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 private boolean closureShare=false;
69
70 public Parameter(ClassNode type, String name) {
71 this.name = name;
72 this.setType(type);
73 this.hasDefaultValue = false;
74 }
75
76 public Parameter(ClassNode type, String name, Expression defaultValue) {
77 this(type,name);
78 this.defaultValue = defaultValue;
79 this.hasDefaultValue = true;
80 }
81
82 public String toString() {
83 return super.toString() + "[name:" + name + ((type == null) ? "" : " type: " + type.getName()) + ", hasDefaultValue: " + this.hasInitialExpression() + "]";
84 }
85
86 public String getName() {
87 return name;
88 }
89
90 public ClassNode getType() {
91 return type;
92 }
93
94 public void setType(ClassNode type) {
95 this.type = type;
96 dynamicTyped |= type==ClassHelper.DYNAMIC_TYPE;
97 }
98
99 public boolean hasInitialExpression() {
100 return this.hasDefaultValue;
101 }
102
103 /***
104 * @return the default value expression for this parameter or null if
105 * no default value is specified
106 */
107 public Expression getInitialExpression() {
108 return defaultValue;
109 }
110
111 public void setInitialExpression(Expression init) {
112 defaultValue = init;
113 }
114
115 public boolean isInStaticContext() {
116 return inStaticContext;
117 }
118
119 public void setInStaticContext(boolean inStaticContext) {
120 this.inStaticContext = inStaticContext;
121 }
122
123 public boolean isDynamicTyped() {
124 return dynamicTyped;
125 }
126
127 public boolean isClosureSharedVariable() {
128 return closureShare;
129 }
130
131 public void setClosureSharedVariable(boolean inClosure) {
132 closureShare = inClosure;
133 }
134 }