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 5010746
0N/A * @summary MethodDeclaration tests
0N/A * @library ../../lib
0N/A * @compile -source 1.5 MethodDecl.java
131N/A * @run main/othervm MethodDecl
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 MethodDecl extends Tester {
0N/A
0N/A public static void main(String[] args) {
0N/A (new MethodDecl()).run();
0N/A }
0N/A
0N/A
0N/A private MethodDeclaration meth1 = null; // a method
0N/A private MethodDeclaration meth2 = null; // another method
0N/A
0N/A protected void init() {
0N/A meth1 = getMethod("m1");
0N/A meth2 = getMethod("m2");
0N/A }
0N/A
0N/A
0N/A // Declaration methods
0N/A
0N/A @Test(result="method")
0N/A Collection<String> accept() {
0N/A final Collection<String> res = new ArrayList<String>();
0N/A
0N/A meth1.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 visitMethodDeclaration(MethodDeclaration m) {
0N/A res.add("method");
0N/A }
0N/A public void visitAnnotationTypeElementDeclaration(
0N/A AnnotationTypeElementDeclaration a) {
0N/A res.add("anno type element");
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 meth1.getAnnotationMirrors();
0N/A }
0N/A
0N/A @Test(result=" Sed Quis custodiet ipsos custodes?\n")
0N/A String getDocComment() {
0N/A return meth1.getDocComment();
0N/A }
0N/A
0N/A @Test(result={"private", "static", "strictfp"})
0N/A Collection<Modifier> getModifiers() {
0N/A return meth1.getModifiers();
0N/A }
0N/A
0N/A // Interface methods are implicitly public and abstract.
0N/A @Test(result={"public", "abstract"})
0N/A Collection<Modifier> getModifiersInterface() {
0N/A for (TypeDeclaration t : thisClassDecl.getNestedTypes()) {
0N/A for (MethodDeclaration m : t.getMethods()) {
0N/A return m.getModifiers();
0N/A }
0N/A }
0N/A throw new AssertionError();
0N/A }
0N/A
0N/A @Test(result="MethodDecl.java")
0N/A String getPosition() {
0N/A return meth1.getPosition().file().getName();
0N/A }
0N/A
0N/A @Test(result="m2")
0N/A String getSimpleName() {
0N/A return meth2.getSimpleName();
0N/A }
0N/A
0N/A
0N/A // MemberDeclaration method
0N/A
0N/A @Test(result="MethodDecl")
0N/A TypeDeclaration getDeclaringType() {
0N/A return meth1.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 meth1.getFormalTypeParameters();
0N/A }
0N/A
0N/A @Test(result={"T", "N extends java.lang.Number"},
0N/A ordered=true)
0N/A Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
0N/A return meth2.getFormalTypeParameters();
0N/A }
0N/A
0N/A @Test(result={})
0N/A Collection<ParameterDeclaration> getParameters1() {
0N/A return meth1.getParameters();
0N/A }
0N/A
0N/A @Test(result={"N n", "java.lang.String[] ss"},
0N/A ordered=true)
0N/A Collection<ParameterDeclaration> getParameters2() {
0N/A return meth2.getParameters();
0N/A }
0N/A
0N/A @Test(result="true")
0N/A boolean parameterEquals1() {
0N/A ParameterDeclaration p1 =
0N/A getMethod("m3").getParameters().iterator().next();
0N/A ParameterDeclaration p2 =
0N/A getMethod("m3").getParameters().iterator().next();
0N/A return p1.equals(p2);
0N/A }
0N/A
0N/A @Test(result="false")
0N/A boolean parameterEquals2() {
0N/A ParameterDeclaration p1 =
0N/A getMethod("m3").getParameters().iterator().next();
0N/A ParameterDeclaration p2 =
0N/A getMethod("m4").getParameters().iterator().next();
0N/A return p1.equals(p2);
0N/A }
0N/A
0N/A @Test(result="true")
0N/A boolean parameterHashCode() {
0N/A ParameterDeclaration p1 =
0N/A getMethod("m3").getParameters().iterator().next();
0N/A ParameterDeclaration p2 =
0N/A getMethod("m3").getParameters().iterator().next();
0N/A return p1.hashCode() == p2.hashCode();
0N/A }
0N/A
0N/A @Test(result={"java.lang.Throwable"})
0N/A Collection<ReferenceType> getThrownTypes() {
0N/A return meth2.getThrownTypes();
0N/A }
0N/A
0N/A @Test(result="false")
0N/A Boolean isVarArgs1() {
0N/A return meth1.isVarArgs();
0N/A }
0N/A
0N/A @Test(result="true")
0N/A Boolean isVarArgs2() {
0N/A return meth2.isVarArgs();
0N/A }
0N/A
0N/A
0N/A // MethodDeclaration methods
0N/A
0N/A @Test(result="void")
0N/A TypeMirror getReturnType1() {
0N/A return meth1.getReturnType();
0N/A }
0N/A
0N/A @Test(result="N")
0N/A TypeMirror getReturnType2() {
0N/A return meth2.getReturnType();
0N/A }
0N/A
0N/A
0N/A // toString
0N/A
0N/A @Test(result="<T, N extends java.lang.Number> m2(N, java.lang.String...)")
0N/A @Ignore("This is what it would be nice to see.")
0N/A String toStringTest() {
0N/A return meth2.toString();
0N/A }
0N/A
0N/A
0N/A // Declarations used by tests.
0N/A
0N/A /**
0N/A * Sed Quis custodiet ipsos custodes?
0N/A */
0N/A @AT1
0N/A private static strictfp void m1() {
0N/A }
0N/A
0N/A private <T, N extends Number> N m2(N n, String... ss) throws Throwable {
0N/A return null;
0N/A }
0N/A
0N/A private void m3(String s) {
0N/A }
0N/A
0N/A private void m4(String s) {
0N/A }
0N/A
0N/A // A nested interface
0N/A interface I {
0N/A void m();
0N/A }
0N/A}
0N/A
0N/A
0N/A// Annotation type used by tests.
0N/A
0N/A@interface AT1 {
0N/A}