Java Code Examples for org.springframework.asm.Opcodes

The following examples show how to use org.springframework.asm.Opcodes. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: ClassMetadataReadingVisitor.java    License: MIT License 6 votes vote down vote up
@Override
public void visit(
		int version, int access, String name, String signature, @Nullable String supername, String[] interfaces) {

	this.className = ClassUtils.convertResourcePathToClassName(name);
	this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
	this.isAnnotation = ((access & Opcodes.ACC_ANNOTATION) != 0);
	this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
	this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
	if (supername != null && !this.isInterface) {
		this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
	}
	this.interfaces = new String[interfaces.length];
	for (int i = 0; i < interfaces.length; i++) {
		this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
	}
}
 
Example 2
@Override
public void visit(
		int version, int access, String name, String signature, @Nullable String supername, String[] interfaces) {

	this.className = ClassUtils.convertResourcePathToClassName(name);
	this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
	this.isAnnotation = ((access & Opcodes.ACC_ANNOTATION) != 0);
	this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
	this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
	if (supername != null && !this.isInterface) {
		this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
	}
	this.interfaces = new String[interfaces.length];
	for (int i = 0; i < interfaces.length; i++) {
		this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
	}
}
 
Example 3
@Override
public void visitInnerClass(String name, @Nullable String outerName, String innerName,
		int access) {
	if (outerName != null) {
		String className = toClassName(name);
		String outerClassName = toClassName(outerName);
		if (this.className.equals(className)) {
			this.enclosingClassName = outerClassName;
			this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
		}
		else if (this.className.equals(outerClassName)) {
			this.memberClassNames.add(className);
		}
	}
}
 
Example 4
@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);
}
 
Example 5
Source Project: spring-analysis-note   Source File: ClassMetadataReadingVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public void visitInnerClass(String name, @Nullable String outerName, String innerName, int access) {
	if (outerName != null) {
		String fqName = ClassUtils.convertResourcePathToClassName(name);
		String fqOuterName = ClassUtils.convertResourcePathToClassName(outerName);
		if (this.className.equals(fqName)) {
			this.enclosingClassName = fqOuterName;
			this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
		}
		else if (this.className.equals(fqOuterName)) {
			this.memberClassNames.add(fqName);
		}
	}
}
 
Example 6
@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);
}
 
Example 7
@Override
public void visitInnerClass(String name, @Nullable String outerName, String innerName, int access) {
	if (outerName != null) {
		String fqName = ClassUtils.convertResourcePathToClassName(name);
		String fqOuterName = ClassUtils.convertResourcePathToClassName(outerName);
		if (this.className.equals(fqName)) {
			this.enclosingClassName = fqOuterName;
			this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
		}
		else if (this.className.equals(fqOuterName)) {
			this.memberClassNames.add(fqName);
		}
	}
}
 
Example 8
public void visit(int version, int access, String name, String signature, String supername, String[] interfaces) {
    this.className = ClassUtils.convertResourcePathToClassName(name);
    this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
    this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
    this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
    if (supername != null) {
        this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
    }
    this.interfaces = new String[interfaces.length];
    for (int i = 0; i < interfaces.length; i++) {
        this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
    }
}
 
Example 9
@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);
}
 
Example 10
@Override
public void visit(int version, int access, String name, String signature, String supername, String[] interfaces) {
	this.className = ClassUtils.convertResourcePathToClassName(name);
	this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
	this.isAnnotation = ((access & Opcodes.ACC_ANNOTATION) != 0);
	this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
	this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
	if (supername != null && !this.isInterface) {
		this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
	}
	this.interfaces = new String[interfaces.length];
	for (int i = 0; i < interfaces.length; i++) {
		this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
	}
}
 
Example 11
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
	if (outerName != null) {
		String fqName = ClassUtils.convertResourcePathToClassName(name);
		String fqOuterName = ClassUtils.convertResourcePathToClassName(outerName);
		if (this.className.equals(fqName)) {
			this.enclosingClassName = fqOuterName;
			this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
		}
		else if (this.className.equals(fqOuterName)) {
			this.memberClassNames.add(fqName);
		}
	}
}
 
Example 12
@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);
}
 
Example 13
@Override
public void visit(int version, int access, String name, String signature, String supername, String[] interfaces) {
	this.className = ClassUtils.convertResourcePathToClassName(name);
	this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
	this.isAnnotation = ((access & Opcodes.ACC_ANNOTATION) != 0);
	this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
	this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
	if (supername != null && !this.isInterface) {
		this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
	}
	this.interfaces = new String[interfaces.length];
	for (int i = 0; i < interfaces.length; i++) {
		this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
	}
}
 
Example 14
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
	if (outerName != null) {
		String fqName = ClassUtils.convertResourcePathToClassName(name);
		String fqOuterName = ClassUtils.convertResourcePathToClassName(outerName);
		if (this.className.equals(fqName)) {
			this.enclosingClassName = fqOuterName;
			this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
		}
		else if (this.className.equals(fqOuterName)) {
			this.memberClassNames.add(fqName);
		}
	}
}
 
Example 15
Source Project: mica   Source File: MicaBeanCopier.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 处理 map 的 copy
 * @param ce ClassEmitter
 * @param e CodeEmitter
 * @param sourceType sourceType
 * @param targetType targetType
 */
public void generateClassFormMap(ClassEmitter ce, CodeEmitter e, Type sourceType, Type targetType) {
	// 2018.12.27 by L.cm 支持链式 bean
	PropertyDescriptor[] setters = ReflectUtil.getBeanSetters(target);

	// 入口变量
	Local targetLocal = e.make_local();
	Local sourceLocal = e.make_local();
	e.load_arg(1);
	e.checkcast(targetType);
	e.store_local(targetLocal);
	e.load_arg(0);
	e.checkcast(sourceType);
	e.store_local(sourceLocal);
	Type mapBox = Type.getType(Object.class);

	for (PropertyDescriptor setter : setters) {
		String propName = setter.getName();

		// set 上有忽略的 注解
		CopyProperty targetIgnoreCopy = ReflectUtil.getAnnotation(target, propName, CopyProperty.class);
		if (targetIgnoreCopy != null) {
			if (targetIgnoreCopy.ignore()) {
				continue;
			}
			// 注解上的别名
			String aliasTargetPropName = targetIgnoreCopy.value();
			if (StringUtil.isNotBlank(aliasTargetPropName)) {
				propName = aliasTargetPropName;
			}
		}

		Method writeMethod = setter.getWriteMethod();
		MethodInfo write = ReflectUtils.getMethodInfo(writeMethod);
		Type setterType = write.getSignature().getArgumentTypes()[0];

		e.load_local(targetLocal);
		e.load_local(sourceLocal);

		e.push(propName);
		// 执行 map get
		e.invoke_interface(BEAN_MAP, BEAN_MAP_GET);
		// box 装箱,避免 array[] 数组问题
		e.box(mapBox);

		// 生成变量
		Local var = e.make_local();
		e.store_local(var);
		e.load_local(var);

		// 先判断 不为null,然后做类型判断
		Label l0 = e.make_label();
		e.ifnull(l0);
		EmitUtils.load_class(e, setterType);
		e.load_local(var);
		// ClassUtils.isAssignableValue(Integer.class, id)
		e.invoke_static(CLASS_UTILS, IS_ASSIGNABLE_VALUE, false);
		Label l1 = new Label();
		// 返回值,判断 链式 bean
		Class<?> returnType = writeMethod.getReturnType();
		if (useConverter) {
			e.if_jump(Opcodes.IFEQ, l1);
			e.load_local(targetLocal);
			e.load_local(var);
			e.unbox_or_zero(setterType);
			e.invoke(write);
			if (!returnType.equals(Void.TYPE)) {
				e.pop();
			}
			e.goTo(l0);
			e.visitLabel(l1);
			e.load_local(targetLocal);
			e.load_arg(2);
			e.load_local(var);
			EmitUtils.load_class(e, setterType);
			e.push(propName);
			e.invoke_interface(CONVERTER, CONVERT);
		} else {
			e.if_jump(Opcodes.IFEQ, l0);
			e.load_local(targetLocal);
			e.load_local(var);
		}
		e.unbox_or_zero(setterType);
		e.invoke(write);
		// 返回值,判断 链式 bean
		if (!returnType.equals(Void.TYPE)) {
			e.pop();
		}
		e.visitLabel(l0);
	}
	e.return_value();
	e.end_method();
	ce.end_class();
}
 
Example 16
Source Project: spring-analysis-note   Source File: AsmApi.java    License: MIT License 4 votes vote down vote up
/**
 * SPRING PATCH: always returns ASM7.
 */
static int value() {
    return Opcodes.ASM7;
}
 
Example 17
private static boolean isSyntheticOrBridged(int access) {
	return (((access & Opcodes.ACC_SYNTHETIC) | (access & Opcodes.ACC_BRIDGE)) > 0);
}
 
Example 18
private static boolean isStatic(int access) {
	return ((access & Opcodes.ACC_STATIC) > 0);
}
 
Example 19
Source Project: spring-analysis-note   Source File: SimpleAnnotationMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isInterface() {
	return (this.access & Opcodes.ACC_INTERFACE) != 0;
}
 
Example 20
Source Project: spring-analysis-note   Source File: SimpleAnnotationMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isAnnotation() {
	return (this.access & Opcodes.ACC_ANNOTATION) != 0;
}
 
Example 21
Source Project: spring-analysis-note   Source File: SimpleAnnotationMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isAbstract() {
	return (this.access & Opcodes.ACC_ABSTRACT) != 0;
}
 
Example 22
Source Project: spring-analysis-note   Source File: SimpleAnnotationMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isFinal() {
	return (this.access & Opcodes.ACC_FINAL) != 0;
}
 
Example 23
private boolean isBridge(int access) {
	return (access & Opcodes.ACC_BRIDGE) != 0;
}
 
Example 24
private boolean isInterface(int access) {
	return (access & Opcodes.ACC_INTERFACE) != 0;
}
 
Example 25
@Override
public boolean isAbstract() {
	return ((this.access & Opcodes.ACC_ABSTRACT) != 0);
}
 
Example 26
@Override
public boolean isStatic() {
	return ((this.access & Opcodes.ACC_STATIC) != 0);
}
 
Example 27
@Override
public boolean isFinal() {
	return ((this.access & Opcodes.ACC_FINAL) != 0);
}
 
Example 28
@Override
public boolean isOverridable() {
	return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0));
}
 
Example 29
Source Project: spring-analysis-note   Source File: SimpleMethodMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isAbstract() {
	return (this.access & Opcodes.ACC_ABSTRACT) != 0;
}
 
Example 30
Source Project: spring-analysis-note   Source File: SimpleMethodMetadata.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isStatic() {
	return (this.access & Opcodes.ACC_STATIC) != 0;
}