本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitTryCatchBlock方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitTryCatchBlock方法的具体用法?Java MethodVisitor.visitTryCatchBlock怎么用?Java MethodVisitor.visitTryCatchBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitTryCatchBlock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeNonAbstractMethodWrapper
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeNonAbstractMethodWrapper(ClassVisitor visitor, Type generatedType, Class<?> managedTypeClass, Method method) {
Label start = new Label();
Label end = new Label();
Label handler = new Label();
MethodVisitor methodVisitor = declareMethod(visitor, method);
methodVisitor.visitTryCatchBlock(start, end, handler, null);
setCanCallSettersField(methodVisitor, generatedType, false);
methodVisitor.visitLabel(start);
invokeSuperMethod(methodVisitor, managedTypeClass, method);
methodVisitor.visitLabel(end);
setCanCallSettersField(methodVisitor, generatedType, true);
methodVisitor.visitInsn(ARETURN);
methodVisitor.visitLabel(handler);
setCanCallSettersField(methodVisitor, generatedType, true);
methodVisitor.visitInsn(ATHROW);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
示例2: visitBlockStructured
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void visitBlockStructured(ClassWriter cw, boolean normalReturnError, boolean tooMany) {
String name = (tooMany ? "tooMany" : "tooFew") + "Exits" + (normalReturnError ? "" : "Exceptional");
// Generate too many or too few exits down the either the normal or exceptional return
// paths
int exceptionalExitCount = normalReturnError ? 1 : (tooMany ? 2 : 0);
int normalExitCount = normalReturnError ? (tooMany ? 2 : 0) : 1;
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, name, "(Ljava/lang/Object;Ljava/lang/Object;)Z", null, null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, null);
Label l3 = new Label();
mv.visitTryCatchBlock(l2, l3, l2, null);
Label l4 = new Label();
Label l5 = new Label();
Label l6 = new Label();
mv.visitTryCatchBlock(l4, l5, l6, null);
Label l7 = new Label();
mv.visitTryCatchBlock(l2, l7, l6, null);
Label l8 = new Label();
mv.visitLabel(l8);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(DUP);
mv.visitVarInsn(ASTORE, 3);
mv.visitInsn(MONITORENTER);
mv.visitLabel(l4);
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(DUP);
mv.visitVarInsn(ASTORE, 4);
mv.visitInsn(MONITORENTER);
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 2);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
mv.visitVarInsn(ALOAD, 4);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l1);
for (int i = 0; i < normalExitCount; i++) {
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(MONITOREXIT);
}
mv.visitLabel(l5);
mv.visitInsn(IRETURN);
mv.visitLabel(l2);
mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
"java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
mv.visitVarInsn(ALOAD, 4);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l3);
mv.visitInsn(ATHROW);
mv.visitLabel(l6);
mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
new Object[]{"java/lang/Throwable"});
for (int i = 0; i < exceptionalExitCount; i++) {
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(MONITOREXIT);
}
mv.visitLabel(l7);
mv.visitInsn(ATHROW);
Label l9 = new Label();
mv.visitLabel(l9);
mv.visitMaxs(2, 5);
mv.visitEnd();
}
示例3: visit
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Object visit(ASTCatch node, Object data) throws CompileException {
dump_context_stack();
TContext context = popContext();
Debug.assertion(context != null, "Context should not be null");
LangUnitNode stream_node = (LangUnitNode) node.jjtGetParent();
Debug.assertion(stream_node != null, "stream_node should be valid");
Debug.assertion(stream_node.isNodeId(JJTSTREAM), "stream_node should be stream node");
int streamblock_idx = stream_node.getChildIdxWithId(JJTSTREAMBLOCK, 0);
LangUnitNode streamblock_node = (LangUnitNode) stream_node.getChildren(streamblock_idx);
Debug.assertion(streamblock_node != null, "streamblock_node should be valid");
Debug.assertion(streamblock_node.isNodeId(JJTSTREAMBLOCK), "streamblock_node should be streamblock node");
Label stream_end_label = stream_node.getStreamEndLabel();
Debug.assertion(stream_end_label != null, "stream_end_label should be valid");
Label streamblock_start_label = streamblock_node.getStreamBlockStartLabel();
Debug.assertion(streamblock_start_label != null, "streamblock_start_label should be valid");
Label streamblock_end_label = streamblock_node.getStreamBlockEndLabel();
Debug.assertion(streamblock_end_label != null, "streamblock_end_label should be valid");
Label catch_label = node.getCatchLabel();
Debug.assertion(catch_label != null, "catch_label should be valid");
TContextFunc func_ctx = (TContextFunc) getTopContext().getClosestAncestor(AbsType.FORM_FUNC);
Debug.assertion(func_ctx != null, "catch should be used in function context");
MethodVisitor mv = func_ctx.getMethodVisitor();
/*
* public void visitCode() { super.visitCode(); visitTryCatchBlock(start,
* end, handler, "java/lang/Exception"); visitLabel(start); }
* mv.visitTryCatchBlock(arg0, arg1, arg2, arg3);
*/
AbsTypeList excptype_list = node.getCatchExceptionList();
Debug.assertion(excptype_list != null, "excptype_list should be valid");
AbsType excptype = null;
int size = excptype_list.size();
for (int i = 0; i < size; i++) {
excptype = excptype_list.get(i);
LOG.debug("trycatch block for exception " + excptype);
mv.visitTryCatchBlock(streamblock_start_label, streamblock_end_label, catch_label, excptype.getName());
}
LOG.info("GOTO stream_end_label({})", stream_end_label);
mv.visitJumpInsn(GOTO, stream_end_label);
return null;
}
示例4: writeTypeConvertingSetter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeTypeConvertingSetter(ClassVisitor visitor, Type generatedType, Class<?> viewClass, ModelProperty<?> property) {
WeaklyTypeReferencingMethod<?, ?> weakSetter = property.getAccessor(SETTER);
// There is no setter for this property
if (weakSetter == null) {
return;
}
if (!(property.getSchema() instanceof ScalarValueSchema)) {
return;
}
Class<?> propertyClass = property.getType().getConcreteClass();
Type propertyType = Type.getType(propertyClass);
Class<?> boxedClass = propertyClass.isPrimitive() ? BOXED_TYPES.get(propertyClass) : propertyClass;
Type boxedType = Type.getType(boxedClass);
Method setter = weakSetter.getMethod();
MethodVisitor methodVisitor = declareMethod(visitor, setter.getName(), SET_OBJECT_PROPERTY_DESCRIPTOR, SET_OBJECT_PROPERTY_DESCRIPTOR);
putThisOnStack(methodVisitor);
putTypeConverterFieldValueOnStack(methodVisitor, generatedType);
// Object converted = $typeConverter.convert(foo, Float.class, false);
methodVisitor.visitVarInsn(ALOAD, 1); // put var #1 ('foo') on the stack
methodVisitor.visitLdcInsn(boxedType); // push the constant Class onto the stack
methodVisitor.visitInsn(propertyClass.isPrimitive() ? ICONST_1 : ICONST_0); // push int 1 or 0 (interpreted as true or false) onto the stack
Label startTry = new Label();
methodVisitor.visitLabel(startTry);
methodVisitor.visitMethodInsn(INVOKEINTERFACE, TYPE_CONVERTER_TYPE.getInternalName(), "convert", COERCE_TO_SCALAR_DESCRIPTOR, true);
Label endTry = new Label();
methodVisitor.visitLabel(endTry);
methodVisitor.visitTypeInsn(CHECKCAST, boxedType.getInternalName());
if (propertyClass.isPrimitive()) {
unboxType(methodVisitor, propertyClass);
}
// invoke the typed setter
methodVisitor.visitMethodInsn(INVOKEVIRTUAL, generatedType.getInternalName(), setter.getName(), Type.getMethodDescriptor(Type.VOID_TYPE, propertyType), false);
methodVisitor.visitInsn(RETURN);
// catch(TypeConversionException e) { throw ... }
Label startCatch = new Label();
methodVisitor.visitLabel(startCatch);
methodVisitor.visitTryCatchBlock(startTry, endTry, startCatch, TYPE_CONVERSION_EXCEPTION_TYPE.getInternalName());
methodVisitor.visitVarInsn(ASTORE, 2); // store thrown exception
putClassOnStack(methodVisitor, viewClass);
methodVisitor.visitLdcInsn(property.getName());
putFirstMethodArgumentOnStack(methodVisitor);
methodVisitor.visitVarInsn(ALOAD, 2);
methodVisitor.visitMethodInsn(INVOKESTATIC, Type.getInternalName(ManagedProxyClassGenerator.class), "propertyValueConvertFailure",
Type.getMethodDescriptor(Type.VOID_TYPE, CLASS_TYPE, STRING_TYPE, OBJECT_TYPE, TYPE_CONVERSION_EXCEPTION_TYPE), false);
finishVisitingMethod(methodVisitor);
}
示例5: visitWrongOrder
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void visitWrongOrder(ClassWriter cw) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "wrongOrder", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", null, null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, null);
Label l3 = new Label();
mv.visitTryCatchBlock(l2, l3, l2, null);
Label l4 = new Label();
Label l5 = new Label();
Label l6 = new Label();
mv.visitTryCatchBlock(l4, l5, l6, null);
Label l7 = new Label();
mv.visitTryCatchBlock(l2, l7, l6, null);
Label l8 = new Label();
mv.visitLabel(l8);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(DUP);
mv.visitVarInsn(ASTORE, 3);
mv.visitInsn(MONITORENTER);
mv.visitLabel(l4);
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(DUP);
mv.visitVarInsn(ASTORE, 4);
mv.visitInsn(MONITORENTER);
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 2);
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l1);
// Swapped exit order with exit above
mv.visitVarInsn(ALOAD, 4);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l5);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
"java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
mv.visitVarInsn(ALOAD, 4);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l3);
mv.visitInsn(ATHROW);
mv.visitLabel(l6);
mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
new Object[]{"java/lang/Throwable"});
mv.visitVarInsn(ALOAD, 3);
mv.visitInsn(MONITOREXIT);
mv.visitLabel(l7);
mv.visitInsn(ATHROW);
Label l9 = new Label();
mv.visitLabel(l9);
mv.visitMaxs(2, 5);
mv.visitEnd();
}