Tue, 07 Oct 2008 15:39:19 -0700
6749967: regression tests for apt should be same-vm friendly
Reviewed-by: darcy
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 */
25 /*
26 * @test
27 * @bug 4853450 5031171
28 * @summary ParameterDeclaration tests
29 * @library ../../lib
30 * @run main/othervm ParameterDecl
31 */
34 import java.util.*;
35 import com.sun.mirror.declaration.*;
36 import com.sun.mirror.type.*;
37 import com.sun.mirror.util.*;
40 public class ParameterDecl extends Tester {
42 public static void main(String[] args) {
43 (new ParameterDecl()).run();
44 }
47 // Declarations used by tests
49 @interface AT1 {
50 }
52 @interface AT2 {
53 boolean value();
54 }
56 private void m1(@AT1 @AT2(true) final int p1) {
57 }
59 private void m2(int p1) {
60 }
63 private ParameterDeclaration p1 = null; // a parameter
65 protected void init() {
66 p1 = getMethod("m1").getParameters().iterator().next();
67 }
70 // Declaration methods
72 @Test(result="param")
73 Collection<String> accept() {
74 final Collection<String> res = new ArrayList<String>();
76 p1.accept(new SimpleDeclarationVisitor() {
77 public void visitFieldDeclaration(FieldDeclaration f) {
78 res.add("field");
79 }
80 public void visitParameterDeclaration(ParameterDeclaration p) {
81 res.add("param");
82 }
83 });
84 return res;
85 }
87 @Test(result={"@ParameterDecl.AT1", "@ParameterDecl.AT2(true)"})
88 Collection<AnnotationMirror> getAnnotationMirrors() {
89 return p1.getAnnotationMirrors();
90 }
92 @Test(result={"final"})
93 Collection<Modifier> getModifiers() {
94 return p1.getModifiers();
95 }
97 @Test(result="ParameterDecl.java")
98 String getPosition() {
99 return p1.getPosition().file().getName();
100 }
102 @Test(result="p1")
103 String getSimpleName() {
104 return p1.getSimpleName();
105 }
108 // ParameterDeclaration methods
110 @Test(result="int")
111 TypeMirror getType() {
112 return p1.getType();
113 }
116 // toString, equals
118 @Test(result="int p1")
119 String toStringTest() {
120 return p1.toString();
121 }
123 @Test(result="true")
124 boolean equalsTest1() {
125 ParameterDeclaration p =
126 getMethod("m1").getParameters().iterator().next();
127 return p1.equals(p);
128 }
130 // Not all p1's are equal.
131 @Test(result="false")
132 boolean equalsTest2() {
133 ParameterDeclaration p2 =
134 getMethod("m2").getParameters().iterator().next();
135 return p1.equals(p2);
136 }
137 }