Home | History | Annotate | Download | only in attrib
      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.cst.Constant;
     20 
     21 /**
     22  * Attribute class for {@code AnnotationDefault} attributes.
     23  */
     24 public final class AttAnnotationDefault extends BaseAttribute {
     25     /** {@code non-null;} attribute name for attributes of this type */
     26     public static final String ATTRIBUTE_NAME = "AnnotationDefault";
     27 
     28     /** {@code non-null;} the annotation default value */
     29     private final Constant value;
     30 
     31     /** {@code >= 0;} attribute data length in the original classfile (not
     32      * including the attribute header) */
     33     private final int byteLength;
     34 
     35     /**
     36      * Constructs an instance.
     37      *
     38      * @param value {@code non-null;} the annotation default value
     39      * @param byteLength {@code >= 0;} attribute data length in the original
     40      * classfile (not including the attribute header)
     41      */
     42     public AttAnnotationDefault(Constant value, int byteLength) {
     43         super(ATTRIBUTE_NAME);
     44 
     45         if (value == null) {
     46             throw new NullPointerException("value == null");
     47         }
     48 
     49         this.value = value;
     50         this.byteLength = byteLength;
     51     }
     52 
     53     /** {@inheritDoc} */
     54     @Override
     55     public int byteLength() {
     56         // Add six for the standard attribute header.
     57         return byteLength + 6;
     58     }
     59 
     60     /**
     61      * Gets the annotation default value.
     62      *
     63      * @return {@code non-null;} the value
     64      */
     65     public Constant getValue() {
     66         return value;
     67     }
     68 }
     69