本文整理汇总了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);
}