1579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson/* 2579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Copyright (C) 2007 The Android Open Source Project 3579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 4579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * you may not use this file except in compliance with the License. 6579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * You may obtain a copy of the License at 7579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 8579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 10579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * See the License for the specific language governing permissions and 14579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * limitations under the License. 15579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 16579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 17579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonpackage com.android.dx.rop.cst; 18579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 19579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonimport com.android.dx.rop.annotation.Annotation; 20579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 21579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson/** 22579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Constant type that represents an annotation. 23579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 24579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonpublic final class CstAnnotation extends Constant { 25579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code non-null;} the actual annotation */ 26579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson private final Annotation annotation; 27579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 28579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 29579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Constructs an instance. 30579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 31579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * @param annotation {@code non-null;} the annotation to hold 32579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 33579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public CstAnnotation(Annotation annotation) { 34579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson if (annotation == null) { 35579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson throw new NullPointerException("annotation == null"); 36579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 37579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 38579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson annotation.throwIfMutable(); 39579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 40579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson this.annotation = annotation; 41579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 42579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 43579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 44579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson @Override 45579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public boolean equals(Object other) { 46579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson if (! (other instanceof CstAnnotation)) { 47579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return false; 48579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 49579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 50579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return annotation.equals(((CstAnnotation) other).annotation); 51579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 52579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 53579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 54579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson @Override 55579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public int hashCode() { 56579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return annotation.hashCode(); 57579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 58579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 59579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 60579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson @Override 61579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson protected int compareTo0(Constant other) { 62579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return annotation.compareTo(((CstAnnotation) other).annotation); 63579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 64579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 65579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 66579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson @Override 67579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public String toString() { 68579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return annotation.toString(); 69579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 70579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 71579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 72579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson @Override 73579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public String typeName() { 74579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return "annotation"; 75579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 76579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 77579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 78579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson @Override 79579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public boolean isCategory2() { 80579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return false; 81579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 82579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 83579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@inheritDoc} */ 84579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public String toHuman() { 85579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return annotation.toString(); 86579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 87579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 88579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 89579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Get the underlying annotation. 90579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 91579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * @return {@code non-null;} the annotation 92579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 93579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public Annotation getAnnotation() { 94579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return annotation; 95579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 96579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson} 97