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 dex.reader.DexFileReader.FieldIdItem;
20 import dex.structure.DexAnnotation;
21 import dex.structure.DexAnnotationAttribute;
22 import dex.structure.DexEncodedAnnotation;
23 import dex.structure.DexEncodedValueType;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 /* package */final class DexEncodedAnnotationImpl implements
29         DexEncodedAnnotation {
30 
31     private List<DexAnnotationAttribute> values;
32     private final DexBuffer buffer;
33     private final int[] typeIds;
34     private final String[] stringPool;
35     private int typeIdx;
36     private final FieldIdItem[] fieldIdItems;
37     private final DexAnnotation annotation;
38 
DexEncodedAnnotationImpl(DexBuffer buffer, DexAnnotation annotation, int[] typeIds, String[] stringPool, FieldIdItem[] fieldIdItems)39     public DexEncodedAnnotationImpl(DexBuffer buffer, DexAnnotation annotation,
40             int[] typeIds, String[] stringPool, FieldIdItem[] fieldIdItems) {
41         this.buffer = buffer;
42         this.annotation = annotation;
43         this.typeIds = typeIds;
44         this.stringPool = stringPool;
45         this.fieldIdItems = fieldIdItems;
46         parseEncodedAnnotation();
47     }
48 
parseEncodedAnnotation()49     private void parseEncodedAnnotation() {
50         typeIdx = buffer.readUleb128();
51         int size = buffer.readUleb128();
52         values = new ArrayList<DexAnnotationAttribute>(size);
53         for (int j = 0; j < size; j++) {
54             values.add(new DexAnnotationAttributeImpl(buffer, annotation,
55                     typeIds, stringPool, fieldIdItems));
56         }
57     }
58 
getType()59     public DexEncodedValueType getType() {
60         return DexEncodedValueType.VALUE_ANNOTATION;
61     }
62 
getValue()63     public List<DexAnnotationAttribute> getValue() {
64         return values;
65     }
66 
getTypeName()67     public String getTypeName() {
68         return stringPool[typeIds[typeIdx]];
69     }
70 
71     @Override
toString()72     public String toString() {
73         return getTypeName() + ":" + getValue();
74     }
75 }
76