blob: 8af6e7b3751398959e2ffb7d86566751d6f0dc6a [file] [log] [blame]
Andreas Gampeab2f0d02017-01-05 17:23:45 -08001/*
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.Field;
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 testField(Math.class, "PI");
29 testField(Integer.class, "value");
30 testField(Foo.class, "this$0");
31 testField(Bar.class, "VAL");
32 }
33
34 private static void testField(Class<?> base, String fieldName)
35 throws Exception {
36 Field f = base.getDeclaredField(fieldName);
37 String[] result = getFieldName(f);
38 System.out.println(Arrays.toString(result));
39
40 Class<?> declClass = getFieldDeclaringClass(f);
41 if (base != declClass) {
42 throw new RuntimeException("Declaring class not equal: " + base + " vs " + declClass);
43 }
44 System.out.println(declClass);
45
46 int modifiers = getFieldModifiers(f);
47 if (modifiers != f.getModifiers()) {
48 throw new RuntimeException("Modifiers not equal: " + f.getModifiers() + " vs " + modifiers);
49 }
50 System.out.println(modifiers);
51
52 boolean synth = isFieldSynthetic(f);
53 if (synth != f.isSynthetic()) {
54 throw new RuntimeException("Synthetic not equal: " + f.isSynthetic() + " vs " + synth);
55 }
56 System.out.println(synth);
57 }
58
59 private static native String[] getFieldName(Field f);
60 private static native Class<?> getFieldDeclaringClass(Field f);
61 private static native int getFieldModifiers(Field f);
62 private static native boolean isFieldSynthetic(Field f);
63
64 private class Foo {
65 }
66
67 private static interface Bar {
68 public static int VAL = 1;
69 }
70}