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.dexgen.rop.cst; 18 19 import com.android.dexgen.rop.annotation.Annotation; 20 21 /** 22 * Constant type that represents an annotation. 23 */ 24 public final class CstAnnotation extends Constant { 25 /** {@code non-null;} the actual annotation */ 26 private final Annotation annotation; 27 28 /** 29 * Constructs an instance. 30 * 31 * @param annotation {@code non-null;} the annotation to hold 32 */ CstAnnotation(Annotation annotation)33 public CstAnnotation(Annotation annotation) { 34 if (annotation == null) { 35 throw new NullPointerException("annotation == null"); 36 } 37 38 annotation.throwIfMutable(); 39 40 this.annotation = annotation; 41 } 42 43 /** {@inheritDoc} */ 44 @Override equals(Object other)45 public boolean equals(Object other) { 46 if (! (other instanceof CstAnnotation)) { 47 return false; 48 } 49 50 return annotation.equals(((CstAnnotation) other).annotation); 51 } 52 53 /** {@inheritDoc} */ 54 @Override hashCode()55 public int hashCode() { 56 return annotation.hashCode(); 57 } 58 59 /** {@inheritDoc} */ 60 @Override compareTo0(Constant other)61 protected int compareTo0(Constant other) { 62 return annotation.compareTo(((CstAnnotation) other).annotation); 63 } 64 65 /** {@inheritDoc} */ 66 @Override toString()67 public String toString() { 68 return annotation.toString(); 69 } 70 71 /** {@inheritDoc} */ 72 @Override typeName()73 public String typeName() { 74 return "annotation"; 75 } 76 77 /** {@inheritDoc} */ 78 @Override isCategory2()79 public boolean isCategory2() { 80 return false; 81 } 82 83 /** {@inheritDoc} */ toHuman()84 public String toHuman() { 85 return annotation.toString(); 86 } 87 88 /** 89 * Get the underlying annotation. 90 * 91 * @return {@code non-null;} the annotation 92 */ getAnnotation()93 public Annotation getAnnotation() { 94 return annotation; 95 } 96 } 97