test/tools/apt/mirror/declaration/ParameterDecl.java

changeset 1
9a66ca7c79fa
child 132
a54ef8459576
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
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 5031171
28 * @summary ParameterDeclaration tests
29 * @library ../../lib
30 */
31
32
33 import java.util.*;
34 import com.sun.mirror.declaration.*;
35 import com.sun.mirror.type.*;
36 import com.sun.mirror.util.*;
37
38
39 public class ParameterDecl extends Tester {
40
41 public static void main(String[] args) {
42 (new ParameterDecl()).run();
43 }
44
45
46 // Declarations used by tests
47
48 @interface AT1 {
49 }
50
51 @interface AT2 {
52 boolean value();
53 }
54
55 private void m1(@AT1 @AT2(true) final int p1) {
56 }
57
58 private void m2(int p1) {
59 }
60
61
62 private ParameterDeclaration p1 = null; // a parameter
63
64 protected void init() {
65 p1 = getMethod("m1").getParameters().iterator().next();
66 }
67
68
69 // Declaration methods
70
71 @Test(result="param")
72 Collection<String> accept() {
73 final Collection<String> res = new ArrayList<String>();
74
75 p1.accept(new SimpleDeclarationVisitor() {
76 public void visitFieldDeclaration(FieldDeclaration f) {
77 res.add("field");
78 }
79 public void visitParameterDeclaration(ParameterDeclaration p) {
80 res.add("param");
81 }
82 });
83 return res;
84 }
85
86 @Test(result={"@ParameterDecl.AT1", "@ParameterDecl.AT2(true)"})
87 Collection<AnnotationMirror> getAnnotationMirrors() {
88 return p1.getAnnotationMirrors();
89 }
90
91 @Test(result={"final"})
92 Collection<Modifier> getModifiers() {
93 return p1.getModifiers();
94 }
95
96 @Test(result="ParameterDecl.java")
97 String getPosition() {
98 return p1.getPosition().file().getName();
99 }
100
101 @Test(result="p1")
102 String getSimpleName() {
103 return p1.getSimpleName();
104 }
105
106
107 // ParameterDeclaration methods
108
109 @Test(result="int")
110 TypeMirror getType() {
111 return p1.getType();
112 }
113
114
115 // toString, equals
116
117 @Test(result="int p1")
118 String toStringTest() {
119 return p1.toString();
120 }
121
122 @Test(result="true")
123 boolean equalsTest1() {
124 ParameterDeclaration p =
125 getMethod("m1").getParameters().iterator().next();
126 return p1.equals(p);
127 }
128
129 // Not all p1's are equal.
130 @Test(result="false")
131 boolean equalsTest2() {
132 ParameterDeclaration p2 =
133 getMethod("m2").getParameters().iterator().next();
134 return p1.equals(p2);
135 }
136 }

mercurial