• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MethodVisitor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.asm.MethodVisitor的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor类的具体用法?Java MethodVisitor怎么用?Java MethodVisitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MethodVisitor类属于org.springframework.asm包,在下文中一共展示了MethodVisitor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateCodeForArgument

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Ask an argument to generate its bytecode and then follow it up
 * with any boxing/unboxing/checkcasting to ensure it matches the expected parameter descriptor.
 */
protected static void generateCodeForArgument(MethodVisitor mv, CodeFlow cf, SpelNodeImpl argument, String paramDesc) {
	cf.enterCompilationScope();
	argument.generateCode(mv, cf);
	boolean primitiveOnStack = CodeFlow.isPrimitive(cf.lastDescriptor());
	// Check if need to box it for the method reference?
	if (primitiveOnStack && paramDesc.charAt(0) == 'L') {
		CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	}
	else if (paramDesc.length() == 1 && !primitiveOnStack) {
		CodeFlow.insertUnboxInsns(mv, paramDesc.charAt(0), cf.lastDescriptor());
	}
	else if (!cf.lastDescriptor().equals(paramDesc)) {
		// This would be unnecessary in the case of subtyping (e.g. method takes Number but Integer passed in)
		CodeFlow.insertCheckCast(mv, paramDesc);
	}
	cf.exitCompilationScope();
}
 
开发者ID:txazo,项目名称:spring,代码行数:22,代码来源:SpelNodeImpl.java


示例2: insertArrayStore

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Produce appropriate bytecode to store a stack item in an array. The
 * instruction to use varies depending on whether the type
 * is a primitive or reference type.
 * @param mv where to insert the bytecode
 * @param arrayElementType the type of the array elements
 */
public static void insertArrayStore(MethodVisitor mv, String arrayElementType) {
	if (arrayElementType.length()==1) {
		switch (arrayElementType.charAt(0)) {
			case 'I': mv.visitInsn(IASTORE); break;
			case 'J': mv.visitInsn(LASTORE); break;
			case 'F': mv.visitInsn(FASTORE); break;
			case 'D': mv.visitInsn(DASTORE); break;
			case 'B': mv.visitInsn(BASTORE); break;
			case 'C': mv.visitInsn(CASTORE); break;
			case 'S': mv.visitInsn(SASTORE); break;
			case 'Z': mv.visitInsn(BASTORE); break;
			default:
				throw new IllegalArgumentException("Unexpected arraytype "+arrayElementType.charAt(0));
		}
	}
	else {
		mv.visitInsn(AASTORE);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:CodeFlow.java


示例3: insertNewArrayCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Produce the correct bytecode to build an array. The opcode to use and the
 * signature to pass along with the opcode can vary depending on the signature
 * of the array type.
 * @param mv the methodvisitor into which code should be inserted
 * @param size the size of the array
 * @param arraytype the type of the array
 */
public static void insertNewArrayCode(MethodVisitor mv, int size, String arraytype) {
	insertOptimalLoad(mv, size);
	if (arraytype.length() == 1) {
		mv.visitIntInsn(NEWARRAY, CodeFlow.arrayCodeFor(arraytype));
	}
	else {
		if (arraytype.charAt(0) == '[') {
			// Handling the nested array case here. If vararg
			// is [[I then we want [I and not [I;
			if (CodeFlow.isReferenceTypeArray(arraytype)) {
				mv.visitTypeInsn(ANEWARRAY, arraytype+";");
			}
			else {
				mv.visitTypeInsn(ANEWARRAY, arraytype);
			}
		}
		else {
			mv.visitTypeInsn(ANEWARRAY, arraytype.substring(1));
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:CodeFlow.java


示例4: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// exit type descriptor can be null if both components are literal expressions
	computeExitTypeDescriptor();
	this.children[0].generateCode(mv, cf);
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitInsn(DUP);
	mv.visitJumpInsn(IFNULL, elseTarget);
	mv.visitJumpInsn(GOTO, endOfIf);
	mv.visitLabel(elseTarget);
	mv.visitInsn(POP);
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	}
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:txazo,项目名称:spring,代码行数:20,代码来源:Elvis.java


示例5: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFNE, elseTarget);
	mv.visitLdcInsn(0); // FALSE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:OpAnd.java


示例6: walk

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Walk through a possible tree of nodes that combine strings and append
 * them all to the same (on stack) StringBuilder.
 */
private void walk(MethodVisitor mv, CodeFlow cf, SpelNodeImpl operand) {
	if (operand instanceof OpPlus) {
		OpPlus plus = (OpPlus)operand;
		walk(mv,cf,plus.getLeftOperand());
		walk(mv,cf,plus.getRightOperand());
	}
	else {
		cf.enterCompilationScope();
		operand.generateCode(mv,cf);
		if (!"Ljava/lang/String".equals(cf.lastDescriptor())) {
			mv.visitTypeInsn(CHECKCAST, "java/lang/String");
		}
		cf.exitCompilationScope();
		mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:OpPlus.java


示例7: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFEQ, elseTarget);
	mv.visitLdcInsn(1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:OpOr.java


示例8: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(String propertyName, MethodVisitor mv,CodeFlow cf) {
	if (method == null) {
		try {
			method = Payload2.class.getDeclaredMethod("getField", String.class);
		}
		catch (Exception e) {
		}
	}
	String descriptor = cf.lastDescriptor();
	String memberDeclaringClassSlashedDescriptor = method.getDeclaringClass().getName().replace('.','/');
	if (descriptor == null) {
		cf.loadTarget(mv);
	}
	if (descriptor == null || !memberDeclaringClassSlashedDescriptor.equals(descriptor.substring(1))) {
		mv.visitTypeInsn(CHECKCAST, memberDeclaringClassSlashedDescriptor);
	}
	mv.visitLdcInsn(propertyName);
	mv.visitMethodInsn(INVOKEVIRTUAL, memberDeclaringClassSlashedDescriptor, method.getName(),CodeFlow.createSignatureDescriptor(method),false);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:SpelCompilationCoverageTests.java


示例9: finish

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Called after the main expression evaluation method has been generated, this
 * method will callback any registered FieldAdders or ClinitAdders to add any
 * extra information to the class representing the compiled expression.
 */
public void finish() {
	if (fieldAdders != null) {
		for (FieldAdder fieldAdder: fieldAdders) {
			fieldAdder.generateField(cw,this);
		}
	}
	if (clinitAdders != null) {
		MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
		mv.visitCode();
		nextFreeVariableId = 0; // To 0 because there is no 'this' in a clinit
		for (ClinitAdder clinitAdder: clinitAdders) {
			clinitAdder.generateCode(mv, this);
		}
		mv.visitInsn(RETURN);
		mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS
		mv.visitEnd();
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:24,代码来源:CodeFlow.java


示例10: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) {
	String descriptor = cf.lastDescriptor();
	if (descriptor == null || !descriptor.equals("Ljava/util/Map")) {
		if (descriptor == null) {
			cf.loadTarget(mv);
		}
		CodeFlow.insertCheckCast(mv, "Ljava/util/Map");
	}
	mv.visitLdcInsn(propertyName);
	mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get","(Ljava/lang/Object;)Ljava/lang/Object;",true);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:MapAccessor.java


示例11: visitMethod

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
	// exclude synthetic + bridged && static class initialization
	if (!isSyntheticOrBridged(access) && !STATIC_CLASS_INIT.equals(name)) {
		return new LocalVariableTableVisitor(clazz, memberMap, name, desc, isStatic(access));
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:LocalVariableTableParameterNameDiscoverer.java


示例12: visitMethod

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
	// Skip bridge methods - we're only interested in original annotation-defining user methods.
	// On JDK 8, we'd otherwise run into double detection of the same annotated method...
	if ((access & Opcodes.ACC_BRIDGE) != 0) {
		return super.visitMethod(access, name, desc, signature, exceptions);
	}
	return new MethodMetadataReadingVisitor(name, access, getClassName(),
			Type.getReturnType(desc).getClassName(), this.classLoader, this.methodMetadataSet);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AnnotationMetadataReadingVisitor.java


示例13: insertUnboxNumberInsns

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * For numbers, use the appropriate method on the number to convert it to the primitive type requested.
 * @param mv the method visitor into which instructions should be inserted
 * @param targetDescriptor the primitive type desired as output
 * @param stackDescriptor the descriptor of the type on top of the stack
 */
public static void insertUnboxNumberInsns(MethodVisitor mv, char targetDescriptor, String stackDescriptor) {
	switch (targetDescriptor) {
		case 'D':
			if (stackDescriptor.equals("Ljava/lang/Object")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "doubleValue", "()D", false);
			break;
		case 'F':
			if (stackDescriptor.equals("Ljava/lang/Object")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "floatValue", "()F", false);
			break;
		case 'J':
			if (stackDescriptor.equals("Ljava/lang/Object")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "longValue", "()J", false);
			break;
		case 'I':
			if (stackDescriptor.equals("Ljava/lang/Object")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "intValue", "()I", false);
			break;
		// does not handle Z, B, C, S
		default:
			throw new IllegalArgumentException("Unboxing should not be attempted for descriptor '" + targetDescriptor + "'");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:CodeFlow.java


示例14: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	getLeftOperand().generateCode(mv, cf);
	CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor());
	if (this.type.isPrimitive()) {
		// always false - but left operand code always driven
		// in case it had side effects
		mv.visitInsn(POP);
		mv.visitInsn(ICONST_0); // value of false
	} 
	else {
		mv.visitTypeInsn(INSTANCEOF,Type.getInternalName(this.type));
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:txazo,项目名称:spring,代码行数:16,代码来源:OperatorInstanceof.java


示例15: insertBoxIfNecessary

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Determine the appropriate boxing instruction for a specific type (if it needs
 * boxing) and insert the instruction into the supplied visitor.
 * @param mv the target visitor for the new instructions
 * @param ch the descriptor of the type that might need boxing
 */
public static void insertBoxIfNecessary(MethodVisitor mv, char ch) {
	switch (ch) {
		case 'Z':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
			break;
		case 'B':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
			break;
		case 'C':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false);
			break;
		case 'D':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
			break;
		case 'F':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
			break;
		case 'I':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
			break;
		case 'J':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
			break;
		case 'S':
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
			break;
		case 'L':
		case 'V':
		case '[':
			// no box needed
			break;
		default:
			throw new IllegalArgumentException("Boxing should not be attempted for descriptor '" + ch + "'");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:CodeFlow.java


示例16: insertOptimalLoad

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * Create the optimal instruction for loading a number on the stack.
 * @param mv where to insert the bytecode
 * @param value the value to be loaded
 */
public static void insertOptimalLoad(MethodVisitor mv, int value) {
	if (value < 6) {
		mv.visitInsn(ICONST_0+value);
	}
	else if (value < Byte.MAX_VALUE) {
		mv.visitIntInsn(BIPUSH, value);
	}
	else if (value < Short.MAX_VALUE) {
		mv.visitIntInsn(SIPUSH, value);
	}
	else {
		mv.visitLdcInsn(value);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CodeFlow.java


示例17: insertNumericUnboxOrPrimitiveTypeCoercion

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
/**
 * For use in mathematical operators, handles converting from a (possibly boxed)
 * number on the stack to a primitive numeric type.
 * <p>For example, from a Integer to a double, just need to call 'Number.doubleValue()'
 * but from an int to a double, need to use the bytecode 'i2d'.
 * @param mv the method visitor when instructions should be appended
 * @param stackDescriptor a descriptor of the operand on the stack
 * @param targetDescriptor a primitive type descriptor
 */
public static void insertNumericUnboxOrPrimitiveTypeCoercion(
		MethodVisitor mv, String stackDescriptor, char targetDescriptor) {

	if (!CodeFlow.isPrimitive(stackDescriptor)) {
		CodeFlow.insertUnboxNumberInsns(mv, targetDescriptor, stackDescriptor);
	}
	else {
		CodeFlow.insertAnyNecessaryTypeConversionBytecodes(mv, targetDescriptor, stackDescriptor);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CodeFlow.java


示例18: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	int intValue = (Integer) this.value.getValue();
	if (intValue == -1) {
		// Not sure we can get here because -1 is OpMinus
		mv.visitInsn(ICONST_M1);
	}
	else if (intValue >= 0 && intValue < 6) {
		mv.visitInsn(ICONST_0 + intValue);
	}
	else {
		mv.visitLdcInsn(intValue);
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:IntLiteral.java


示例19: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	ReflectiveConstructorExecutor executor = ((ReflectiveConstructorExecutor) this.cachedExecutor);
	Constructor<?> constructor = executor.getConstructor();		
	String classDesc = constructor.getDeclaringClass().getName().replace('.', '/');
	mv.visitTypeInsn(NEW, classDesc);
	mv.visitInsn(DUP);
	// children[0] is the type of the constructor, don't want to include that in argument processing
	SpelNodeImpl[] arguments = new SpelNodeImpl[children.length - 1];
	System.arraycopy(children, 1, arguments, 0, children.length - 1);
	generateCodeForArguments(mv, cf, constructor, arguments);	
	mv.visitMethodInsn(INVOKESPECIAL, classDesc, "<init>", CodeFlow.createSignatureDescriptor(constructor), false);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:ConstructorReference.java


示例20: generateCode

import org.springframework.asm.MethodVisitor; //导入依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// May reach here without it computed if all elements are literals
	computeExitTypeDescriptor();
	cf.enterCompilationScope();
	this.children[0].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(cf.lastDescriptor())) {
		CodeFlow.insertUnboxInsns(mv, 'Z', cf.lastDescriptor());
	}
	cf.exitCompilationScope();
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitJumpInsn(IFEQ, elseTarget);
	cf.enterCompilationScope();
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitJumpInsn(GOTO, endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	this.children[2].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:Ternary.java



注:本文中的org.springframework.asm.MethodVisitor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Triple类代码示例发布时间:2022-05-23
下一篇:
Java CompareGenerator类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap