author | tonyp |
Wed, 19 Aug 2009 12:53:25 -0400 | |
changeset 3691 | c84b8483cd2c |
parent 2678 | 57cf2a1c1a05 |
permissions | -rw-r--r-- |
8 | 1 |
/* |
2678
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
8 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
package com.sun.codemodel.internal; |
|
26 |
||
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
29 |
import java.lang.annotation.Annotation; |
|
30 |
||
31 |
/** |
|
32 |
* Enum Constant. |
|
33 |
* |
|
34 |
* When used as an {@link JExpression}, this object represents a reference to the enum constant. |
|
35 |
* |
|
36 |
* @author |
|
37 |
* Bhakti Mehta (Bhakti.Mehta@sun.com) |
|
38 |
*/ |
|
39 |
public final class JEnumConstant extends JExpressionImpl implements JDeclaration, JAnnotatable { |
|
40 |
||
41 |
/** |
|
42 |
* The constant. |
|
43 |
*/ |
|
44 |
private final String name; |
|
45 |
/** |
|
46 |
* The enum class. |
|
47 |
*/ |
|
48 |
private final JDefinedClass type; |
|
49 |
/** |
|
50 |
* javadoc comments, if any. |
|
51 |
*/ |
|
52 |
private JDocComment jdoc = null; |
|
53 |
||
54 |
/** |
|
55 |
* Annotations on this variable. Lazily created. |
|
56 |
*/ |
|
57 |
private List<JAnnotationUse> annotations = null; |
|
58 |
||
59 |
||
60 |
/** |
|
61 |
* List of the constructor argument expressions. |
|
62 |
* Lazily constructed. |
|
63 |
*/ |
|
64 |
private List<JExpression> args = null; |
|
65 |
||
66 |
JEnumConstant(JDefinedClass type,String name) { |
|
67 |
this.name = name; |
|
68 |
this.type = type; |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Add an expression to this constructor's argument list |
|
73 |
* |
|
74 |
* @param arg |
|
75 |
* Argument to add to argument list |
|
76 |
*/ |
|
77 |
public JEnumConstant arg(JExpression arg) { |
|
78 |
if(arg==null) throw new IllegalArgumentException(); |
|
79 |
if(args==null) |
|
80 |
args = new ArrayList<JExpression>(); |
|
81 |
args.add(arg); |
|
82 |
return this; |
|
83 |
} |
|
84 |
||
85 |
/** |
|
86 |
* Returns the name of this constant. |
|
87 |
* |
|
88 |
* @return never null. |
|
89 |
*/ |
|
90 |
public String getName() { |
|
91 |
return this.type.fullName().concat(".").concat(this.name); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Creates, if necessary, and returns the enum constant javadoc. |
|
96 |
* |
|
97 |
* @return JDocComment containing javadocs for this constant. |
|
98 |
*/ |
|
99 |
public JDocComment javadoc() { |
|
100 |
if (jdoc == null) |
|
101 |
jdoc = new JDocComment(type.owner()); |
|
102 |
return jdoc; |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Adds an annotation to this variable. |
|
107 |
* @param clazz |
|
108 |
* The annotation class to annotate the field with |
|
109 |
*/ |
|
110 |
public JAnnotationUse annotate(JClass clazz){ |
|
111 |
if(annotations==null) |
|
112 |
annotations = new ArrayList<JAnnotationUse>(); |
|
113 |
JAnnotationUse a = new JAnnotationUse(clazz); |
|
114 |
annotations.add(a); |
|
115 |
return a; |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Adds an annotation to this variable. |
|
120 |
* |
|
121 |
* @param clazz |
|
122 |
* The annotation class to annotate the field with |
|
123 |
*/ |
|
124 |
public JAnnotationUse annotate(Class <? extends Annotation> clazz){ |
|
125 |
return annotate(type.owner().ref(clazz)); |
|
126 |
} |
|
127 |
||
128 |
public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) { |
|
129 |
return TypedAnnotationWriter.create(clazz,this); |
|
130 |
} |
|
131 |
||
132 |
public void declare(JFormatter f) { |
|
133 |
if( jdoc != null ) |
|
134 |
f.nl().g( jdoc ); |
|
135 |
if (annotations != null) { |
|
136 |
for( int i=0; i<annotations.size(); i++ ) |
|
137 |
f.g(annotations.get(i)).nl(); |
|
138 |
} |
|
139 |
f.id(name); |
|
140 |
if(args!=null) { |
|
141 |
f.p('(').g(args).p(')'); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
public void generate(JFormatter f) { |
|
146 |
f.t(type).p('.').p(name); |
|
147 |
} |
|
148 |
} |