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.dexgen.rop;
18 
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 
23 /**
24  * Standard implementation of {@link Member}, which directly stores
25  * all the associated data.
26  */
27 public abstract class StdMember implements Member {
28     /** {@code non-null;} the defining class */
29     private final CstType definingClass;
30 
31     /** access flags */
32     private final int accessFlags;
33 
34     /** {@code non-null;} member name and type */
35     private final CstNat nat;
36 
37     /** {@code non-null;} list of associated attributes */
38     private final AttributeList attributes;
39 
40     /**
41      * Constructs an instance.
42      *
43      * @param definingClass {@code non-null;} the defining class
44      * @param accessFlags access flags
45      * @param nat {@code non-null;} member name and type (descriptor)
46      * @param attributes {@code non-null;} list of associated attributes
47      */
StdMember(CstType definingClass, int accessFlags, CstNat nat, AttributeList attributes)48     public StdMember(CstType definingClass, int accessFlags, CstNat nat,
49                      AttributeList attributes) {
50         if (definingClass == null) {
51             throw new NullPointerException("definingClass == null");
52         }
53 
54         if (nat == null) {
55             throw new NullPointerException("nat == null");
56         }
57 
58         if (attributes == null) {
59             throw new NullPointerException("attributes == null");
60         }
61 
62         this.definingClass = definingClass;
63         this.accessFlags = accessFlags;
64         this.nat = nat;
65         this.attributes = attributes;
66     }
67 
68     /** {@inheritDoc} */
69     @Override
toString()70     public String toString() {
71         StringBuffer sb = new StringBuffer(100);
72 
73         sb.append(getClass().getName());
74         sb.append('{');
75         sb.append(nat.toHuman());
76         sb.append('}');
77 
78         return sb.toString();
79     }
80 
81     /** {@inheritDoc} */
getDefiningClass()82     public final CstType getDefiningClass() {
83         return definingClass;
84     }
85 
86     /** {@inheritDoc} */
getAccessFlags()87     public final int getAccessFlags() {
88         return accessFlags;
89     }
90 
91     /** {@inheritDoc} */
getNat()92     public final CstNat getNat() {
93         return nat;
94     }
95 
96     /** {@inheritDoc} */
getName()97     public final CstUtf8 getName() {
98         return nat.getName();
99     }
100 
101     /** {@inheritDoc} */
getDescriptor()102     public final CstUtf8 getDescriptor() {
103         return nat.getDescriptor();
104     }
105 
106     /** {@inheritDoc} */
getAttributes()107     public final AttributeList getAttributes() {
108         return attributes;
109     }
110 }
111