org.springframework.asm.Opcodes Java Examples

The following examples show how to use org.springframework.asm.Opcodes. 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 File: ClassMetadataReadingVisitor.java    From java-technology-stack with 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
Source File: ClassMetadataReadingVisitor.java    From spring-analysis-note with 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 #3
Source File: ClassMetadataReadingVisitor.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: ClassMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #5
Source File: ClassMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #6
Source File: AnnotationMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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
Source File: ClassMetadataReadingVisitor.java    From spring-analysis-note with 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 #8
Source File: AnnotationMetadataReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 #9
Source File: AnnotationMetadataReadingVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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
Source File: SimpleAnnotationMetadataReadingVisitor.java    From spring-analysis-note with 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 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 #11
Source File: AnnotationMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: ClassMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: ClassMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: ClassMetadataReadingVisitor.java    From java-technology-stack with 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 #15
Source File: MethodMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isFinal() {
	return ((this.access & Opcodes.ACC_FINAL) != 0);
}
 
Example #16
Source File: ClassMetadataReadingVisitor.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
public void visitInnerClass(String name, String outerName, String innerName, int access) {
    if (outerName != null && this.className.equals(ClassUtils.convertResourcePathToClassName(name))) {
        this.enclosingClassName = ClassUtils.convertResourcePathToClassName(outerName);
        this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
    }
}
 
Example #17
Source File: LocalVariableTableParameterNameDiscoverer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isSyntheticOrBridged(int access) {
	return (((access & Opcodes.ACC_SYNTHETIC) | (access & Opcodes.ACC_BRIDGE)) > 0);
}
 
Example #18
Source File: LocalVariableTableParameterNameDiscoverer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isStatic(int access) {
	return ((access & Opcodes.ACC_STATIC) > 0);
}
 
Example #19
Source File: MethodMetadataReadingVisitor.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean isOverridable() {
	return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0));
}
 
Example #20
Source File: MethodMetadataReadingVisitor.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean isFinal() {
	return ((this.access & Opcodes.ACC_FINAL) != 0);
}
 
Example #21
Source File: MethodMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isAbstract() {
	return ((this.access & Opcodes.ACC_ABSTRACT) != 0);
}
 
Example #22
Source File: MethodMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isStatic() {
	return ((this.access & Opcodes.ACC_STATIC) != 0);
}
 
Example #23
Source File: MethodMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isOverridable() {
	return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0));
}
 
Example #24
Source File: MethodMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isOverridable() {
	return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0));
}
 
Example #25
Source File: LocalVariableTableParameterNameDiscoverer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private static boolean isSyntheticOrBridged(int access) {
	return (((access & Opcodes.ACC_SYNTHETIC) | (access & Opcodes.ACC_BRIDGE)) > 0);
}
 
Example #26
Source File: LocalVariableTableParameterNameDiscoverer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private static boolean isStatic(int access) {
	return ((access & Opcodes.ACC_STATIC) > 0);
}
 
Example #27
Source File: MethodMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAbstract() {
	return ((this.access & Opcodes.ACC_ABSTRACT) != 0);
}
 
Example #28
Source File: MethodMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isStatic() {
	return ((this.access & Opcodes.ACC_STATIC) != 0);
}
 
Example #29
Source File: MethodMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isFinal() {
	return ((this.access & Opcodes.ACC_FINAL) != 0);
}
 
Example #30
Source File: MicaBeanCopier.java    From mica with 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();
}