本文整理汇总了Java中org.apache.bcel.classfile.ConstantPool.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java ConstantPool.getLength方法的具体用法?Java ConstantPool.getLength怎么用?Java ConstantPool.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.ConstantPool
的用法示例。
在下文中一共展示了ConstantPool.getLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: flagTests
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
public void flagTests(HashSet<String> tests) {
if (true == _clazz.isAbstract()) {
return;
}
ConstantPool pool = _clazz.getConstantPool();
for (int i = 0; i < pool.getLength(); ++i) {
Constant constant = pool.getConstant(i);
if (null == constant) {
continue;
}
Byte tag = constant.getTag();
if (Constants.CONSTANT_Utf8 != tag) {
continue;
}
String constantAsString = pool.constantToString(constant);
if (constantAsString.contains("Lorg/junit/Test")) {
tests.add(_clazz.getClassName());
}
}
}
示例2: init
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
private void init(JavaClass jclass) {
ConstantPool cp = jclass.getConstantPool();
int numConstants = cp.getLength();
for (int i = 0; i < numConstants; ++i) {
try {
Constant c = cp.getConstant(i);
if (c instanceof ConstantMethodref) {
ConstantMethodref cmr = (ConstantMethodref) c;
ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex(),
CONSTANT_NameAndType);
String methodName = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex(), CONSTANT_Utf8)).getBytes();
String className = cp.getConstantString(cmr.getClassIndex(), CONSTANT_Class).replace('/', '.');
String methodSig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex(), CONSTANT_Utf8)).getBytes();
String classNameLC = className.toLowerCase();
String methodNameLC = methodName.toLowerCase();
boolean voidReturnType = methodSig.endsWith(")V");
boolean boolReturnType = methodSig.endsWith(")Z");
if (DEBUG) {
System.out.print("Is " + className + "." + methodName + " assertion method: " + voidReturnType);
}
if (isUserAssertionMethod(className, methodName)
|| className.endsWith("Assert")
&& methodName.startsWith("is")
|| (voidReturnType || boolReturnType)
&& (classNameLC.indexOf("assert") >= 0 || methodNameLC.startsWith("throw")
|| methodName.startsWith("affirm") || methodName.startsWith("panic")
|| methodName.equals("logTerminal") || methodName.startsWith("logAndThrow")
|| methodNameLC.equals("insist") || methodNameLC.equals("usage")
|| methodNameLC.equals("exit") || methodNameLC.startsWith("fail")
|| methodNameLC.startsWith("fatal") || methodNameLC.indexOf("assert") >= 0
|| methodNameLC.indexOf("legal") >= 0 || methodNameLC.indexOf("error") >= 0
|| methodNameLC.indexOf("abort") >= 0
// || methodNameLC.indexOf("check") >= 0
|| methodNameLC.indexOf("failed") >= 0) || methodName.equals("addOrThrowException")) {
assertionMethodRefSet.set(i);
if (DEBUG) {
System.out.println("==> YES");
}
} else {
if (DEBUG) {
System.out.println("==> NO");
}
}
}
} catch (ClassFormatException e) {
// FIXME: should report
}
}
}
示例3: init
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
private void init(JavaClass jclass) {
ConstantPool cp = jclass.getConstantPool();
int numConstants = cp.getLength();
for (int i = 0; i < numConstants; ++i) {
try {
Constant c = cp.getConstant(i);
if (c instanceof ConstantMethodref) {
ConstantMethodref cmr = (ConstantMethodref) c;
ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex(),
CONSTANT_NameAndType);
String methodName = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex(), CONSTANT_Utf8)).getBytes();
String className = cp.getConstantString(cmr.getClassIndex(), CONSTANT_Class).replace('/', '.');
String methodSig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex(), CONSTANT_Utf8)).getBytes();
String classNameLC = className.toLowerCase();
String methodNameLC = methodName.toLowerCase();
boolean voidReturnType = methodSig.endsWith(")V");
boolean boolReturnType = methodSig.endsWith(")Z");
if (DEBUG) {
System.out.print("Is " + className + "." + methodName + " assertion method: " + voidReturnType);
}
if (isUserAssertionMethod(className, methodName)
|| className.endsWith("Assert")
&& methodName.startsWith("is")
|| (voidReturnType || boolReturnType)
&& (classNameLC.indexOf("assert") >= 0 || methodNameLC.startsWith("throw")
|| methodName.startsWith("affirm") || methodName.startsWith("panic")
|| methodName.equals("logTerminal") || methodName.startsWith("logAndThrow")
|| methodNameLC.equals("insist") || methodNameLC.equals("usage")
|| methodNameLC.equals("exit") || methodNameLC.startsWith("fail")
|| methodNameLC.startsWith("fatal") || methodNameLC.indexOf("assert") >= 0
|| methodNameLC.indexOf("legal") >= 0 || methodNameLC.indexOf("error") >= 0
|| methodNameLC.indexOf("abort") >= 0
// || methodNameLC.indexOf("check") >= 0
|| methodNameLC.indexOf("failed") >= 0) || methodName.equals("addOrThrowException")) {
assertionMethodRefSet.set(i);
if (DEBUG) {
System.out.println("==> YES");
}
} else {
if (DEBUG) {
System.out.println("==> NO");
}
}
}
} catch (ClassFormatException e) {
// FIXME: should report
}
}
}