use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class AnnotationAppenderDefaultTest method makeTypeWithAnnotation.
private Class<?> makeTypeWithAnnotation(Annotation annotation) throws Exception {
when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), Opcodes.ACC_PUBLIC, BAR.replace('.', '/'), null, Type.getInternalName(Object.class), null);
AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true);
when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
annotationAppender.append(annotationDescription, valueFilter);
classWriter.visitEnd();
Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
assertThat(bar.getName(), is(BAR));
assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
return bar;
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class MethodAttributeAppenderForInstrumentedMethodTest method testJdkTypeIsFiltered.
@Test
@SuppressWarnings("unchecked")
public void testJdkTypeIsFiltered() throws Exception {
when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
TypeDescription annotationType = mock(TypeDescription.class);
when(annotationType.getDeclaredMethods()).thenReturn(new MethodList.Empty<MethodDescription.InDefinedShape>());
when(annotationDescription.getRetention()).thenReturn(RetentionPolicy.RUNTIME);
when(annotationDescription.getAnnotationType()).thenReturn(annotationType);
when(annotationType.getActualName()).thenReturn("jdk.internal.Sample");
when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Explicit(annotationDescription));
when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
verifyZeroInteractions(methodVisitor);
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testNoneAnnotation.
@Test
public void testNoneAnnotation() throws Exception {
AnnotationDescription annotationDescription = new TypeDescription.ForLoadedType(IsAnnotatedWith.class).getDeclaredAnnotations().ofType(IsAnnotatedWithAnnotation.class);
assertThat(ElementMatchers.noneOf(IsAnnotatedWith.class.getAnnotation(IsAnnotatedWithAnnotation.class)).matches(annotationDescription), is(false));
assertThat(ElementMatchers.noneOf(IsAnnotatedWith.class.getAnnotation(IsAnnotatedWithAnnotation.class), Other.class.getAnnotation(OtherAnnotation.class)).matches(annotationDescription), is(false));
assertThat(ElementMatchers.noneOf(Other.class.getAnnotation(OtherAnnotation.class)).matches(annotationDescription), is(true));
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testAnnotationType.
@Test
public void testAnnotationType() throws Exception {
AnnotationDescription annotationDescription = new TypeDescription.ForLoadedType(IsAnnotatedWith.class).getDeclaredAnnotations().ofType(IsAnnotatedWithAnnotation.class);
assertThat(ElementMatchers.annotationType(IsAnnotatedWithAnnotation.class).matches(annotationDescription), is(true));
assertThat(ElementMatchers.annotationType(OtherAnnotation.class).matches(annotationDescription), is(false));
assertThat(ElementMatchers.annotationType(IsAnnotatedWithAnnotation.class).matches(AnnotationDescription.ForLoadedAnnotation.of(Other.class.getAnnotation(OtherAnnotation.class))), is(false));
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project incubator-skywalking by apache.
the class ClassAnnotationMatch method isMatch.
@Override
public boolean isMatch(TypeDescription typeDescription) {
List<String> annotationList = new ArrayList<String>(Arrays.asList(annotations));
AnnotationList declaredAnnotations = typeDescription.getDeclaredAnnotations();
for (AnnotationDescription annotation : declaredAnnotations) {
annotationList.remove(annotation.getAnnotationType().getActualName());
}
if (annotationList.isEmpty()) {
return true;
}
return false;
}
Aggregations