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