View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.bcel.generic;
20  
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  import org.apache.bcel.classfile.AnnotationElementValue;
25  import org.apache.bcel.classfile.ElementValue;
26  
27  /**
28   * @since 6.0
29   */
30  public class AnnotationElementValueGen extends ElementValueGen {
31      // For annotation element values, this is the annotation
32      private final AnnotationEntryGen a;
33  
34      public AnnotationElementValueGen(final AnnotationElementValue value, final ConstantPoolGen cpool, final boolean copyPoolEntries) {
35          super(ANNOTATION, cpool);
36          a = new AnnotationEntryGen(value.getAnnotationEntry(), cpool, copyPoolEntries);
37      }
38  
39      public AnnotationElementValueGen(final AnnotationEntryGen a, final ConstantPoolGen cpool) {
40          super(ANNOTATION, cpool);
41          this.a = a;
42      }
43  
44      public AnnotationElementValueGen(final int type, final AnnotationEntryGen annotation, final ConstantPoolGen cpool) {
45          super(type, cpool);
46          if (type != ANNOTATION) {
47              throw new IllegalArgumentException("Only element values of type annotation can be built with this ctor - type specified: " + type);
48          }
49          this.a = annotation;
50      }
51  
52      @Override
53      public void dump(final DataOutputStream dos) throws IOException {
54          dos.writeByte(super.getElementValueType()); // u1 type of value (ANNOTATION == '@')
55          a.dump(dos);
56      }
57  
58      public AnnotationEntryGen getAnnotation() {
59          return a;
60      }
61  
62      /**
63       * Return immutable variant of this AnnotationElementValueGen
64       */
65      @Override
66      public ElementValue getElementValue() {
67          return new AnnotationElementValue(super.getElementValueType(), a.getAnnotation(), getConstantPool().getConstantPool());
68      }
69  
70      @Override
71      public String stringifyValue() {
72          throw new UnsupportedOperationException("Not implemented yet");
73      }
74  }