1 /* 2 * Copyright (c) 2004, 2008, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* 26 * @test 27 * @bug 4853450 5031171 28 * @summary ParameterDeclaration tests 29 * @library ../../lib 30 * @run main/othervm ParameterDecl 31 */ 32 33 34 import java.util.*; 35 import com.sun.mirror.declaration.*; 36 import com.sun.mirror.type.*; 37 import com.sun.mirror.util.*; 38 39 40 public class ParameterDecl extends Tester { 41 42 public static void main(String[] args) { 43 (new ParameterDecl()).run(); 44 } 45 46 47 // Declarations used by tests 48 49 @interface AT1 { 50 } 51 52 @interface AT2 { 53 boolean value(); 54 } 55 56 private void m1(@AT1 @AT2(true) final int p1) { 57 } 58 59 private void m2(int p1) { 60 } 61 62 63 private ParameterDeclaration p1 = null; // a parameter 64 65 protected void init() { 66 p1 = getMethod("m1").getParameters().iterator().next(); 67 } 68 69 70 // Declaration methods 71 72 @Test(result="param") 73 Collection<String> accept() { 74 final Collection<String> res = new ArrayList<String>(); 75 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 } 86 87 @Test(result={"@ParameterDecl.AT1", "@ParameterDecl.AT2(true)"}) 88 Collection<AnnotationMirror> getAnnotationMirrors() { 89 return p1.getAnnotationMirrors(); 90 } 91 92 @Test(result={"final"}) 93 Collection<Modifier> getModifiers() { 94 return p1.getModifiers(); 95 } 96 97 @Test(result="ParameterDecl.java") 98 String getPosition() { 99 return p1.getPosition().file().getName(); 100 } 101 102 @Test(result="p1") 103 String getSimpleName() { 104 return p1.getSimpleName(); 105 } 106 107 108 // ParameterDeclaration methods 109 110 @Test(result="int") 111 TypeMirror getType() { 112 return p1.getType(); 113 } 114 115 116 // toString, equals 117 118 @Test(result="int p1") 119 String toStringTest() { 120 return p1.toString(); 121 } 122 123 @Test(result="true") 124 boolean equalsTest1() { 125 ParameterDeclaration p = 126 getMethod("m1").getParameters().iterator().next(); 127 return p1.equals(p); 128 } 129 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 }