author | prr |
Fri, 26 Jan 2018 15:38:18 -0800 | |
changeset 48727 | 8a99ef2b3558 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
27837
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.codemodel.internal; |
|
27 |
||
28 |
import java.lang.annotation.Annotation; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Collection; |
|
32 |
import java.util.Collections; |
|
33 |
||
34 |
||
35 |
/** |
|
36 |
* Variables and fields. |
|
37 |
*/ |
|
38 |
||
39 |
public class JVar extends JExpressionImpl implements JDeclaration, JAssignmentTarget, JAnnotatable { |
|
40 |
||
41 |
/** |
|
42 |
* Modifiers. |
|
43 |
*/ |
|
44 |
private JMods mods; |
|
45 |
||
46 |
/** |
|
47 |
* JType of the variable |
|
48 |
*/ |
|
49 |
private JType type; |
|
50 |
||
51 |
/** |
|
52 |
* Name of the variable |
|
53 |
*/ |
|
54 |
private String name; |
|
55 |
||
56 |
/** |
|
57 |
* Initialization of the variable in its declaration |
|
58 |
*/ |
|
59 |
private JExpression init; |
|
60 |
||
61 |
/** |
|
62 |
* Annotations on this variable. Lazily created. |
|
63 |
*/ |
|
64 |
private List<JAnnotationUse> annotations = null; |
|
65 |
||
66 |
||
67 |
||
68 |
/** |
|
69 |
* JVar constructor |
|
70 |
* |
|
71 |
* @param type |
|
72 |
* Datatype of this variable |
|
73 |
* |
|
74 |
* @param name |
|
75 |
* Name of this variable |
|
76 |
* |
|
77 |
* @param init |
|
78 |
* Value to initialize this variable to |
|
79 |
*/ |
|
80 |
JVar(JMods mods, JType type, String name, JExpression init) { |
|
81 |
this.mods = mods; |
|
82 |
this.type = type; |
|
83 |
this.name = name; |
|
84 |
this.init = init; |
|
85 |
} |
|
86 |
||
87 |
||
88 |
/** |
|
89 |
* Initialize this variable |
|
90 |
* |
|
91 |
* @param init |
|
92 |
* JExpression to be used to initialize this field |
|
93 |
*/ |
|
94 |
public JVar init(JExpression init) { |
|
95 |
this.init = init; |
|
96 |
return this; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Get the name of this variable |
|
101 |
* |
|
102 |
* @return Name of the variable |
|
103 |
*/ |
|
104 |
public String name() { |
|
105 |
return name; |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Changes the name of this variable. |
|
110 |
*/ |
|
111 |
public void name(String name) { |
|
112 |
if(!JJavaName.isJavaIdentifier(name)) |
|
113 |
throw new IllegalArgumentException(); |
|
114 |
this.name = name; |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* Return the type of this variable. |
|
119 |
* @return |
|
120 |
* always non-null. |
|
121 |
*/ |
|
122 |
public JType type() { |
|
123 |
return type; |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* @return |
|
128 |
* the current modifiers of this method. |
|
129 |
* Always return non-null valid object. |
|
130 |
*/ |
|
131 |
public JMods mods() { |
|
132 |
return mods; |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* Sets the type of this variable. |
|
137 |
* |
|
138 |
* @param newType |
|
139 |
* must not be null. |
|
140 |
* |
|
141 |
* @return |
|
142 |
* the old type value. always non-null. |
|
143 |
*/ |
|
144 |
public JType type(JType newType) { |
|
145 |
JType r = type; |
|
146 |
if(newType==null) |
|
147 |
throw new IllegalArgumentException(); |
|
148 |
type = newType; |
|
149 |
return r; |
|
150 |
} |
|
151 |
||
152 |
||
153 |
/** |
|
154 |
* Adds an annotation to this variable. |
|
155 |
* @param clazz |
|
156 |
* The annotation class to annotate the field with |
|
157 |
*/ |
|
158 |
public JAnnotationUse annotate(JClass clazz){ |
|
159 |
if(annotations==null) |
|
160 |
annotations = new ArrayList<JAnnotationUse>(); |
|
161 |
JAnnotationUse a = new JAnnotationUse(clazz); |
|
162 |
annotations.add(a); |
|
163 |
return a; |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Adds an annotation to this variable. |
|
168 |
* |
|
169 |
* @param clazz |
|
170 |
* The annotation class to annotate the field with |
|
171 |
*/ |
|
172 |
public JAnnotationUse annotate(Class <? extends Annotation> clazz){ |
|
173 |
return annotate(type.owner().ref(clazz)); |
|
174 |
} |
|
175 |
||
176 |
public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) { |
|
177 |
return TypedAnnotationWriter.create(clazz,this); |
|
178 |
} |
|
179 |
||
27837
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
180 |
public boolean removeAnnotation(JAnnotationUse annotation) { |
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
181 |
return this.annotations.remove(annotation); |
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
182 |
} |
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
183 |
|
12009 | 184 |
public Collection<JAnnotationUse> annotations() { |
185 |
if (annotations == null) |
|
186 |
annotations = new ArrayList<JAnnotationUse>(); |
|
187 |
return Collections.unmodifiableList(annotations); |
|
188 |
} |
|
189 |
||
190 |
protected boolean isAnnotated() { |
|
191 |
return annotations!=null; |
|
192 |
} |
|
193 |
||
194 |
public void bind(JFormatter f) { |
|
195 |
if (annotations != null){ |
|
196 |
for( int i=0; i<annotations.size(); i++ ) |
|
197 |
f.g(annotations.get(i)).nl(); |
|
198 |
} |
|
199 |
f.g(mods).g(type).id(name); |
|
200 |
if (init != null) |
|
201 |
f.p('=').g(init); |
|
202 |
} |
|
203 |
||
204 |
public void declare(JFormatter f) { |
|
205 |
f.b(this).p(';').nl(); |
|
206 |
} |
|
207 |
||
208 |
public void generate(JFormatter f) { |
|
209 |
f.id(name); |
|
210 |
} |
|
211 |
||
212 |
||
213 |
public JExpression assign(JExpression rhs) { |
|
214 |
return JExpr.assign(this,rhs); |
|
215 |
} |
|
216 |
public JExpression assignPlus(JExpression rhs) { |
|
217 |
return JExpr.assignPlus(this,rhs); |
|
218 |
} |
|
219 |
||
220 |
} |