当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor.visitTypeInsn方法代码示例

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


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

示例1: insertCheckCast

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Insert the appropriate CHECKCAST instruction for the supplied descriptor.
 * @param mv the target visitor into which the instruction should be inserted
 * @param descriptor the descriptor of the type to cast to
 */
public static void insertCheckCast(MethodVisitor mv, String descriptor) {
	if (descriptor.length() != 1) {
		if (descriptor.charAt(0) == '[') {
			if (isPrimitiveArray(descriptor)) {
				mv.visitTypeInsn(CHECKCAST, descriptor);
			}
			else {
				mv.visitTypeInsn(CHECKCAST, descriptor + ";");
			}
		}
		else {
			if (!descriptor.equals("Ljava/lang/Object")) {
				// This is chopping off the 'L' to leave us with "java/lang/String"
				mv.visitTypeInsn(CHECKCAST, descriptor.substring(1));
			}
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:CodeFlow.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: generateCode

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) {
	boolean isStatic = Modifier.isStatic(this.member.getModifiers());
	String descriptor = cf.lastDescriptor();
	String classDesc = this.member.getDeclaringClass().getName().replace('.', '/');

	if (!isStatic) {
		if (descriptor == null) {
			cf.loadTarget(mv);
		}
		if (descriptor == null || !classDesc.equals(descriptor.substring(1))) {
			mv.visitTypeInsn(CHECKCAST, classDesc);
		}
	}
	else {
		if (descriptor != null) {
			// A static field/method call will not consume what is on the stack,
			// it needs to be popped off.
			mv.visitInsn(POP);
		}
	}

	if (this.member instanceof Method) {
		mv.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, this.member.getName(),
				CodeFlow.createSignatureDescriptor((Method) this.member), false);
	}
	else {
		mv.visitFieldInsn((isStatic ? GETSTATIC : GETFIELD), classDesc, this.member.getName(),
				CodeFlow.toJvmDescriptor(((Field) this.member).getType()));
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:32,代码来源:ReflectivePropertyAccessor.java

示例8: generateClinitCode

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
void generateClinitCode(String clazzname, String constantFieldName, MethodVisitor mv, CodeFlow codeflow, boolean nested) {
	mv.visitTypeInsn(NEW, "java/util/ArrayList");
	mv.visitInsn(DUP);
	mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
	if (!nested) {
		mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;");
	}
	int childcount = getChildCount();		
	for (int c=0; c < childcount; c++) {
		if (!nested) {
			mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;");
		}
		else {
			mv.visitInsn(DUP);
		}
		// The children might be further lists if they are not constants. In this
		// situation do not call back into generateCode() because it will register another clinit adder.
		// Instead, directly build the list here:
		if (children[c] instanceof InlineList) {
			((InlineList)children[c]).generateClinitCode(clazzname, constantFieldName, mv, codeflow, true);
		}
		else {
			children[c].generateCode(mv, codeflow);
			if (CodeFlow.isPrimitive(codeflow.lastDescriptor())) {
				CodeFlow.insertBoxIfNecessary(mv, codeflow.lastDescriptor().charAt(0));
			}
		}
		mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
		mv.visitInsn(POP);
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:32,代码来源:InlineList.java

示例9: 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

示例10: insertUnboxInsns

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Insert any necessary cast and value call to convert from a boxed type to a
 * primitive value
 * @param mv the method visitor into which instructions should be inserted
 * @param ch the primitive type desired as output
 * @param stackDescriptor the descriptor of the type on top of the stack
 */
public static void insertUnboxInsns(MethodVisitor mv, char ch, String stackDescriptor) {
	switch (ch) {
		case 'Z':
			if (!stackDescriptor.equals("Ljava/lang/Boolean")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
			break;
		case 'B':
			if (!stackDescriptor.equals("Ljava/lang/Byte")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Byte");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
			break;
		case 'C':
			if (!stackDescriptor.equals("Ljava/lang/Character")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Character");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Character", "charValue", "()C", false);
			break;
		case 'D':
			if (!stackDescriptor.equals("Ljava/lang/Double")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
			break;
		case 'F':
			if (!stackDescriptor.equals("Ljava/lang/Float")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
			break;
		case 'I':
			if (!stackDescriptor.equals("Ljava/lang/Integer")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
			break;
		case 'J':
			if (!stackDescriptor.equals("Ljava/lang/Long")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
			break;
		case 'S':
			if (!stackDescriptor.equals("Ljava/lang/Short")) {
				mv.visitTypeInsn(CHECKCAST, "java/lang/Short");
			}
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false);
			break;
		default:
			throw new IllegalArgumentException("Unboxing should not be attempted for descriptor '" + ch + "'");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:62,代码来源:CodeFlow.java

示例11: generateCode

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	if (this.exitTypeDescriptor == "Ljava/lang/String") {
		mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
		mv.visitInsn(DUP);
		mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
		walk(mv,cf,getLeftOperand());
		walk(mv,cf,getRightOperand());
		mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
	}
	else {
		getLeftOperand().generateCode(mv, cf);
		String leftDesc = getLeftOperand().exitTypeDescriptor;
		CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
		if (this.children.length > 1) {
			cf.enterCompilationScope();
			getRightOperand().generateCode(mv, cf);
			String rightDesc = getRightOperand().exitTypeDescriptor;
			cf.exitCompilationScope();
			CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
			switch (this.exitTypeDescriptor.charAt(0)) {
				case 'I':
					mv.visitInsn(IADD);
					break;
				case 'J':
					mv.visitInsn(LADD);
					break;
				case 'F': 
					mv.visitInsn(FADD);
					break;
				case 'D':
					mv.visitInsn(DADD);
					break;				
				default:
					throw new IllegalStateException(
							"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
			}
		}
	}
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:OpPlus.java

示例12: generateCode

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	getLeftOperand().generateCode(mv, cf);
	mv.visitTypeInsn(INSTANCEOF,Type.getInternalName(this.type));
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:7,代码来源:OperatorInstanceof.java


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