Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 import java.lang.reflect.Method;
     18 
     19 /**
     20  * Test reflection on old-style inner classes.
     21  */
     22 public class Main {
     23     /*
     24     // Main$1.j
     25     private static Runnable theRunnable = new Runnable() {
     26             public void run() { }
     27         };
     28 
     29     // Main$1.2
     30     private static Runnable create() {
     31         return new Runnable() {
     32                 public void run() { }
     33             };
     34     }
     35     */
     36 
     37     private static String nameOf(Class clazz) {
     38         return (clazz == null) ? "(null)" : clazz.getName();
     39     }
     40 
     41     private static String nameOf(Method meth) {
     42         return (meth == null) ? "(null)" : meth.toString();
     43     }
     44 
     45     private static void infoFor(Class clazz) {
     46         System.out.println("Class: " + nameOf(clazz) + "\n" +
     47                 "  getDeclaringClass(): " +
     48                 nameOf(clazz.getDeclaringClass()) + "\n" +
     49                 "  getEnclosingClass(): " +
     50                 nameOf(clazz.getEnclosingClass()) + "\n" +
     51                 "  getEnclosingMethod(): " +
     52                 nameOf(clazz.getEnclosingMethod()));
     53     }
     54 
     55     public static void main(String args[]) throws ClassNotFoundException {
     56         infoFor(Class.forName("Main$1"));
     57         infoFor(Class.forName("Main$2"));
     58     }
     59 }
     60