1 /* 2 * Copyright (C) 2011 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.dex; 18 19 import static com.android.dex.EncodedValueReader.ENCODED_ANNOTATION; 20 21 /** 22 * An annotation. 23 */ 24 public final class Annotation implements Comparable<Annotation> { 25 private final Dex dex; 26 private final byte visibility; 27 private final EncodedValue encodedAnnotation; 28 Annotation(Dex dex, byte visibility, EncodedValue encodedAnnotation)29 public Annotation(Dex dex, byte visibility, EncodedValue encodedAnnotation) { 30 this.dex = dex; 31 this.visibility = visibility; 32 this.encodedAnnotation = encodedAnnotation; 33 } 34 getVisibility()35 public byte getVisibility() { 36 return visibility; 37 } 38 getReader()39 public EncodedValueReader getReader() { 40 return new EncodedValueReader(encodedAnnotation, ENCODED_ANNOTATION); 41 } 42 getTypeIndex()43 public int getTypeIndex() { 44 EncodedValueReader reader = getReader(); 45 reader.readAnnotation(); 46 return reader.getAnnotationType(); 47 } 48 writeTo(Dex.Section out)49 public void writeTo(Dex.Section out) { 50 out.writeByte(visibility); 51 encodedAnnotation.writeTo(out); 52 } 53 54 @Override compareTo(Annotation other)55 public int compareTo(Annotation other) { 56 return encodedAnnotation.compareTo(other.encodedAnnotation); 57 } 58 59 @Override toString()60 public String toString() { 61 return dex == null 62 ? visibility + " " + getTypeIndex() 63 : visibility + " " + dex.typeNames().get(getTypeIndex()); 64 } 65 } 66