|
|
|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.bcel.internal.classfile; |
|
|
|
import java.io.DataInput; |
|
import java.io.DataOutputStream; |
|
import java.io.IOException; |
|
|
|
import com.sun.org.apache.bcel.internal.Const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public final class ConstantValue extends Attribute { |
|
|
|
private int constantvalue_index; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ConstantValue(final ConstantValue c) { |
|
this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(), c.getConstantPool()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
ConstantValue(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool) |
|
throws IOException { |
|
this(name_index, length, input.readUnsignedShort(), constant_pool); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ConstantValue(final int name_index, final int length, final int constantvalue_index, |
|
final ConstantPool constant_pool) { |
|
super(Const.ATTR_CONSTANT_VALUE, name_index, length, constant_pool); |
|
this.constantvalue_index = constantvalue_index; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public void accept( final Visitor v ) { |
|
v.visitConstantValue(this); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public final void dump( final DataOutputStream file ) throws IOException { |
|
super.dump(file); |
|
file.writeShort(constantvalue_index); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public final int getConstantValueIndex() { |
|
return constantvalue_index; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public final void setConstantValueIndex( final int constantvalue_index ) { |
|
this.constantvalue_index = constantvalue_index; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public final String toString() { |
|
Constant c = super.getConstantPool().getConstant(constantvalue_index); |
|
String buf; |
|
int i; |
|
|
|
switch (c.getTag()) { |
|
case Const.CONSTANT_Long: |
|
buf = String.valueOf(((ConstantLong) c).getBytes()); |
|
break; |
|
case Const.CONSTANT_Float: |
|
buf = String.valueOf(((ConstantFloat) c).getBytes()); |
|
break; |
|
case Const.CONSTANT_Double: |
|
buf = String.valueOf(((ConstantDouble) c).getBytes()); |
|
break; |
|
case Const.CONSTANT_Integer: |
|
buf = String.valueOf(((ConstantInteger) c).getBytes()); |
|
break; |
|
case Const.CONSTANT_String: |
|
i = ((ConstantString) c).getStringIndex(); |
|
c = super.getConstantPool().getConstant(i, Const.CONSTANT_Utf8); |
|
buf = "\"" + Utility.convertString(((ConstantUtf8) c).getBytes()) + "\""; |
|
break; |
|
default: |
|
throw new IllegalStateException("Type of ConstValue invalid: " + c); |
|
} |
|
return buf; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public Attribute copy( final ConstantPool _constant_pool ) { |
|
final ConstantValue c = (ConstantValue) clone(); |
|
c.setConstantPool(_constant_pool); |
|
return c; |
|
} |
|
} |