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 4993299
0N/A * @summary ConstructorDeclaration tests
0N/A * @library ../../lib
0N/A * @compile -source 1.5 ConstructorDecl.java
131N/A * @run main/othervm ConstructorDecl
0N/A */
0N/A
0N/A
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/Apublic class ConstructorDecl extends Tester {
0N/A
0N/A /**
0N/A * Sed Quis custodiet ipsos custodes?
0N/A */
0N/A @AT1
0N/A public ConstructorDecl() {
0N/A }
0N/A
0N/A
0N/A public static void main(String[] args) {
0N/A (new ConstructorDecl()).run();
0N/A }
0N/A
0N/A
0N/A private ConstructorDeclaration ctor = null; // a constructor
0N/A private ConstructorDeclaration ctorDef = null; // a default c'tor
0N/A private ConstructorDeclaration ctorInner = null; // an inner class c'tor
0N/A
0N/A protected void init() {
0N/A ctor = getAConstructor(thisClassDecl);
0N/A ctorDef = getAConstructor((ClassDeclaration)
0N/A env.getTypeDeclaration("C1"));
0N/A ctorInner = getAConstructor((ClassDeclaration)
0N/A env.getTypeDeclaration("C1.C2"));
0N/A }
0N/A
0N/A // Return a constructor of a class.
0N/A private ConstructorDeclaration getAConstructor(ClassDeclaration c) {
0N/A return c.getConstructors().iterator().next();
0N/A }
0N/A
0N/A
0N/A // Declaration methods
0N/A
0N/A @Test(result="constructor")
0N/A Collection<String> accept() {
0N/A final Collection<String> res = new ArrayList<String>();
0N/A
0N/A ctor.accept(new SimpleDeclarationVisitor() {
0N/A public void visitTypeDeclaration(TypeDeclaration t) {
0N/A res.add("type");
0N/A }
0N/A public void visitExecutableDeclaration(ExecutableDeclaration e) {
0N/A res.add("executable");
0N/A }
0N/A public void visitConstructorDeclaration(ConstructorDeclaration c) {
0N/A res.add("constructor");
0N/A }
0N/A });
0N/A return res;
0N/A }
0N/A
0N/A @Test(result={"@AT1"})
0N/A Collection<AnnotationMirror> getAnnotationMirrors() {
0N/A return ctor.getAnnotationMirrors();
0N/A }
0N/A
0N/A @Test(result=" Sed Quis custodiet ipsos custodes?\n")
0N/A String getDocComment() {
0N/A return ctor.getDocComment();
0N/A }
0N/A
0N/A @Test(result={"public"})
0N/A Collection<Modifier> getModifiers() {
0N/A return ctor.getModifiers();
0N/A }
0N/A
0N/A @Test(result="ConstructorDecl.java")
0N/A String getPosition() {
0N/A return ctor.getPosition().file().getName();
0N/A }
0N/A
0N/A @Test(result="ConstructorDecl.java")
0N/A String getPositionDefault() {
0N/A return ctorDef.getPosition().file().getName();
0N/A }
0N/A
0N/A @Test(result="ConstructorDecl")
0N/A String getSimpleName() {
0N/A return ctor.getSimpleName();
0N/A }
0N/A
0N/A @Test(result="C2")
0N/A String getSimpleNameInner() {
0N/A return ctorInner.getSimpleName();
0N/A }
0N/A
0N/A
0N/A // MemberDeclaration method
0N/A
0N/A @Test(result="ConstructorDecl")
0N/A TypeDeclaration getDeclaringType() {
0N/A return ctor.getDeclaringType();
0N/A }
0N/A
0N/A
0N/A // ExecutableDeclaration methods
0N/A
0N/A @Test(result={})
0N/A Collection<TypeParameterDeclaration> getFormalTypeParameters1() {
0N/A return ctor.getFormalTypeParameters();
0N/A }
0N/A
0N/A @Test(result={"N extends java.lang.Number"})
0N/A Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
0N/A return ctorInner.getFormalTypeParameters();
0N/A }
0N/A
0N/A @Test(result={})
0N/A Collection<ParameterDeclaration> getParameters1() {
0N/A return ctor.getParameters();
0N/A }
0N/A
0N/A // 4993299: verify synthetic parameters to inner class constructors
0N/A // aren't visible
0N/A @Test(result={"N n1", "N n2", "java.lang.String[] ss"},
0N/A ordered=true)
0N/A Collection<ParameterDeclaration> getParameters2() {
0N/A return ctorInner.getParameters();
0N/A }
0N/A
0N/A @Test(result={"java.lang.Throwable"})
0N/A Collection<ReferenceType> getThrownTypes() {
0N/A return ctorInner.getThrownTypes();
0N/A }
0N/A
0N/A @Test(result="false")
0N/A Boolean isVarArgs1() {
0N/A return ctor.isVarArgs();
0N/A }
0N/A
0N/A @Test(result="true")
0N/A Boolean isVarArgs2() {
0N/A return ctorInner.isVarArgs();
0N/A }
0N/A
0N/A
0N/A // toString
0N/A
0N/A @Test(result="<N extends java.lang.Number> C2(N, N, String...)")
0N/A @Ignore("This is what it would be nice to see.")
0N/A String toStringTest() {
0N/A return ctorInner.toString();
0N/A }
0N/A}
0N/A
0N/A
0N/A// Classes and interfaces used for testing.
0N/A
0N/Aclass C1 {
0N/A class C2 {
0N/A <N extends Number> C2(N n1, N n2, String... ss) throws Throwable {
0N/A }
0N/A }
0N/A}
0N/A
0N/A@interface AT1 {
0N/A}