2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.dexgen.rop;
19 import com.android.dexgen.rop.cst.CstNat;
20 import com.android.dexgen.rop.cst.CstType;
21 import com.android.dexgen.rop.cst.CstUtf8;
22 import com.android.dexgen.rop.cst.TypedConstant;
25 * Standard implementation of {@link Field}, which directly stores
26 * all the associated data.
28 public final class StdField extends StdMember implements Field {
30 * Constructs an instance.
32 * @param definingClass {@code non-null;} the defining class
33 * @param accessFlags access flags
34 * @param nat {@code non-null;} member name and type (descriptor)
35 * @param attributes {@code non-null;} list of associated attributes
37 public StdField(CstType definingClass, int accessFlags, CstNat nat,
38 AttributeList attributes) {
39 super(definingClass, accessFlags, nat, attributes);
43 * Constructs an instance having Java field as its pattern.
45 * @param field {@code non-null;} pattern for dex field
47 public StdField(java.lang.reflect.Field field) {
48 this(CstType.intern(field.getDeclaringClass()),
50 new CstNat(new CstUtf8(field.getName()),
51 CstType.intern(field.getType()).getDescriptor()),
52 new StdAttributeList(0));
56 * Constructs an instance taking field description as user-friendly arguments.
58 * @param declaringClass {@code non-null;} the class field belongs to
59 * @param type {@code non-null;} type of the field
60 * @param name {@code non-null;} name of the field
61 * @param modifiers access flags of the field
63 public StdField(Class definingClass, Class type, String name, int modifiers) {
64 this(CstType.intern(definingClass),
66 new CstNat(new CstUtf8(name), CstType.intern(type).getDescriptor()),
67 new StdAttributeList(0));
71 public TypedConstant getConstantValue() {
72 AttributeList attribs = getAttributes();
73 AttConstantValue cval = (AttConstantValue)
74 attribs.findFirst(AttConstantValue.ATTRIBUTE_NAME);
80 return cval.getConstantValue();