1 /*
2  * Copyright (C) 2017 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 package art;
18 
19 import java.lang.reflect.Proxy;
20 import java.util.Arrays;
21 import java.util.Base64;
22 
23 public class Test992 {
24 
25   static class Target1 { }
26 
run()27   public static void run() {
28     doTest(Test992.class);
29     doTest(Target1.class);
30     doTest(Target2.class);
31     doTest(Integer.TYPE);
32     doTest(Integer.class);
33     doTest(Object.class);
34     doTest(Runnable.class);
35     doTest(new Object[0].getClass());
36     doTest(new int[0].getClass());
37     doTest(null);
38     doTest(Proxy.getProxyClass(Test992.class.getClassLoader(), Runnable.class));
39   }
40 
printClass(Class<?> k)41   public static String printClass(Class<?> k) {
42     if (k != null && Proxy.class.isAssignableFrom(k)) {
43       return String.format("Proxy of %s", Arrays.toString(k.getInterfaces()));
44     } else {
45       return String.format("%s", k);
46     }
47   }
doTest(Class<?> k)48   public static void doTest(Class<?> k) {
49     String pk = printClass(k);
50     try {
51       System.out.println(pk + " is defined in file \"" + getSourceFileName(k) + "\"");
52     } catch (Exception e) {
53       System.out.println(pk + " does not have a known source file because " + e);
54     }
55     try {
56       System.out.println(pk + " has extension \"" + getSourceDebugExtension(k) + "\"");
57     } catch (Exception e) {
58       System.out.println(pk + " does not have a known source file extension because " + e);
59     }
60   }
61 
getSourceFileName(Class<?> k)62   public static native String getSourceFileName(Class<?> k) throws Exception;
getSourceDebugExtension(Class<?> k)63   public static native String getSourceDebugExtension(Class<?> k) throws Exception;
64 }
65