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 17package com.android.dx.cf.attrib; 18 19import com.android.dx.rop.annotation.Annotations; 20import com.android.dx.util.MutabilityException; 21 22/** 23 * Base class for annotations attributes. 24 */ 25public abstract class BaseAnnotations extends BaseAttribute { 26 /** {@code non-null;} list of annotations */ 27 private final Annotations annotations; 28 29 /** {@code >= 0;} attribute data length in the original classfile (not 30 * including the attribute header) */ 31 private final int byteLength; 32 33 /** 34 * Constructs an instance. 35 * 36 * @param attributeName {@code non-null;} the name of the attribute 37 * @param annotations {@code non-null;} the list of annotations 38 * @param byteLength {@code >= 0;} attribute data length in the original 39 * classfile (not including the attribute header) 40 */ 41 public BaseAnnotations(String attributeName, Annotations annotations, 42 int byteLength) { 43 super(attributeName); 44 45 try { 46 if (annotations.isMutable()) { 47 throw new MutabilityException("annotations.isMutable()"); 48 } 49 } catch (NullPointerException ex) { 50 // Translate the exception. 51 throw new NullPointerException("annotations == null"); 52 } 53 54 this.annotations = annotations; 55 this.byteLength = byteLength; 56 } 57 58 /** {@inheritDoc} */ 59 public final int byteLength() { 60 // Add six for the standard attribute header. 61 return byteLength + 6; 62 } 63 64 /** 65 * Gets the list of annotations associated with this instance. 66 * 67 * @return {@code non-null;} the list 68 */ 69 public final Annotations getAnnotations() { 70 return annotations; 71 } 72} 73