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


Java MethodVisitor.visitCode方法代码示例

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


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

示例1: 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:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:CodeFlow.java

示例2: createExpressionClass

import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * Generate the class that encapsulates the compiled expression and define it.
 * The  generated class will be a subtype of CompiledExpression.
 * @param expressionToCompile the expression to be compiled
 * @return the expression call, or {@code null} if the decision was to opt out of
 * compilation during code generation
 */
@SuppressWarnings("unchecked")
private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl expressionToCompile) {
	// Create class outline 'spel/ExNNN extends org.springframework.expression.spel.CompiledExpression'
	String clazzName = "spel/Ex" + getNextSuffix();
	ClassWriter cw = new ExpressionClassWriter();
	cw.visit(V1_5, ACC_PUBLIC, clazzName, null, "org/springframework/expression/spel/CompiledExpression", null);

	// Create default constructor
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
	mv.visitCode();
	mv.visitVarInsn(ALOAD, 0);
	mv.visitMethodInsn(INVOKESPECIAL, "org/springframework/expression/spel/CompiledExpression",
			"<init>", "()V", false);
	mv.visitInsn(RETURN);
	mv.visitMaxs(1, 1);
	mv.visitEnd();

	// Create getValue() method
	mv = cw.visitMethod(ACC_PUBLIC, "getValue",
			"(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;", null,
			new String[ ]{"org/springframework/expression/EvaluationException"});
	mv.visitCode();

	CodeFlow cf = new CodeFlow(clazzName, cw);

	// Ask the expression AST to generate the body of the method
	try {
		expressionToCompile.generateCode(mv, cf);
	}
	catch (IllegalStateException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug(expressionToCompile.getClass().getSimpleName() +
					".generateCode opted out of compilation: " + ex.getMessage());
		}
		return null;
	}

	CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor());
	if ("V".equals(cf.lastDescriptor())) {
		mv.visitInsn(ACONST_NULL);
	}
	mv.visitInsn(ARETURN);

	mv.visitMaxs(0, 0);  // not supplied due to COMPUTE_MAXS
	mv.visitEnd();
	cw.visitEnd();

	cf.finish();

	byte[] data = cw.toByteArray();
	// TODO need to make this conditionally occur based on a debug flag
	// dump(expressionToCompile.toStringAST(), clazzName, data);
	return (Class<? extends CompiledExpression>) this.ccl.defineClass(clazzName.replaceAll("/", "."), data);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:62,代码来源:SpelCompiler.java


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