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.DataInput;
022import java.io.DataOutputStream;
023import java.io.IOException;
024
025import org.apache.bcel.Const;
026
027/**
028 * The type annotations of a class, field, method, record component or {@link Code} attribute, provided to the JVM and visible at runtime.
029 *
030 * @since 6.14.0
031 */
032public class RuntimeVisibleTypeAnnotations extends TypeAnnotations {
033
034    /**
035     * Constructs a new instance.
036     *
037     * @param nameIndex Index pointing to the name of the attribute.
038     * @param length Content length in bytes.
039     * @param input Input stream.
040     * @param constantPool Array of constants.
041     * @throws IOException Thrown when an I/O exception of some sort has occurred.
042     */
043    public RuntimeVisibleTypeAnnotations(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool) throws IOException {
044        super(Const.ATTR_RUNTIME_VISIBLE_TYPE_ANNOTATIONS, nameIndex, length, input, constantPool, true);
045    }
046
047    /**
048     * Creates a deep copy of this attribute, whose type annotations are independent of this one's and refer to the given constant pool.
049     *
050     * @param constantPool The constant pool of the copy.
051     * @return deep copy of this attribute.
052     */
053    @Override
054    public Attribute copy(final ConstantPool constantPool) {
055        final RuntimeVisibleTypeAnnotations c = (RuntimeVisibleTypeAnnotations) clone();
056        c.setConstantPool(constantPool);
057        c.setTypeAnnotationTable(copyTypeAnnotations(constantPool));
058        return c;
059    }
060
061    @Override
062    public final void dump(final DataOutputStream dos) throws IOException {
063        super.dump(dos);
064        writeTypeAnnotations(dos);
065    }
066}