1f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project/*
2f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * Copyright (C) 2009 The Android Open Source Project
3f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *
4f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * you may not use this file except in compliance with the License.
6f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * You may obtain a copy of the License at
7f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *
8f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *
10f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * See the License for the specific language governing permissions and
14f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * limitations under the License.
15f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project */
16f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
17f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectpackage dex.reader;
18f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
19f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport dex.reader.DexFileReader.FieldIdItem;
20f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport dex.structure.DexAnnotation;
21f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport dex.structure.DexAnnotationAttribute;
22f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport dex.structure.DexEncodedAnnotation;
23f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport dex.structure.DexEncodedValueType;
24f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
25f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport java.util.ArrayList;
26f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport java.util.List;
27f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
28f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project/* package */final class DexEncodedAnnotationImpl implements
29f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        DexEncodedAnnotation {
30f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
31f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private List<DexAnnotationAttribute> values;
32f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private final DexBuffer buffer;
33f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private final int[] typeIds;
34f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private final String[] stringPool;
35f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private int typeIdx;
36f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private final FieldIdItem[] fieldIdItems;
37f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private final DexAnnotation annotation;
38f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
39f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public DexEncodedAnnotationImpl(DexBuffer buffer, DexAnnotation annotation,
40f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project            int[] typeIds, String[] stringPool, FieldIdItem[] fieldIdItems) {
41f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        this.buffer = buffer;
42f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        this.annotation = annotation;
43f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        this.typeIds = typeIds;
44f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        this.stringPool = stringPool;
45f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        this.fieldIdItems = fieldIdItems;
46f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        parseEncodedAnnotation();
47f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
48f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
49f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    private void parseEncodedAnnotation() {
50f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        typeIdx = buffer.readUleb128();
51f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        int size = buffer.readUleb128();
52f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        values = new ArrayList<DexAnnotationAttribute>(size);
53f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        for (int j = 0; j < size; j++) {
54f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project            values.add(new DexAnnotationAttributeImpl(buffer, annotation,
55f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    typeIds, stringPool, fieldIdItems));
56f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        }
57f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
58f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
59f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public DexEncodedValueType getType() {
60f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        return DexEncodedValueType.VALUE_ANNOTATION;
61f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
62f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
63f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public List<DexAnnotationAttribute> getValue() {
64f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        return values;
65f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
66f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
67f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public String getTypeName() {
68f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        return stringPool[typeIds[typeIdx]];
69f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
70f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
71f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    @Override
72f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public String toString() {
73f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project        return getTypeName() + ":" + getValue();
74f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
75f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project}
76