001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.bcel.classfile;
020
021import java.io.DataOutputStream;
022import java.io.IOException;
023
024/**
025 * @since 6.0
026 */
027public class AnnotationElementValue extends ElementValue {
028    // For annotation element values, this is the annotation
029    private final AnnotationEntry annotationEntry;
030
031    public AnnotationElementValue(final int type, final AnnotationEntry annotationEntry, final ConstantPool cpool) {
032        super(type, cpool);
033        if (type != ANNOTATION) {
034            throw new ClassFormatException("Only element values of type annotation can be built with this ctor - type specified: " + type);
035        }
036        this.annotationEntry = annotationEntry;
037    }
038
039    @Override
040    public void dump(final DataOutputStream dos) throws IOException {
041        dos.writeByte(super.getType()); // u1 type of value (ANNOTATION == '@')
042        annotationEntry.dump(dos);
043    }
044
045    public AnnotationEntry getAnnotationEntry() {
046        return annotationEntry;
047    }
048
049    @Override
050    public String stringifyValue() {
051        return annotationEntry.toString();
052    }
053
054    @Override
055    public String toString() {
056        return stringifyValue();
057    }
058}