0N/A/*
553N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4853450 4997614
0N/A * @summary ClassDeclaration tests
0N/A * @library ../../lib
0N/A * @compile -source 1.5 ClassDecl.java
131N/A * @run main/othervm ClassDecl
0N/A */
0N/A
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.util.*;
0N/Aimport com.sun.mirror.declaration.*;
0N/Aimport com.sun.mirror.type.*;
0N/Aimport com.sun.mirror.util.*;
0N/A
0N/A
0N/A/**
0N/A * Sed Quis custodiet ipsos custodes?
0N/A */
0N/A@AT1
0N/A@AT2
0N/Apublic class ClassDecl extends Tester {
0N/A
0N/A public static void main(String[] args) {
0N/A (new ClassDecl()).run();
0N/A }
0N/A
0N/A
0N/A private ClassDeclaration nested = null; // a nested type
0N/A private ClassDeclaration object = null; // java.lang.object
0N/A
0N/A // A constructor to be found
0N/A private ClassDecl() {
0N/A }
0N/A
0N/A // Another constructor to be found
0N/A private ClassDecl(int i) {
0N/A this();
0N/A }
0N/A
0N/A // An extra field to be found
0N/A static int i;
0N/A
0N/A // Static initializer isn't among this class's methods.
0N/A static {
0N/A i = 7;
0N/A }
0N/A
0N/A // A nested class with some accoutrements
0N/A private static strictfp class NestedClass<T> implements Serializable {
0N/A void m1() {}
0N/A void m2() {}
0N/A void m2(int i) {}
0N/A }
0N/A
0N/A protected void init() {
0N/A nested = (ClassDeclaration)
0N/A thisClassDecl.getNestedTypes().iterator().next();
0N/A object = (ClassDeclaration)
0N/A env.getTypeDeclaration("java.lang.Object");
0N/A }
0N/A
0N/A
0N/A // Declaration methods
0N/A
0N/A @Test(result="class")
0N/A Collection<String> accept() {
0N/A final Collection<String> res = new ArrayList<String>();
0N/A
0N/A thisClassDecl.accept(new SimpleDeclarationVisitor() {
0N/A public void visitTypeDeclaration(TypeDeclaration t) {
0N/A res.add("type");
0N/A }
0N/A public void visitClassDeclaration(ClassDeclaration c) {
0N/A res.add("class");
0N/A }
0N/A public void visitEnumDeclaration(EnumDeclaration e) {
0N/A res.add("enum");
0N/A }
0N/A });
0N/A return res;
0N/A }
0N/A
0N/A @Test(result={"@AT1", "@AT2"})
0N/A Collection<AnnotationMirror> getAnnotationMirrors() {
0N/A return thisClassDecl.getAnnotationMirrors();
0N/A }
0N/A
0N/A @Test(result=" Sed Quis custodiet ipsos custodes?\n")
0N/A String getDocComment() {
0N/A return thisClassDecl.getDocComment();
0N/A }
0N/A
0N/A @Test(result={"public"})
0N/A Collection<Modifier> getModifiers1() {
0N/A return thisClassDecl.getModifiers();
0N/A }
0N/A
0N/A // Check that static nested class has "static" modifier, even though
0N/A // the VM doesn't set that bit.
0N/A @Test(result={"private", "static", "strictfp"})
0N/A Collection<Modifier> getModifiers2() {
0N/A return nested.getModifiers();
0N/A }
0N/A
0N/A @Test(result="ClassDecl.java")
0N/A String getPosition() {
0N/A return thisClassDecl.getPosition().file().getName();
0N/A }
0N/A
0N/A @Test(result="ClassDecl")
0N/A String getSimpleName1() {
0N/A return thisClassDecl.getSimpleName();
0N/A }
0N/A
0N/A @Test(result="NestedClass")
0N/A String getSimpleName2() {
0N/A return nested.getSimpleName();
0N/A }
0N/A
0N/A
0N/A // MemberDeclaration method
0N/A
0N/A @Test(result="null")
0N/A TypeDeclaration getDeclaringType1() {
0N/A return thisClassDecl.getDeclaringType();
0N/A }
0N/A
0N/A @Test(result="ClassDecl")
0N/A TypeDeclaration getDeclaringType2() {
0N/A return nested.getDeclaringType();
0N/A }
0N/A
0N/A
0N/A // TypeDeclaration methods
0N/A
0N/A @Test(result={"nested", "object", "i"})
0N/A Collection<FieldDeclaration> getFields() {
0N/A return thisClassDecl.getFields();
0N/A }
0N/A
0N/A @Test(result={})
0N/A Collection<TypeParameterDeclaration> getFormalTypeParameters1() {
0N/A return thisClassDecl.getFormalTypeParameters();
0N/A }
0N/A
0N/A @Test(result="T")
0N/A Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
0N/A return nested.getFormalTypeParameters();
0N/A }
0N/A
0N/A @Test(result="ClassDecl.NestedClass<T>")
0N/A Collection<TypeDeclaration> getNestedTypes() {
0N/A return thisClassDecl.getNestedTypes();
0N/A }
0N/A
0N/A @Test(result="")
0N/A PackageDeclaration getPackage1() {
0N/A return thisClassDecl.getPackage();
0N/A }
0N/A
0N/A @Test(result="java.lang")
0N/A PackageDeclaration getPackage2() {
0N/A return object.getPackage();
0N/A }
0N/A
0N/A @Test(result="ClassDecl")
0N/A String getQualifiedName1() {
0N/A return thisClassDecl.getQualifiedName();
0N/A }
0N/A
0N/A @Test(result="ClassDecl.NestedClass")
0N/A String getQualifiedName2() {
0N/A return nested.getQualifiedName();
0N/A }
0N/A
0N/A @Test(result="java.lang.Object")
0N/A String getQualifiedName3() {
0N/A return object.getQualifiedName();
0N/A }
0N/A
0N/A @Test(result="java.io.Serializable")
0N/A Collection<InterfaceType> getSuperinterfaces() {
0N/A return nested.getSuperinterfaces();
0N/A }
0N/A
0N/A
0N/A // ClassDeclaration methods
0N/A
0N/A @Test(result={"ClassDecl()", "ClassDecl(int)"})
0N/A Collection<ConstructorDeclaration> getConstructors1() {
0N/A return thisClassDecl.getConstructors();
0N/A }
0N/A
0N/A // Check for default constructor.
0N/A // 4997614: visitConstructionDeclaration reports info when there is no ctor
0N/A @Test(result={"NestedClass()"})
0N/A Collection<ConstructorDeclaration> getConstructors2() {
0N/A return nested.getConstructors();
0N/A }
0N/A
0N/A @Test(result={"m1()", "m2()", "m2(int)"})
0N/A Collection<MethodDeclaration> getMethods() {
0N/A return nested.getMethods();
0N/A }
0N/A
0N/A @Test(result={"Tester"})
0N/A ClassType getSuperclass() {
0N/A return thisClassDecl.getSuperclass();
0N/A }
0N/A
0N/A @Test(result={"null"})
0N/A ClassType objectHasNoSuperclass() {
0N/A return object.getSuperclass();
0N/A }
0N/A}
0N/A
0N/A
0N/A// Annotations used for testing.
0N/A
0N/A@interface AT1 {
0N/A}
0N/A
0N/A@interface AT2 {
0N/A}