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