    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 */
    017package org.apache.bcel.classfile;
    018
    019import java.io.DataOutputStream;
    020import java.io.IOException;
    021
    022/**
    023 * @since 6.0
    024 */
    025public class ClassElementValue extends ElementValue {
    026    // For primitive types and string type, this points to the value entry in
    027    // the cpool
    028    // For 'class' this points to the class entry in the cpool
    029    private final int idx;
    030
    031    public ClassElementValue(final int type, final int idx, final ConstantPool cpool) {
    032        super(type, cpool);
    033        this.idx = idx;
    034    }
    035
    036    @Override
    037    public void dump(final DataOutputStream dos) throws IOException {
    038        dos.writeByte(super.getType()); // u1 kind of value
    039        dos.writeShort(idx);
    040    }
    041
    042    public String getClassString() {
    043        return super.getConstantPool().getConstantUtf8(idx).getBytes();
    044    }
    045
    046    public int getIndex() {
    047        return idx;
    048    }
    049
    050    @Override
    051    public String stringifyValue() {
    052        return super.getConstantPool().getConstantUtf8(idx).getBytes();
    053    }
    054}