本文整理匯總了Java中org.apache.bcel.classfile.ConstantObject類的典型用法代碼示例。如果您正苦於以下問題:Java ConstantObject類的具體用法?Java ConstantObject怎麽用?Java ConstantObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ConstantObject類屬於org.apache.bcel.classfile包,在下文中一共展示了ConstantObject類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getConstantPool
import org.apache.bcel.classfile.ConstantObject; //導入依賴的package包/類
public static Set<Object> getConstantPool(InputStream is, String name) throws ClassFormatException, IOException {
HashSet<Object> constants = new HashSet<Object>();
ClassParser parser = new ClassParser(is, name);
ConstantPool pool = parser.parse().getConstantPool();
for (Constant constant : pool.getConstantPool()) {
//Strings used in code are stored using String constant, they are just references to Utf8 constant
//but we can't use Utf8 constants because they are used to store field/method/class names and signatures too
if (constant instanceof ConstantString) {
String string = (String) ((ConstantString) constant).getConstantValue(pool);
//skip empty string
if (string.isEmpty()) {
continue;
}
constants.add(string);
}
if (constant instanceof ConstantInteger || constant instanceof ConstantLong || constant instanceof ConstantFloat || constant instanceof ConstantDouble) {
constants.add(((ConstantObject) constant).getConstantValue(pool));
}
}
return constants;
}
示例2: setValue
import org.apache.bcel.classfile.ConstantObject; //導入依賴的package包/類
private void setValue( int index ) {
ConstantPool cp = this.cp.getConstantPool();
Constant c = cp.getConstant(index);
value = ((ConstantObject) c).getConstantValue(cp);
}