001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.bcel.generic; 019 020import java.io.DataOutputStream; 021import java.io.IOException; 022 023import org.apache.bcel.classfile.AnnotationElementValue; 024import org.apache.bcel.classfile.ElementValue; 025 026/** 027 * @since 6.0 028 */ 029public class AnnotationElementValueGen extends ElementValueGen 030{ 031 // For annotation element values, this is the annotation 032 private final AnnotationEntryGen a; 033 034 public AnnotationElementValueGen(final AnnotationEntryGen a, final ConstantPoolGen cpool) 035 { 036 super(ANNOTATION, cpool); 037 this.a = a; 038 } 039 040 public AnnotationElementValueGen(final int type, final AnnotationEntryGen annotation, 041 final ConstantPoolGen cpool) 042 { 043 super(type, cpool); 044 if (type != ANNOTATION) { 045 throw new RuntimeException( 046 "Only element values of type annotation can be built with this ctor - type specified: " + type); 047 } 048 this.a = annotation; 049 } 050 051 public AnnotationElementValueGen(final AnnotationElementValue value, 052 final ConstantPoolGen cpool, final boolean copyPoolEntries) 053 { 054 super(ANNOTATION, cpool); 055 a = new AnnotationEntryGen(value.getAnnotationEntry(), cpool, copyPoolEntries); 056 } 057 058 @Override 059 public void dump(final DataOutputStream dos) throws IOException 060 { 061 dos.writeByte(super.getElementValueType()); // u1 type of value (ANNOTATION == '@') 062 a.dump(dos); 063 } 064 065 @Override 066 public String stringifyValue() 067 { 068 throw new RuntimeException("Not implemented yet"); 069 } 070 071 /** 072 * Return immutable variant of this AnnotationElementValueGen 073 */ 074 @Override 075 public ElementValue getElementValue() 076 { 077 return new AnnotationElementValue(super.getElementValueType(), 078 a.getAnnotation(), 079 getConstantPool().getConstantPool()); 080 } 081 082 public AnnotationEntryGen getAnnotation() 083 { 084 return a; 085 } 086}