2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.dx.cf.attrib;
19 import com.android.dx.rop.annotation.Annotations;
20 import com.android.dx.util.MutabilityException;
23 * Base class for annotations attributes.
25 public abstract class BaseAnnotations extends BaseAttribute {
26 /** {@code non-null;} list of annotations */
27 private final Annotations annotations;
29 /** {@code >= 0;} attribute data length in the original classfile (not
30 * including the attribute header) */
31 private final int byteLength;
34 * Constructs an instance.
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)
41 public BaseAnnotations(String attributeName, Annotations annotations,
46 if (annotations.isMutable()) {
47 throw new MutabilityException("annotations.isMutable()");
49 } catch (NullPointerException ex) {
50 // Translate the exception.
51 throw new NullPointerException("annotations == null");
54 this.annotations = annotations;
55 this.byteLength = byteLength;
59 public final int byteLength() {
60 // Add six for the standard attribute header.
61 return byteLength + 6;
65 * Gets the list of annotations associated with this instance.
67 * @return {@code non-null;} the list
69 public final Annotations getAnnotations() {