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.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 /**
  28  * @since 6.0
  29  */
  30 public class AnnotationElementValue extends ElementValue
  31 {
  32         // For annotation element values, this is the annotation
  33         private final AnnotationEntry annotationEntry;
  34 
  35         public AnnotationElementValue(final int type, final AnnotationEntry annotationEntry,
  36                         final ConstantPool cpool)
  37         {
  38                 super(type, cpool);
  39                 if (type != ANNOTATION) {
  40                     throw new RuntimeException(
  41                                     "Only element values of type annotation can be built with this ctor - type specified: " + type);
  42                 }
  43                 this.annotationEntry = annotationEntry;
  44         }
  45 
  46         @Override
  47         public void dump(final DataOutputStream dos) throws IOException
  48         {
  49                 dos.writeByte(super.getType()); // u1 type of value (ANNOTATION == '@')
  50                 annotationEntry.dump(dos);
  51         }
  52 
  53         @Override
  54         public String stringifyValue()
  55         {
  56                 return annotationEntry.toString();
  57         }
  58 
  59         @Override
  60         public String toString()
  61         {
  62                 return stringifyValue();
  63         }
  64 
  65         public AnnotationEntry getAnnotationEntry()
  66         {
  67                 return annotationEntry;
  68         }
  69 }