blob: a2dc7e15cc95fdea607dc9e66d46d13be275933e [file] [log] [blame]
Andreas Gampee492ae32016-10-28 19:34:57 -07001/*
2 * Copyright (C) 2016 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
17import java.lang.reflect.Proxy;
18import java.util.Arrays;
19
20public class Main {
21 public static void main(String[] args) throws Exception {
22 System.loadLibrary(args[1]);
23
24 doTest();
25 }
26
27 public static void doTest() throws Exception {
28 testClass("java.lang.Object");
29 testClass("java.lang.String");
30 testClass("java.lang.Math");
31 testClass("java.util.List");
32
33 testClass(getProxyClass());
34
35 testClass(int.class);
36 testClass(double[].class);
Andreas Gampe4fd66ec2017-01-05 14:42:13 -080037
38 testClassType(int.class);
39 testClassType(getProxyClass());
40 testClassType(Runnable.class);
41 testClassType(String.class);
42
43 testClassType(int[].class);
44 testClassType(Runnable[].class);
45 testClassType(String[].class);
Andreas Gampee492ae32016-10-28 19:34:57 -070046 }
47
48 private static Class<?> proxyClass = null;
49
50 private static Class<?> getProxyClass() throws Exception {
51 if (proxyClass != null) {
52 return proxyClass;
53 }
54
55 proxyClass = Proxy.getProxyClass(Main.class.getClassLoader(), new Class[] { Runnable.class });
56 return proxyClass;
57 }
58
59 private static void testClass(String className) throws Exception {
60 Class<?> base = Class.forName(className);
61 testClass(base);
62 }
63
64 private static void testClass(Class<?> base) throws Exception {
65 String[] result = getClassSignature(base);
66 System.out.println(Arrays.toString(result));
67 }
68
Andreas Gampe4fd66ec2017-01-05 14:42:13 -080069 private static void testClassType(Class<?> c) throws Exception {
70 boolean isInterface = isInterface(c);
71 boolean isArray = isArrayClass(c);
72 System.out.println(c.getName() + " interface=" + isInterface + " array=" + isArray);
73 }
74
Andreas Gampee492ae32016-10-28 19:34:57 -070075 private static native String[] getClassSignature(Class<?> c);
Andreas Gampe4fd66ec2017-01-05 14:42:13 -080076
77 private static native boolean isInterface(Class<?> c);
78 private static native boolean isArrayClass(Class<?> c);
Andreas Gampee492ae32016-10-28 19:34:57 -070079}