1 /* tests/regression/MinimalClassReflection.java - checks most some of the
2 reflective methods onto java.lang.Class
4 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
5 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
6 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 Contact: cacao@cacaojvm.org
28 Authors: Mathias Panzenböck
32 import java.lang.reflect.Method;
33 import java.lang.reflect.Constructor;
35 public class MinimalClassReflection {
36 public static void printClassInfo(String header, Class<?> cls) {
38 Constructor<?> constr;
41 p("---------------------- %s ----------------------", header);
42 p("is local: %s", cls.isLocalClass());
43 p("is anonymous: %s", cls.isAnonymousClass());
44 p("is member: %s", cls.isMemberClass());
45 p("name: %s", cls.getName());
46 p("simple name: %s", cls.getSimpleName());
47 p("canonical name: %s", cls.getCanonicalName());
49 clazz = cls.getSuperclass();
51 (clazz == null ? "null" : clazz.getName()));
53 clazz = cls.getDeclaringClass();
54 p("declaring class: %s",
55 (clazz == null ? "null" : clazz.getName()));
57 clazz = cls.getEnclosingClass();
58 p("enclosing class: %s",
59 (clazz == null ? "null" : clazz.getName()));
61 constr = cls.getEnclosingConstructor();
62 p("enclosing constructor: %s",
63 (constr == null ? "null" :
64 constr.getDeclaringClass().getName() +
65 "." + constr.getName()));
67 method = cls.getEnclosingMethod();
68 p("enclosing method: %s",
69 (method == null ? "null" :
70 method.getDeclaringClass().getName() +
71 "." + method.getName()));
76 public static void main(String[] args) {
81 public ALocalClass() {
82 class AnotherLocalClass {
86 "test a member class",
90 "test a anonymous class derived from a member class",
91 new AMemberClass() {}.getClass());
94 "test a local class (local to a constructor)",
95 AnotherLocalClass.class);
98 "test a anonymous class derived from a local " +
99 "class (local to a constructor)",
100 new AnotherLocalClass() {}.getClass());
105 "test a normal class",
106 MinimalClassReflection.class);
109 "test a local class (local to a method)",
113 "test a anonymous class",
114 new Object() {}.getClass());
117 "test a anonymous class derived from a local class" +
118 " (local to a method)",
119 new ALocalClass() {}.getClass());
124 public static void p(String fmt, Object... args) {
125 System.out.printf(fmt + "\n", args);
128 public static <T> void p(T o) {
129 System.out.println(o);
132 public static void p() {
133 System.out.println();