langtools/test/tools/apt/mirror/declaration/InterfaceDecl.java
author lana
Tue, 01 Jun 2010 14:17:38 -0700
changeset 5597 ab490f66d2cf
parent 5520 86e4b9a9da40
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     2
 * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 * @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @bug 4853450 4993303 5004618 5010746
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 * @summary InterfaceDeclaration tests
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 * @library ../../lib
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
 * @compile -source 1.5 InterfaceDecl.java
1467
290837884931 6749967: regression tests for apt should be same-vm friendly
jjg
parents: 10
diff changeset
    31
 * @run main/othervm InterfaceDecl
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.mirror.declaration.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.mirror.type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.mirror.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * Sed Quis custodiet ipsos custodes?
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
@AT1
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
@AT2
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class InterfaceDecl extends Tester {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        (new InterfaceDecl()).run();
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    private InterfaceDeclaration iDecl = null;          // an interface
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    private InterfaceDeclaration nested = null;         // a nested interface
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    protected void init() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        iDecl = (InterfaceDeclaration) env.getTypeDeclaration("I");
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        nested = (InterfaceDeclaration)
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            iDecl.getNestedTypes().iterator().next();
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    // Declaration methods
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    @Test(result="interface")
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    Collection<String> accept() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        final Collection<String> res = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        iDecl.accept(new SimpleDeclarationVisitor() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            public void visitTypeDeclaration(TypeDeclaration t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
                res.add("type");
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            public void visitClassDeclaration(ClassDeclaration c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                res.add("class");
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
            public void visitInterfaceDeclaration(InterfaceDeclaration e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
                res.add("interface");
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            public void visitAnnotationTypeDeclaration(
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                                        AnnotationTypeDeclaration e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
                res.add("annotation type");
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        return res;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    @Test(result="true")
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    boolean equals1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        return iDecl.equals(iDecl);
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    @Test(result="false")
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    boolean equals2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return iDecl.equals(nested);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    @Test(result="true")
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    boolean equals3() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        return iDecl.equals(env.getTypeDeclaration("I"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    @Test(result={"@AT1", "@AT2"})
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    Collection<AnnotationMirror> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        return iDecl.getAnnotationMirrors();
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    @Test(result=" Sed Quis custodiet ipsos custodes?\n")
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    String getDocComment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        return iDecl.getDocComment();
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    // Check that interface has "abstract" modifier, even though it's implict
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    // in the source code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    @Test(result={"abstract"})
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    Collection<Modifier> getModifiers1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return iDecl.getModifiers();
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    // Check that nested interface has "static" modifier, even though
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    // it's implicit in the source code and the VM doesn't set that bit.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    @Test(result={"public", "abstract", "static"})
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    Collection<Modifier> getModifiers2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return nested.getModifiers();
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    @Test(result="InterfaceDecl.java")
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    String getPosition() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        return iDecl.getPosition().file().getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    @Test(result="I")
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    String getSimpleName1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        return iDecl.getSimpleName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    @Test(result="Nested")
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    String getSimpleName2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return nested.getSimpleName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    // MemberDeclaration method
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    @Test(result="null")
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    TypeDeclaration getDeclaringType1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        return iDecl.getDeclaringType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    @Test(result="I<T extends java.lang.Number>")
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    TypeDeclaration getDeclaringType2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        return nested.getDeclaringType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    // TypeDeclaration methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    @Test(result={"i"})
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    Collection<FieldDeclaration> getFields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        return iDecl.getFields();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    @Test(result={"T extends java.lang.Number"})
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    Collection<TypeParameterDeclaration> getFormalTypeParameters1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        return iDecl.getFormalTypeParameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    @Test(result={})
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        return nested.getFormalTypeParameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    // 4993303: verify policy on Object methods being visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    @Test(result={"m()", "toString()"})
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    Collection<? extends MethodDeclaration> getMethods() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        return nested.getMethods();
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    @Test(result="I.Nested")
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    Collection<TypeDeclaration> getNestedTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return iDecl.getNestedTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    @Test(result="")
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    PackageDeclaration getPackage1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        return iDecl.getPackage();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    @Test(result="java.util")
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    PackageDeclaration getPackage2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        InterfaceDeclaration set =
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
            (InterfaceDeclaration) env.getTypeDeclaration("java.util.Set");
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        return set.getPackage();
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    @Test(result="I")
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    String getQualifiedName1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        return iDecl.getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    @Test(result="I.Nested")
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    String getQualifiedName2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        return nested.getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    @Test(result="java.util.Set")
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    String getQualifiedName3() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        InterfaceDeclaration set =
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            (InterfaceDeclaration) env.getTypeDeclaration("java.util.Set");
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        return set.getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    @Test(result="java.lang.Runnable")
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    Collection<InterfaceType> getSuperinterfaces() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        return iDecl.getSuperinterfaces();
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
}
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
// Interfaces used for testing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
 * Sed Quis custodiet ipsos custodes?
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
@AT1
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
@AT2
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
interface I<T extends Number> extends Runnable {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    int i = 6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    void m1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    void m2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    void m2(int j);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    interface Nested {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        void m();
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        String toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
}
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
@interface AT1 {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
}
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
@interface AT2 {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
}