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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 132
a54ef8459576
permissions
-rw-r--r--

Initial load

     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  */
    33 import java.util.*;
    34 import com.sun.mirror.declaration.*;
    35 import com.sun.mirror.type.*;
    36 import com.sun.mirror.util.*;
    39 public class ParameterDecl extends Tester {
    41     public static void main(String[] args) {
    42         (new ParameterDecl()).run();
    43     }
    46     // Declarations used by tests
    48     @interface AT1 {
    49     }
    51     @interface AT2 {
    52         boolean value();
    53     }
    55     private void m1(@AT1 @AT2(true) final int p1) {
    56     }
    58     private void m2(int p1) {
    59     }
    62     private ParameterDeclaration p1 = null;     // a parameter
    64     protected void init() {
    65         p1 = getMethod("m1").getParameters().iterator().next();
    66     }
    69     // Declaration methods
    71     @Test(result="param")
    72     Collection<String> accept() {
    73         final Collection<String> res = new ArrayList<String>();
    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     }
    86     @Test(result={"@ParameterDecl.AT1", "@ParameterDecl.AT2(true)"})
    87     Collection<AnnotationMirror> getAnnotationMirrors() {
    88         return p1.getAnnotationMirrors();
    89     }
    91     @Test(result={"final"})
    92     Collection<Modifier> getModifiers() {
    93         return p1.getModifiers();
    94     }
    96     @Test(result="ParameterDecl.java")
    97     String getPosition() {
    98         return p1.getPosition().file().getName();
    99     }
   101     @Test(result="p1")
   102     String getSimpleName() {
   103         return p1.getSimpleName();
   104     }
   107     // ParameterDeclaration methods
   109     @Test(result="int")
   110     TypeMirror getType() {
   111         return p1.getType();
   112     }
   115     // toString, equals
   117     @Test(result="int p1")
   118     String toStringTest() {
   119         return p1.toString();
   120     }
   122     @Test(result="true")
   123     boolean equalsTest1() {
   124         ParameterDeclaration p =
   125             getMethod("m1").getParameters().iterator().next();
   126         return p1.equals(p);
   127     }
   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