1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.classfile;
  23 
  24 import java.io.DataInput;
  25 import java.io.DataOutputStream;
  26 import java.io.IOException;
  27 
  28 import com.sun.org.apache.bcel.internal.Const;
  29 
  30 /**
  31  * Represents the default value of a annotation for a method info
  32  *
  33  * @since 6.0
  34  */
  35 public class AnnotationDefault extends Attribute {
  36 
  37     private ElementValue default_value;
  38 
  39     /**
  40      * @param name_index    Index pointing to the name <em>Code</em>
  41      * @param length        Content length in bytes
  42      * @param input         Input stream
  43      * @param constant_pool Array of constants
  44      */
  45     AnnotationDefault(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool) throws IOException {
  46         this(name_index, length, (ElementValue) null, constant_pool);
  47         default_value = ElementValue.readElementValue(input, constant_pool);
  48     }
  49 
  50     /**
  51      * @param name_index    Index pointing to the name <em>Code</em>
  52      * @param length        Content length in bytes
  53      * @param defaultValue  the annotation's default value
  54      * @param constant_pool Array of constants
  55      */
  56     public AnnotationDefault(final int name_index, final int length, final ElementValue defaultValue, final ConstantPool constant_pool) {
  57         super(Const.ATTR_ANNOTATION_DEFAULT, name_index, length, constant_pool);
  58         this.default_value = defaultValue;
  59     }
  60 
  61     /**
  62      * Called by objects that are traversing the nodes of the tree implicitely
  63      * defined by the contents of a Java class. I.e., the hierarchy of methods,
  64      * fields, attributes, etc. spawns a tree of objects.
  65      *
  66      * @param v Visitor object
  67      */
  68     @Override
  69     public void accept(final Visitor v) {
  70         v.visitAnnotationDefault(this);
  71     }
  72 
  73     /**
  74      * @param defaultValue the default value of this methodinfo's annotation
  75      */
  76     public final void setDefaultValue(final ElementValue defaultValue) {
  77         default_value = defaultValue;
  78     }
  79 
  80     /**
  81      * @return the default value
  82      */
  83     public final ElementValue getDefaultValue() {
  84         return default_value;
  85     }
  86 
  87     @Override
  88     public Attribute copy(final ConstantPool _constant_pool) {
  89         return (Attribute) clone();
  90     }
  91 
  92     @Override
  93     public final void dump(final DataOutputStream dos) throws IOException {
  94         super.dump(dos);
  95         default_value.dump(dos);
  96     }
  97 }