1 /*
2  * Copyright (C) 2007 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 com.android.dx.cf.iface;
18 
19 import com.android.dx.cf.attrib.AttConstantValue;
20 import com.android.dx.rop.cst.CstNat;
21 import com.android.dx.rop.cst.CstType;
22 import com.android.dx.rop.cst.TypedConstant;
23 
24 /**
25  * Standard implementation of {@link Field}, which directly stores
26  * all the associated data.
27  */
28 public final class StdField extends StdMember implements Field {
29     /**
30      * Constructs an instance.
31      *
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
36      */
StdField(CstType definingClass, int accessFlags, CstNat nat, AttributeList attributes)37     public StdField(CstType definingClass, int accessFlags, CstNat nat,
38                     AttributeList attributes) {
39         super(definingClass, accessFlags, nat, attributes);
40     }
41 
42     /** {@inheritDoc} */
getConstantValue()43     public TypedConstant getConstantValue() {
44         AttributeList attribs = getAttributes();
45         AttConstantValue cval = (AttConstantValue)
46             attribs.findFirst(AttConstantValue.ATTRIBUTE_NAME);
47 
48         if (cval == null) {
49             return null;
50         }
51 
52         return cval.getConstantValue();
53     }
54 }
55