Home | History | Annotate | Download | only in iface
      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.rop.cst.CstNat;
     20 import com.android.dx.rop.cst.CstString;
     21 import com.android.dx.rop.cst.CstType;
     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      */
     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
     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} */
     82     public final CstType getDefiningClass() {
     83         return definingClass;
     84     }
     85 
     86     /** {@inheritDoc} */
     87     public final int getAccessFlags() {
     88         return accessFlags;
     89     }
     90 
     91     /** {@inheritDoc} */
     92     public final CstNat getNat() {
     93         return nat;
     94     }
     95 
     96     /** {@inheritDoc} */
     97     public final CstString getName() {
     98         return nat.getName();
     99     }
    100 
    101     /** {@inheritDoc} */
    102     public final CstString getDescriptor() {
    103         return nat.getDescriptor();
    104     }
    105 
    106     /** {@inheritDoc} */
    107     public final AttributeList getAttributes() {
    108         return attributes;
    109     }
    110 }
    111