org.springframework.asm.AnnotationVisitor Java Examples

The following examples show how to use org.springframework.asm.AnnotationVisitor. 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: MergedAnnotationReadingVisitor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
static <A extends Annotation> AnnotationVisitor get(@Nullable ClassLoader classLoader,
		@Nullable Supplier<Object> sourceSupplier, String descriptor, boolean visible,
		Consumer<MergedAnnotation<A>> consumer) {

	if (!visible) {
		return null;
	}

	String typeName = Type.getType(descriptor).getClassName();
	if (AnnotationFilter.PLAIN.matches(typeName)) {
		return null;
	}

	Object source = (sourceSupplier != null ? sourceSupplier.get() : null);
	try {
		Class<A> annotationType = (Class<A>) ClassUtils.forName(typeName, classLoader);
		return new MergedAnnotationReadingVisitor<>(classLoader, source, annotationType, consumer);
	}
	catch (ClassNotFoundException | LinkageError ex) {
		return null;
	}
}
 
Example #2
Source File: MergedAnnotationMetadataVisitorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void loadFrom(Class<?> type) {
	ClassVisitor visitor = new ClassVisitor(SpringAsmInfo.ASM_VERSION) {

		@Override
		public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
			return MergedAnnotationReadingVisitor.get(getClass().getClassLoader(),
					null, descriptor, visible,
					annotation -> MergedAnnotationMetadataVisitorTests.this.annotation = annotation);
		}

	};
	try {
		new ClassReader(type.getName()).accept(visitor, ClassReader.SKIP_DEBUG
				| ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
	}
	catch (IOException ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example #3
Source File: AnnotationMetadataReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
	if (!visible) {
		return null;
	}
	String className = Type.getType(desc).getClassName();
	if (AnnotationUtils.isInJavaLangAnnotationPackage(className)) {
		return null;
	}
	this.annotationSet.add(className);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #4
Source File: MethodMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
	String className = Type.getType(desc).getClassName();
	this.methodMetadataSet.add(this);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #5
Source File: RecursiveAnnotationArrayVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes();
	this.allNestedAttributes.add(nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #6
Source File: AbstractRecursiveAnnotationVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes();
	this.attributes.put(attributeName, nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #7
Source File: AnnotationMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
	String className = Type.getType(desc).getClassName();
	this.annotationSet.add(className);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #8
Source File: MethodMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
	String className = Type.getType(desc).getClassName();
	this.methodMetadataSet.add(this);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #9
Source File: RecursiveAnnotationArrayVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
	this.allNestedAttributes.add(nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #10
Source File: AbstractRecursiveAnnotationVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
	this.attributes.put(attributeName, nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #11
Source File: AnnotationMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
	String className = Type.getType(desc).getClassName();
	this.annotationSet.add(className);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #12
Source File: MethodMetadataReadingVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
	this.methodMetadataSet.add(this);
	String className = Type.getType(desc).getClassName();
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #13
Source File: RecursiveAnnotationArrayVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
	this.allNestedAttributes.add(nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #14
Source File: AbstractRecursiveAnnotationVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
	this.attributes.put(attributeName, nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #15
Source File: AnnotationMetadataReadingVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
	String className = Type.getType(desc).getClassName();
	this.annotationSet.add(className);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #16
Source File: RecursiveAnnotationArrayVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
	this.allNestedAttributes.add(nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #17
Source File: MethodMetadataReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
	if (!visible) {
		return null;
	}
	this.methodMetadataSet.add(this);
	String className = Type.getType(desc).getClassName();
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example #18
Source File: MergedAnnotationReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
private <T extends Annotation> AnnotationVisitor visitAnnotation(
		String descriptor, Consumer<MergedAnnotation<T>> consumer) {

	String className = Type.getType(descriptor).getClassName();
	if (AnnotationFilter.PLAIN.matches(className)) {
		return null;
	}
	Class<T> type = (Class<T>) ClassUtils.resolveClassName(className, this.classLoader);
	return new MergedAnnotationReadingVisitor<>(this.classLoader, this.source, type, consumer);
}
 
Example #19
Source File: AbstractRecursiveAnnotationVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
	String annotationType = Type.getType(asmTypeDescriptor).getClassName();
	AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
	this.attributes.put(attributeName, nestedAttributes);
	return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
}
 
Example #20
Source File: SimpleAnnotationMetadataReadingVisitor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
	return MergedAnnotationReadingVisitor.get(this.classLoader, this::getSource,
			descriptor, visible, this.annotations::add);
}
 
Example #21
Source File: MergedAnnotationReadingVisitor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public AnnotationVisitor visitAnnotation(String name, String descriptor) {
	return visitAnnotation(descriptor, annotation -> this.attributes.put(name, annotation));
}
 
Example #22
Source File: ClassMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitArray(String name) {
	return this;
}
 
Example #23
Source File: ClassMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
	return this;
}
 
Example #24
Source File: ClassMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
	// no-op
	return new EmptyAnnotationVisitor();
}
 
Example #25
Source File: AbstractRecursiveAnnotationVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitArray(String attributeName) {
	return new RecursiveAnnotationArrayVisitor(attributeName, this.attributes, this.classLoader);
}
 
Example #26
Source File: MergedAnnotationReadingVisitor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public AnnotationVisitor visitArray(String name) {
	return new ArrayVisitor(value -> this.attributes.put(name, value));
}
 
Example #27
Source File: MergedAnnotationReadingVisitor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public AnnotationVisitor visitAnnotation(String name, String descriptor) {
	return MergedAnnotationReadingVisitor.this.visitAnnotation(descriptor, this.elements::add);
}
 
Example #28
Source File: ClassMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitArray(String name) {
	return this;
}
 
Example #29
Source File: ClassMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
	return this;
}
 
Example #30
Source File: ClassMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
	// no-op
	return new EmptyAnnotationVisitor();
}