1 /* 2 * Copyright (C) 2009 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 dex.reader; 18 19 import java.util.HashSet; 20 import java.util.Set; 21 22 import dex.reader.DexFileReader.FieldIdItem; 23 import dex.structure.DexAnnotation; 24 import dex.structure.DexParameter; 25 26 public class DexParameterImpl implements DexParameter { 27 28 private final String typeName; 29 private final Integer annotationOffset; 30 private Set<DexAnnotation> annotations; 31 private final DexBuffer buffer; 32 private final int[] typeIds; 33 private final String[] stringPool; 34 private final FieldIdItem[] fieldIdItems; 35 36 public DexParameterImpl(DexBuffer buffer, String typeName, 37 Integer annotationOffset, int[] typeIds, String[] stringPool, 38 FieldIdItem[] fieldIdItems) { 39 this.buffer = buffer; 40 this.typeName = typeName; 41 this.annotationOffset = annotationOffset; 42 this.typeIds = typeIds; 43 this.stringPool = stringPool; 44 this.fieldIdItems = fieldIdItems; 45 parseAnnotations(); 46 } 47 48 private void parseAnnotations() { 49 annotations = new HashSet<DexAnnotation>(); 50 if (annotationOffset != null) { 51 buffer.setPosition(annotationOffset); 52 final int size = buffer.readUInt(); 53 for (int i = 0; i < size; i++) { 54 annotations.add(new DexAnnotationImpl(buffer.createCopy(), 55 buffer.readUInt(), typeIds, stringPool, fieldIdItems)); 56 } 57 } 58 } 59 60 public String getTypeName() { 61 return typeName; 62 } 63 64 public Set<DexAnnotation> getAnnotations() { 65 return annotations; 66 } 67 68 @Override 69 public String toString() { 70 return getTypeName(); 71 } 72 } 73