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