本文整理汇总了Java中org.apache.bcel.classfile.ConstantMethodref类的典型用法代码示例。如果您正苦于以下问题:Java ConstantMethodref类的具体用法?Java ConstantMethodref怎么用?Java ConstantMethodref使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantMethodref类属于org.apache.bcel.classfile包,在下文中一共展示了ConstantMethodref类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitConstantMethodref
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
public void visitConstantMethodref(ConstantMethodref ref)
{
ConstantPool pool = javaClass.getConstantPool();
String cstr = ref.getClass(pool);
if (cstr.equals("java.lang.Class"))
{
int iname = ref.getNameAndTypeIndex();
String name = ((ConstantNameAndType)pool.getConstant(iname)).getName(pool);
if (name.equals("forName")) {
System.out.println("found Class.forName('" + javaClass.getClassName() + "')");
ConstantNameAndType cnat = (ConstantNameAndType)pool.getConstant(iname);
String cfnStr = cnat.getName(pool);
if (lastConst != null) {
refClasses.add(lastConst.replace('.', '/'));
lastConst = null;
}
}
}
}
示例2: checkCode
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
public boolean checkCode(InstructionHandle[] match)
{
InstructionHandle ih = match[0];
CPInstruction ldc_w = (CPInstruction) ih.getInstruction();
Constant cc = cpool.getConstant(ldc_w.getIndex());
if (cc.getTag() != CONSTANT_Class)
return false;
ih = match[1];
CPInstruction invokevirtual = (CPInstruction) ih.getInstruction();
ConstantMethodref cm = (ConstantMethodref) cpool.getConstant(invokevirtual.getIndex());
ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cm.getNameAndTypeIndex());
if (!cnt.getName(cpool.getConstantPool()).equals("desiredAssertionStatus"))
return false;
return true;
}
示例3: visitClassContext
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass jclass = classContext.getJavaClass();
// We can ignore classes that were compiled for anything
// less than JDK 1.5. This should avoid lots of unnecessary work
// when analyzing code for older VM targets.
if (BCELUtil.preTiger(jclass))
return;
boolean sawUtilConcurrentLocks = false;
for (Constant c : jclass.getConstantPool().getConstantPool())
if (c instanceof ConstantMethodref) {
ConstantMethodref m = (ConstantMethodref) c;
ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex());
ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex());
String nameAsString = name.getBytes();
if (nameAsString.startsWith("java/util/concurrent/locks"))
sawUtilConcurrentLocks = true;
}
if (sawUtilConcurrentLocks)
super.visitClassContext(classContext);
}
示例4: addMethodref
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
/**
* Add a new Methodref constant to the ConstantPool, if it is not already
* in there.
*
* @param class_name class name string to add
* @param method_name method name string to add
* @param signature method signature string to add
* @return index of entry
*/
public int addMethodref( String class_name, String method_name, String signature ) {
int ret, class_index, name_and_type_index;
if ((ret = lookupMethodref(class_name, method_name, signature)) != -1) {
return ret; // Already in CP
}
adjustSize();
name_and_type_index = addNameAndType(method_name, signature);
class_index = addClass(class_name);
ret = index;
constants[index++] = new ConstantMethodref(class_index, name_and_type_index);
String key = class_name + METHODREF_DELIM + method_name + METHODREF_DELIM + signature;
if (!cp_table.containsKey(key)) {
cp_table.put(key, new Index(ret));
}
return ret;
}
示例5: visitConstantMethodref
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
@Override
public void visitConstantMethodref(ConstantMethodref obj) {
String name = obj.getClass(this.cp);
String variableType = ParseTool.getType2(name);
if (variableType != null && !jClass.getDetail().getSupers().contains(variableType)) {
jClass.getDetail().addVariableType(variableType);
if (this.parser.isDebug()) {
this.parser.debug("visitConstantMethodref: variable type = " + variableType);
}
}
}
示例6: visitConstantMethodref
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
public void visitConstantMethodref(ConstantMethodref obj){
if (obj.getTag() != Constants.CONSTANT_Methodref){
throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
}
checkIndex(obj, obj.getClassIndex(), CONST_Class);
checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
}
示例7: visit
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
public void visit(ConstantMethodref obj) {
visit((ConstantCP) obj);
}
示例8: visitConstantMethodref
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
public void visitConstantMethodref(ConstantMethodref obj) {
visit(obj);
}
示例9: init
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的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
}
}
}
示例10: init
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的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
}
}
}
示例11: visitConstantMethodref
import org.apache.bcel.classfile.ConstantMethodref; //导入依赖的package包/类
public void visitConstantMethodref(ConstantMethodref obj) {
tostring = toString(obj);
}