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.attrib; 18 19 import com.android.dx.rop.cst.CstString; 20 import com.android.dx.rop.cst.CstType; 21 import com.android.dx.util.FixedSizeList; 22 23 /** 24 * List of "inner class" entries, which are the contents of 25 * {@code InnerClasses} attributes. 26 */ 27 public final class InnerClassList extends FixedSizeList { 28 /** 29 * Constructs an instance. 30 * 31 * @param count the number of elements to be in the list of inner classes 32 */ InnerClassList(int count)33 public InnerClassList(int count) { 34 super(count); 35 } 36 37 /** 38 * Gets the indicated item. 39 * 40 * @param n {@code >= 0;} which item 41 * @return {@code null-ok;} the indicated item 42 */ get(int n)43 public Item get(int n) { 44 return (Item) get0(n); 45 } 46 47 /** 48 * Sets the item at the given index. 49 * 50 * @param n {@code >= 0, < size();} which class 51 * @param innerClass {@code non-null;} class this item refers to 52 * @param outerClass {@code null-ok;} outer class that this class is a 53 * member of, if any 54 * @param innerName {@code null-ok;} original simple name of this class, 55 * if not anonymous 56 * @param accessFlags original declared access flags 57 */ set(int n, CstType innerClass, CstType outerClass, CstString innerName, int accessFlags)58 public void set(int n, CstType innerClass, CstType outerClass, 59 CstString innerName, int accessFlags) { 60 set0(n, new Item(innerClass, outerClass, innerName, accessFlags)); 61 } 62 63 /** 64 * Item in an inner classes list. 65 */ 66 public static class Item { 67 /** {@code non-null;} class this item refers to */ 68 private final CstType innerClass; 69 70 /** {@code null-ok;} outer class that this class is a member of, if any */ 71 private final CstType outerClass; 72 73 /** {@code null-ok;} original simple name of this class, if not anonymous */ 74 private final CstString innerName; 75 76 /** original declared access flags */ 77 private final int accessFlags; 78 79 /** 80 * Constructs an instance. 81 * 82 * @param innerClass {@code non-null;} class this item refers to 83 * @param outerClass {@code null-ok;} outer class that this class is a 84 * member of, if any 85 * @param innerName {@code null-ok;} original simple name of this 86 * class, if not anonymous 87 * @param accessFlags original declared access flags 88 */ Item(CstType innerClass, CstType outerClass, CstString innerName, int accessFlags)89 public Item(CstType innerClass, CstType outerClass, 90 CstString innerName, int accessFlags) { 91 if (innerClass == null) { 92 throw new NullPointerException("innerClass == null"); 93 } 94 95 this.innerClass = innerClass; 96 this.outerClass = outerClass; 97 this.innerName = innerName; 98 this.accessFlags = accessFlags; 99 } 100 101 /** 102 * Gets the class this item refers to. 103 * 104 * @return {@code non-null;} the class 105 */ getInnerClass()106 public CstType getInnerClass() { 107 return innerClass; 108 } 109 110 /** 111 * Gets the outer class that this item's class is a member of, if any. 112 * 113 * @return {@code null-ok;} the class 114 */ getOuterClass()115 public CstType getOuterClass() { 116 return outerClass; 117 } 118 119 /** 120 * Gets the original name of this item's class, if not anonymous. 121 * 122 * @return {@code null-ok;} the name 123 */ getInnerName()124 public CstString getInnerName() { 125 return innerName; 126 } 127 128 /** 129 * Gets the original declared access flags. 130 * 131 * @return the access flags 132 */ getAccessFlags()133 public int getAccessFlags() { 134 return accessFlags; 135 } 136 } 137 } 138