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 ClassElementValue extends ElementValue {
028    // For primitive types and string type, this points to the value entry in
029    // the cpool
030    // For 'class' this points to the class entry in the cpool
031    private final int idx;
032
033    public ClassElementValue(final int type, final int idx, final ConstantPool cpool) {
034        super(type, cpool);
035        this.idx = idx;
036    }
037
038    @Override
039    public void dump(final DataOutputStream dos) throws IOException {
040        dos.writeByte(super.getType()); // u1 kind of value
041        dos.writeShort(idx);
042    }
043
044    public String getClassString() {
045        return super.getConstantPool().getConstantUtf8(idx).getBytes();
046    }
047
048    public int getIndex() {
049        return idx;
050    }
051
052    @Override
053    public String stringifyValue() {
054        return super.getConstantPool().getConstantUtf8(idx).getBytes();
055    }
056}