• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package art;
18 
19 import java.io.InterruptedIOException;
20 import java.lang.reflect.Field;
21 import java.util.Arrays;
22 
23 public class Test918 {
run()24     public static void run() throws Exception {
25         doTest();
26     }
27 
doTest()28     public static void doTest() throws Exception {
29         testField(Math.class, "PI");
30         testField(InterruptedIOException.class, "bytesTransferred");
31         testField(Foo.class, "this$0");
32         testField(Bar.class, "VAL");
33         testField(Generics.class, "generics");
34         testField(Generics.class, "privateValue");
35     }
36 
testField(Class<?> base, String fieldName)37     private static void testField(Class<?> base, String fieldName) throws Exception {
38         Field f = base.getDeclaredField(fieldName);
39         String[] result = getFieldName(f);
40         System.out.println(Arrays.toString(result));
41 
42         Class<?> declClass = getFieldDeclaringClass(f);
43         if (base != declClass) {
44             throw new RuntimeException("Declaring class not equal: " + base + " vs " + declClass);
45         }
46         System.out.println(declClass);
47 
48         int modifiers = getFieldModifiers(f);
49         if (modifiers != f.getModifiers()) {
50             throw new RuntimeException(
51                     "Modifiers not equal: " + f.getModifiers() + " vs " + modifiers);
52         }
53         System.out.println(modifiers);
54 
55         boolean synth = isFieldSynthetic(f);
56         if (synth != f.isSynthetic()) {
57             throw new RuntimeException("Synthetic not equal: " + f.isSynthetic() + " vs " + synth);
58         }
59         System.out.println(synth);
60     }
61 
getFieldName(Field f)62     private static native String[] getFieldName(Field f);
getFieldDeclaringClass(Field f)63     private static native Class<?> getFieldDeclaringClass(Field f);
getFieldModifiers(Field f)64     private static native int getFieldModifiers(Field f);
isFieldSynthetic(Field f)65     private static native boolean isFieldSynthetic(Field f);
66 
67     private class Foo {}
68 
69     private static interface Bar {
70         public static int VAL = 1;
71     }
72 
73     private static class Generics<T> {
74         T generics;
75         private int privateValue = 42;
76     }
77 }
78