|
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 * @version $Id: AnnotationDefault 1 2005-02-13 03:15:08Z dbrosius $ |
|
34 * @since 6.0 |
|
35 */ |
|
36 public class AnnotationDefault extends Attribute { |
|
37 |
|
38 private ElementValue default_value; |
|
39 |
|
40 /** |
|
41 * @param name_index Index pointing to the name <em>Code</em> |
|
42 * @param length Content length in bytes |
|
43 * @param input Input stream |
|
44 * @param constant_pool Array of constants |
|
45 */ |
|
46 AnnotationDefault(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool) throws IOException { |
|
47 this(name_index, length, (ElementValue) null, constant_pool); |
|
48 default_value = ElementValue.readElementValue(input, constant_pool); |
|
49 } |
|
50 |
|
51 /** |
|
52 * @param name_index Index pointing to the name <em>Code</em> |
|
53 * @param length Content length in bytes |
|
54 * @param defaultValue the annotation's default value |
|
55 * @param constant_pool Array of constants |
|
56 */ |
|
57 public AnnotationDefault(final int name_index, final int length, final ElementValue defaultValue, final ConstantPool constant_pool) { |
|
58 super(Const.ATTR_ANNOTATION_DEFAULT, name_index, length, constant_pool); |
|
59 this.default_value = defaultValue; |
|
60 } |
|
61 |
|
62 /** |
|
63 * Called by objects that are traversing the nodes of the tree implicitely |
|
64 * defined by the contents of a Java class. I.e., the hierarchy of methods, |
|
65 * fields, attributes, etc. spawns a tree of objects. |
|
66 * |
|
67 * @param v Visitor object |
|
68 */ |
|
69 @Override |
|
70 public void accept(final Visitor v) { |
|
71 v.visitAnnotationDefault(this); |
|
72 } |
|
73 |
|
74 /** |
|
75 * @param defaultValue the default value of this methodinfo's annotation |
|
76 */ |
|
77 public final void setDefaultValue(final ElementValue defaultValue) { |
|
78 default_value = defaultValue; |
|
79 } |
|
80 |
|
81 /** |
|
82 * @return the default value |
|
83 */ |
|
84 public final ElementValue getDefaultValue() { |
|
85 return default_value; |
|
86 } |
|
87 |
|
88 @Override |
|
89 public Attribute copy(final ConstantPool _constant_pool) { |
|
90 return (Attribute) clone(); |
|
91 } |
|
92 |
|
93 @Override |
|
94 public final void dump(final DataOutputStream dos) throws IOException { |
|
95 super.dump(dos); |
|
96 default_value.dump(dos); |
|
97 } |
|
98 } |