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 */ 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 StringBuilder sb = new StringBuilder(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 @Override getDefiningClass()83 public final CstType getDefiningClass() { 84 return definingClass; 85 } 86 87 /** {@inheritDoc} */ 88 @Override getAccessFlags()89 public final int getAccessFlags() { 90 return accessFlags; 91 } 92 93 /** {@inheritDoc} */ 94 @Override getNat()95 public final CstNat getNat() { 96 return nat; 97 } 98 99 /** {@inheritDoc} */ 100 @Override getName()101 public final CstString getName() { 102 return nat.getName(); 103 } 104 105 /** {@inheritDoc} */ 106 @Override getDescriptor()107 public final CstString getDescriptor() { 108 return nat.getDescriptor(); 109 } 110 111 /** {@inheritDoc} */ 112 @Override getAttributes()113 public final AttributeList getAttributes() { 114 return attributes; 115 } 116 } 117