1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 /* 18 * Copyright (C) 2008 The Android Open Source Project 19 * 20 * Licensed under the Apache License, Version 2.0 (the "License"); 21 * you may not use this file except in compliance with the License. 22 * You may obtain a copy of the License at 23 * 24 * http://www.apache.org/licenses/LICENSE-2.0 25 * 26 * Unless required by applicable law or agreed to in writing, software 27 * distributed under the License is distributed on an "AS IS" BASIS, 28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 * See the License for the specific language governing permissions and 30 * limitations under the License. 31 */ 32 33 package java.lang.reflect; 34 35 import com.android.dex.Dex; 36 37 /** 38 * @hide 39 */ 40 public final class ArtField { 41 42 private Class<?> declaringClass; 43 /** Field access flags (modifiers) */ 44 private int accessFlags; 45 /** Index into DexFile's field ids */ 46 private int fieldDexIndex; 47 /** Offset of field in object or class */ 48 private int offset; 49 50 /** 51 * Only created by art directly. 52 */ 53 private ArtField() {} 54 55 public int getAccessFlags() { 56 return accessFlags; 57 } 58 59 int getDexFieldIndex() { 60 return fieldDexIndex; 61 } 62 63 int getOffset() { 64 return offset; 65 } 66 67 public String getName() { 68 if (fieldDexIndex == -1) { 69 // Proxy classes have 1 synthesized static field with no valid dex index 70 if (!declaringClass.isProxy()) { 71 throw new AssertionError(); 72 } 73 return "throws"; 74 } 75 Dex dex = declaringClass.getDex(); 76 int nameIndex = dex.nameIndexFromFieldIndex(fieldDexIndex); 77 return declaringClass.getDexCacheString(dex, nameIndex); 78 } 79 80 Class<?> getDeclaringClass() { 81 return declaringClass; 82 } 83 84 Class<?> getType() { 85 if (fieldDexIndex == -1) { 86 // The type of the synthesized field in a Proxy class is Class[][] 87 if (!declaringClass.isProxy()) { 88 throw new AssertionError(); 89 } 90 return Class[][].class; 91 } 92 Dex dex = declaringClass.getDex(); 93 int typeIndex = dex.typeIndexFromFieldIndex(fieldDexIndex); 94 return declaringClass.getDexCacheType(dex, typeIndex); 95 } 96 } 97