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.direct; 18 19 import com.android.dx.cf.iface.AttributeList; 20 import com.android.dx.cf.iface.Member; 21 import com.android.dx.cf.iface.StdField; 22 import com.android.dx.cf.iface.StdFieldList; 23 import com.android.dx.rop.code.AccessFlags; 24 import com.android.dx.rop.cst.CstNat; 25 import com.android.dx.rop.cst.CstType; 26 27 /** 28 * Parser for lists of fields in a class file. 29 */ 30 final /*package*/ class FieldListParser extends MemberListParser { 31 /** {@code non-null;} list in progress */ 32 private final StdFieldList fields; 33 34 /** 35 * Constructs an instance. 36 * 37 * @param cf {@code non-null;} the class file to parse from 38 * @param definer {@code non-null;} class being defined 39 * @param offset offset in {@code bytes} to the start of the list 40 * @param attributeFactory {@code non-null;} attribute factory to use 41 */ FieldListParser(DirectClassFile cf, CstType definer, int offset, AttributeFactory attributeFactory)42 public FieldListParser(DirectClassFile cf, CstType definer, int offset, 43 AttributeFactory attributeFactory) { 44 super(cf, definer, offset, attributeFactory); 45 fields = new StdFieldList(getCount()); 46 } 47 48 /** 49 * Gets the parsed list. 50 * 51 * @return {@code non-null;} the parsed list 52 */ getList()53 public StdFieldList getList() { 54 parseIfNecessary(); 55 return fields; 56 } 57 58 /** {@inheritDoc} */ 59 @Override humanName()60 protected String humanName() { 61 return "field"; 62 } 63 64 /** {@inheritDoc} */ 65 @Override humanAccessFlags(int accessFlags)66 protected String humanAccessFlags(int accessFlags) { 67 return AccessFlags.fieldString(accessFlags); 68 } 69 70 /** {@inheritDoc} */ 71 @Override getAttributeContext()72 protected int getAttributeContext() { 73 return AttributeFactory.CTX_FIELD; 74 } 75 76 /** {@inheritDoc} */ 77 @Override set(int n, int accessFlags, CstNat nat, AttributeList attributes)78 protected Member set(int n, int accessFlags, CstNat nat, 79 AttributeList attributes) { 80 StdField field = 81 new StdField(getDefiner(), accessFlags, nat, attributes); 82 83 fields.set(n, field); 84 return field; 85 } 86 } 87