|
1 /* |
|
2 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
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. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 |
|
25 /* |
|
26 * @test |
|
27 * @bug 4853450 5008309 |
|
28 * @summary FieldDeclaration tests |
|
29 * @library ../../lib |
|
30 * @compile -source 1.5 FieldDecl.java |
|
31 * @run main FieldDecl |
|
32 */ |
|
33 |
|
34 |
|
35 import java.util.*; |
|
36 import com.sun.mirror.declaration.*; |
|
37 import com.sun.mirror.type.*; |
|
38 import com.sun.mirror.util.*; |
|
39 |
|
40 |
|
41 public class FieldDecl extends Tester { |
|
42 |
|
43 public static void main(String[] args) { |
|
44 (new FieldDecl()).run(); |
|
45 } |
|
46 |
|
47 |
|
48 private FieldDeclaration f1 = null; // a field |
|
49 private FieldDeclaration f2 = null; // a static field |
|
50 private FieldDeclaration f3 = null; // a constant field |
|
51 |
|
52 protected void init() { |
|
53 f1 = getField("aField"); |
|
54 f2 = getField("aStaticField"); |
|
55 f3 = getField("aConstantField"); |
|
56 } |
|
57 |
|
58 |
|
59 // Declaration methods |
|
60 |
|
61 @Test(result="field") |
|
62 Collection<String> accept() { |
|
63 final Collection<String> res = new ArrayList<String>(); |
|
64 |
|
65 f1.accept(new SimpleDeclarationVisitor() { |
|
66 public void visitTypeDeclaration(TypeDeclaration t) { |
|
67 res.add("type"); |
|
68 } |
|
69 public void visitFieldDeclaration(FieldDeclaration f) { |
|
70 res.add("field"); |
|
71 } |
|
72 public void visitEnumConstantDeclaration( |
|
73 EnumConstantDeclaration e) { |
|
74 res.add("enum const"); |
|
75 } |
|
76 }); |
|
77 return res; |
|
78 } |
|
79 |
|
80 @Test(result={"@FieldDecl.AT1"}) |
|
81 Collection<AnnotationMirror> getAnnotationMirrors() { |
|
82 return f1.getAnnotationMirrors(); |
|
83 } |
|
84 |
|
85 @Test(result=" Sed Quis custodiet ipsos custodes?\n") |
|
86 String getDocComment() { |
|
87 return f1.getDocComment(); |
|
88 } |
|
89 |
|
90 @Test(result={"public"}) |
|
91 Collection<Modifier> getModifiers() { |
|
92 return f1.getModifiers(); |
|
93 } |
|
94 |
|
95 @Test(result="FieldDecl.java") |
|
96 String getPosition() { |
|
97 return f1.getPosition().file().getName(); |
|
98 } |
|
99 |
|
100 @Test(result="aField") |
|
101 String getSimpleName() { |
|
102 return f1.getSimpleName(); |
|
103 } |
|
104 |
|
105 |
|
106 // MemberDeclaration method |
|
107 |
|
108 @Test(result="FieldDecl") |
|
109 TypeDeclaration getDeclaringType() { |
|
110 return f1.getDeclaringType(); |
|
111 } |
|
112 |
|
113 |
|
114 // FieldDeclaration methods |
|
115 |
|
116 @Test(result="java.util.List<java.lang.String>") |
|
117 TypeMirror getType1() { |
|
118 return f1.getType(); |
|
119 } |
|
120 |
|
121 @Test(result="int") |
|
122 TypeMirror getType2() { |
|
123 return f2.getType(); |
|
124 } |
|
125 |
|
126 @Test(result="null") |
|
127 Object getConstantValue1() { |
|
128 return f1.getConstantValue(); |
|
129 } |
|
130 |
|
131 // 5008309: FieldDeclaration.getConstantValue() doesn't return anything |
|
132 @Test(result="true") |
|
133 Object getConstantValue2() { |
|
134 return f3.getConstantValue(); |
|
135 } |
|
136 |
|
137 |
|
138 // toString |
|
139 |
|
140 @Test(result="aField") |
|
141 String toStringTest() { |
|
142 return f1.toString(); |
|
143 } |
|
144 |
|
145 |
|
146 // Declarations used by tests. |
|
147 |
|
148 /** |
|
149 * Sed Quis custodiet ipsos custodes? |
|
150 */ |
|
151 @AT1 |
|
152 public List<String> aField = new ArrayList<String>(); |
|
153 |
|
154 static int aStaticField; |
|
155 |
|
156 public static final boolean aConstantField = true; |
|
157 |
|
158 |
|
159 @interface AT1 { |
|
160 } |
|
161 } |