本文整理匯總了Java中org.objectweb.asm.MethodVisitor類的典型用法代碼示例。如果您正苦於以下問題:Java MethodVisitor類的具體用法?Java MethodVisitor怎麽用?Java MethodVisitor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MethodVisitor類屬於org.objectweb.asm包,在下文中一共展示了MethodVisitor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visit
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
@Override
public Object visit(ASTStreamBlockElementHdr node, Object data) throws CompileException {
// function or stream is in here
TContext func_context = getTopContext().getClosestAncestor(AbsType.FORM_FUNC);
if (func_context != null) {
MethodVisitor mv = ((TContextFunc) func_context).getMethodVisitor();
Debug.assertion(mv != null, "mv should be valid");
/*
* Label linelabel = new Label();
*
* // line label for debugging mv.visitLabel(linelabel);
* mv.visitLineNumber(node.jjtGetFirstToken().beginLine, linelabel);
*/
addLineLable(mv, node.jjtGetFirstToken().beginLine);
}
return null;
}
示例2: hookMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* (none-javadoc)
*
* @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
*/
@Override
public MethodVisitor hookMethod(int access, String name, String desc,
String signature, String[] exceptions, MethodVisitor mv) {
if (name.equals("compile") && desc.startsWith("()V")) {
return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
@Override
protected void onMethodEnter() {
invokeStatic(Type.getType(HookHandler.class),
new Method("preShieldHook", "()V"));
}
@Override
protected void onMethodExit(int i) {
invokeStatic(Type.getType(HookHandler.class),
new Method("postShieldHook", "()V"));
}
};
}
return mv;
}
示例3: generateMethodTest10
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
* MethodHandle of kind get static. The method handle read a static field from a class.
*/
private void generateMethodTest10(ClassVisitor cv) {
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test10", "()V",
null, null);
MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
MethodType.class, MethodHandle.class);
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
"bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
mv.visitFieldInsn(Opcodes.GETSTATIC,
"java/lang/System",
"out",
"Ljava/io/PrintStream;");
mv.visitInvokeDynamicInsn("staticField1", "()Ljava/lang/String;", bootstrap,
new Handle(Opcodes.H_GETSTATIC, Type.getInternalName(InvokeCustom.class),
"staticField1", "Ljava/lang/String;", false));
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(-1, -1);
}
示例4: generateUnsupportedOperationExceptionMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* Generates an exception which is going to be thrown in each method.
* The reason it is in a separate method is because it reduces the bytecode size.
*/
private void generateUnsupportedOperationExceptionMethod() {
MethodVisitor mv = cv.visitMethod(
ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC, UOE_METHOD,
"()Ljava/lang/UnsupportedOperationException;", null, null);
mv.visitCode();
mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
mv.visitInsn(DUP);
mv.visitLdcInsn(
"You tried to call a method on an API class. Is the API jar on the classpath instead of the runtime jar?");
mv.visitMethodInsn(
INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false);
mv.visitInsn(ARETURN);
mv.visitMaxs(3, 0);
mv.visitEnd();
}
示例5: visitHttpMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* Instrument HTTP request methods
*
* @param mv
* original MethodVisitor
* @param access
* @param name
* @param desc
* @param signature
* @param exceptions
* @return original MethodVisitor or new MethodVisitor chained to original
*/
private MethodVisitor visitHttpMethod(MethodVisitor mv, int access, String name, String desc, String signature,
String[] exceptions) {
MethodVisitor httpMv = mv;
/*
* Instrument _jspService method for JSP. Instrument doGet, doPost and
* service methods for servlets.
*/
if ((httpInstrumentJsp && name.equals("_jspService")) || (httpInstrumentServlet
&& (name.equals("doGet") || name.equals("doPost") || name.equals("service")))) {
// Only instrument if method has the correct signature
if (HTTP_REQUEST_METHOD_DESC.equals(desc)) {
httpMv = new ServletCallBackAdapter(className, mv, access, name, desc);
}
}
return httpMv;
}
示例6: generateMethodTest6
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
* MethodHandle of kind invoke interface. The target method is a default method into an interface
* that is at the end of a chain of interfaces.
*/
private void generateMethodTest6(ClassVisitor cv) {
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test6", "()V",
null, null);
MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
MethodType.class, MethodHandle.class);
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
"bsmCreateCallCallingtargetMethodTest7", mt.toMethodDescriptorString(), false);
mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
mv.visitInsn(Opcodes.DUP);
mv.visitMethodInsn(
Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
mv.visitInvokeDynamicInsn("targetMethodTest7", "(Linvokecustom/J;)V", bootstrap,
new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
"targetMethodTest7", "()V", true));
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(-1, -1);
}
示例7: begin
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
@Override
public void begin(final String name, final Attributes attrs) {
String desc = attrs.getValue("desc");
boolean visible = Boolean.valueOf(attrs.getValue("visible"))
.booleanValue();
int typeRef = Integer.parseInt(attrs.getValue("typeRef"));
TypePath typePath = TypePath.fromString(attrs.getValue("typePath"));
Object v = peek();
if (v instanceof ClassVisitor) {
push(((ClassVisitor) v).visitTypeAnnotation(typeRef, typePath,
desc, visible));
} else if (v instanceof FieldVisitor) {
push(((FieldVisitor) v).visitTypeAnnotation(typeRef, typePath,
desc, visible));
} else if (v instanceof MethodVisitor) {
push(((MethodVisitor) v).visitTypeAnnotation(typeRef, typePath,
desc, visible));
}
}
示例8: visitMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
@Override
public MethodVisitor visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions) {
MethodVisitor mv;
if ("<clinit>".equals(name)) {
int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
String n = prefix + counter++;
mv = cv.visitMethod(a, n, desc, signature, exceptions);
if (clinit == null) {
clinit = cv.visitMethod(a, name, desc, null, null);
}
clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc,
false);
} else {
mv = cv.visitMethod(access, name, desc, signature, exceptions);
}
return mv;
}
示例9: writeSetter
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
private void writeSetter(ClassVisitor visitor, Type generatedType, String propertyName, Class<?> propertyClass, WeaklyTypeReferencingMethod<?, ?> weakSetter) {
Type propertyType = Type.getType(propertyClass);
Label calledOutsideOfConstructor = new Label();
Method setter = weakSetter.getMethod();
// the regular typed setter
String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, propertyType);
MethodVisitor methodVisitor = declareMethod(visitor, setter.getName(), methodDescriptor, AsmClassGeneratorUtils.signature(setter));
putCanCallSettersFieldValueOnStack(methodVisitor, generatedType);
jumpToLabelIfStackEvaluatesToTrue(methodVisitor, calledOutsideOfConstructor);
throwExceptionBecauseCalledOnItself(methodVisitor);
methodVisitor.visitLabel(calledOutsideOfConstructor);
putStateFieldValueOnStack(methodVisitor, generatedType);
putConstantOnStack(methodVisitor, propertyName);
putFirstMethodArgumentOnStack(methodVisitor, propertyType);
if (propertyClass.isPrimitive()) {
boxType(methodVisitor, propertyClass);
}
invokeStateSetMethod(methodVisitor);
finishVisitingMethod(methodVisitor);
}
示例10: visitMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
@Override
public MethodVisitor visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions) {
if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
cp.newUTF8("Synthetic");
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
cp.newUTF8("Deprecated");
}
cp.newUTF8(name);
cp.newUTF8(desc);
if (signature != null) {
cp.newUTF8("Signature");
cp.newUTF8(signature);
}
if (exceptions != null) {
cp.newUTF8("Exceptions");
for (int i = 0; i < exceptions.length; ++i) {
cp.newClass(exceptions[i]);
}
}
return new MethodConstantsCollector(cv.visitMethod(access, name, desc,
signature, exceptions), cp);
}
示例11: accept
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* Makes the given visitor visit this stack map frame.
*
* @param mv
* a method visitor.
*/
@Override
public void accept(final MethodVisitor mv) {
switch (type) {
case Opcodes.F_NEW:
case Opcodes.F_FULL:
mv.visitFrame(type, local.size(), asArray(local), stack.size(),
asArray(stack));
break;
case Opcodes.F_APPEND:
mv.visitFrame(type, local.size(), asArray(local), 0, null);
break;
case Opcodes.F_CHOP:
mv.visitFrame(type, local.size(), null, 0, null);
break;
case Opcodes.F_SAME:
mv.visitFrame(type, 0, null, 0, null);
break;
case Opcodes.F_SAME1:
mv.visitFrame(type, 0, null, 1, asArray(stack));
break;
}
}
示例12: hookMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
/**
* (none-javadoc)
*
* @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
*/
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
if ("lookup".equals(name) && desc.startsWith("(Ljava/lang/String;)")) {
return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
@Override
public void onMethodExit(int opcode) {
if (opcode == Opcodes.ARETURN) {
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/ProxyDirContextHook", "checkResourceCacheEntry",
"(Ljava/lang/Object;)V", false);
}
super.onMethodExit(opcode);
}
};
}
return mv;
}
示例13: callUserMethodOrDirect
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
private static void callUserMethodOrDirect(ClassLoader classLoader, InterceptedCall call, MethodVisitor mv) {
/* Check if we have a user-provided validation method */
String validationMethodOwnerName = getClassForMethod(classLoader, call.desc, call);
if (validationMethodOwnerName != null) {
/* we have, so call it... */
mv.visitMethodInsn(INVOKESTATIC, validationMethodOwnerName, call.name, call.desc, false);
} else {
/* we don't have a user-defined validation method yet, so just call the target method directly */
mv.visitMethodInsn(INVOKESTATIC, call.receiverInternalName, call.name, call.desc, false);
}
/* Check GL error if it was a GL call */
if (VALIDATE.enabled && call.glName != null && !call.glName.equals("glGetError")) {
mv.visitLdcInsn(call.name);
mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "checkError", "(Ljava/lang/String;)V", false);
}
}
示例14: insertBooleanGetter
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
@Override
public void insertBooleanGetter(MethodVisitor mv, int var, String key) throws CompilerException {
Class<?> type = insertGetter(mv, var, key, true).clazz;
if(type == boolean.class) {
// The correct type. We don't need to adapt it :D
return;
}
if(type == Boolean.class) {
// b.booleanValue()
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
} else if(type.isPrimitive()) {
throw new CompilerException("Can't parse a primitive into a boolean: " + type);
} else {
// Boolean.parseBoolean(object.toString())
mv.visitMethodInsn(INVOKEVIRTUAL, OBJECT.getInternalName(), "toString", Type.getMethodDescriptor(STRING), false);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "parseBoolean", Type.getMethodDescriptor(STRING, Type.BOOLEAN_TYPE), false);
}
}
示例15: visitMethod
import org.objectweb.asm.MethodVisitor; //導入依賴的package包/類
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
if ((access & Opcodes.ACC_PRIVATE) != 0) {
return null;
}
pendingMethod = name + desc;
line = -1;
return new LineNumberMethodVisitor();
}