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 // For annotation element values, this is the annotation 031 private final AnnotationEntryGen a; 032 033 public AnnotationElementValueGen(final AnnotationElementValue value, final ConstantPoolGen cpool, final boolean copyPoolEntries) { 034 super(ANNOTATION, cpool); 035 a = new AnnotationEntryGen(value.getAnnotationEntry(), cpool, copyPoolEntries); 036 } 037 038 public AnnotationElementValueGen(final AnnotationEntryGen a, final ConstantPoolGen cpool) { 039 super(ANNOTATION, cpool); 040 this.a = a; 041 } 042 043 public AnnotationElementValueGen(final int type, final AnnotationEntryGen annotation, final ConstantPoolGen cpool) { 044 super(type, cpool); 045 if (type != ANNOTATION) { 046 throw new IllegalArgumentException("Only element values of type annotation can be built with this ctor - type specified: " + type); 047 } 048 this.a = annotation; 049 } 050 051 @Override 052 public void dump(final DataOutputStream dos) throws IOException { 053 dos.writeByte(super.getElementValueType()); // u1 type of value (ANNOTATION == '@') 054 a.dump(dos); 055 } 056 057 public AnnotationEntryGen getAnnotation() { 058 return a; 059 } 060 061 /** 062 * Return immutable variant of this AnnotationElementValueGen 063 */ 064 @Override 065 public ElementValue getElementValue() { 066 return new AnnotationElementValue(super.getElementValueType(), a.getAnnotation(), getConstantPool().getConstantPool()); 067 } 068 069 @Override 070 public String stringifyValue() { 071 throw new UnsupportedOperationException("Not implemented yet"); 072 } 073}