use of net.bytebuddy.description.annotation.AnnotationDescription in project incubator-skywalking by apache.
the class MethodAnnotationMatch method isMatch.
@Override
public boolean isMatch(TypeDescription typeDescription) {
for (MethodDescription.InDefinedShape methodDescription : typeDescription.getDeclaredMethods()) {
List<String> annotationList = new ArrayList<String>(Arrays.asList(annotations));
AnnotationList declaredAnnotations = methodDescription.getDeclaredAnnotations();
for (AnnotationDescription annotation : declaredAnnotations) {
annotationList.remove(annotation.getAnnotationType().getActualName());
}
if (annotationList.isEmpty()) {
return true;
}
}
return false;
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class AbstractMethodDescriptionTest method testIsDefault.
@Test
@SuppressWarnings("unchecked")
public void testIsDefault() throws Exception {
Map<String, AnnotationValue<?, ?>> properties = new LinkedHashMap<String, AnnotationValue<?, ?>>();
properties.put("boolean_property", AnnotationValue.ForConstant.of(true));
properties.put("boolean_property_array", AnnotationValue.ForConstant.of(new boolean[] { true }));
properties.put("byte_property", AnnotationValue.ForConstant.of((byte) 0));
properties.put("byte_property_array", AnnotationValue.ForConstant.of(new byte[] { 0 }));
properties.put("short_property", AnnotationValue.ForConstant.of((short) 0));
properties.put("short_property_array", AnnotationValue.ForConstant.of(new short[] { 0 }));
properties.put("int_property", AnnotationValue.ForConstant.of(0));
properties.put("int_property_array", AnnotationValue.ForConstant.of(new int[] { 0 }));
properties.put("long_property", AnnotationValue.ForConstant.of(0L));
properties.put("long_property_array", AnnotationValue.ForConstant.of(new long[] { 0 }));
properties.put("float_property", AnnotationValue.ForConstant.of(0f));
properties.put("float_property_array", AnnotationValue.ForConstant.of(new float[] { 0 }));
properties.put("double_property", AnnotationValue.ForConstant.of(0d));
properties.put("double_property_array", AnnotationValue.ForConstant.of(new double[] { 0d }));
properties.put("string_property", AnnotationValue.ForConstant.of("foo"));
properties.put("string_property_array", AnnotationValue.ForConstant.of(new String[] { "foo" }));
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
when(annotationDescription.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(SampleAnnotation.class));
properties.put("annotation_property", new AnnotationValue.ForAnnotationDescription(annotationDescription));
properties.put("annotation_property_array", AnnotationValue.ForDescriptionArray.of(new TypeDescription.ForLoadedType(SampleAnnotation.class), new AnnotationDescription[] { annotationDescription }));
EnumerationDescription enumerationDescription = mock(EnumerationDescription.class);
when(enumerationDescription.getEnumerationType()).thenReturn(new TypeDescription.ForLoadedType(SampleEnumeration.class));
properties.put("enum_property", AnnotationValue.ForEnumerationDescription.<Enum>of(enumerationDescription));
properties.put("enum_property_array", AnnotationValue.ForDescriptionArray.<Enum>of(new TypeDescription.ForLoadedType(SampleEnumeration.class), new EnumerationDescription[] { enumerationDescription }));
MethodList<?> methods = new TypeDescription.ForLoadedType(AnnotationValues.class).getDeclaredMethods();
for (Map.Entry<String, AnnotationValue<?, ?>> entry : properties.entrySet()) {
assertThat(methods.filter(named(entry.getKey())).getOnly().isDefaultValue(entry.getValue()), is(true));
assertThat(methods.filter(named(entry.getKey())).getOnly().isDefaultValue(mock(AnnotationValue.class)), is(false));
}
when(annotationDescription.getAnnotationType()).thenReturn(TypeDescription.OBJECT);
assertThat(methods.filter(named("annotation_property")).getOnly().isDefaultValue(new AnnotationValue.ForAnnotationDescription(annotationDescription)), is(false));
assertThat(methods.filter(named("annotation_property_array")).getOnly().isDefaultValue(AnnotationValue.ForDescriptionArray.of(new TypeDescription.ForLoadedType(Object.class), new AnnotationDescription[] { annotationDescription })), is(false));
when(enumerationDescription.getEnumerationType()).thenReturn(TypeDescription.OBJECT);
assertThat(methods.filter(named("enum_property")).getOnly().isDefaultValue(AnnotationValue.ForEnumerationDescription.<Enum>of(enumerationDescription)), is(false));
assertThat(methods.filter(named("enum_property_array")).getOnly().isDefaultValue(AnnotationValue.ForDescriptionArray.<Enum>of(new TypeDescription.ForLoadedType(Object.class), new EnumerationDescription[] { enumerationDescription })), is(false));
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class InstrumentedTypeDefaultTest method testWithAnnotation.
@Test
public void testWithAnnotation() throws Exception {
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
InstrumentedType instrumentedType = makePlainInstrumentedType();
assertThat(instrumentedType.getDeclaredAnnotations().size(), is(0));
instrumentedType = instrumentedType.withAnnotations(Collections.singletonList(annotationDescription));
assertThat(instrumentedType.getDeclaredAnnotations(), is(Collections.singletonList(annotationDescription)));
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class TypeAttributeAppenderForInstrumentedTypeDifferentiatingTest method testObjectProperties.
@Test
public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(TypeAttributeAppender.ForInstrumentedType.Differentiating.class).refine(new ObjectPropertyAssertion.Refinement<TypeDescription>() {
@Override
public void apply(TypeDescription mock) {
AnnotationDescription[] annotationDescription = new AnnotationDescription[new Random().nextInt(10000)];
when(mock.getDeclaredAnnotations()).thenReturn(new AnnotationList.Explicit(Arrays.asList(annotationDescription)));
when(mock.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
when(mock.getInterfaces()).thenReturn(new TypeList.Generic.Empty());
}
}).apply();
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class TargetMethodAnnotationDrivenBinderTest method testIgnoreForBindingAnnotation.
@Test
public void testIgnoreForBindingAnnotation() throws Exception {
when(targetMethod.isAccessibleTo(instrumentedType)).thenReturn(true);
AnnotationDescription ignoreForBinding = mock(AnnotationDescription.class);
when(ignoreForBinding.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(IgnoreForBinding.class));
when(targetMethod.getDeclaredAnnotations()).thenReturn(new AnnotationList.Explicit(Collections.singletonList(ignoreForBinding)));
when(termination.isValid()).thenReturn(true);
MethodDelegationBinder methodDelegationBinder = TargetMethodAnnotationDrivenBinder.of(Collections.<TargetMethodAnnotationDrivenBinder.ParameterBinder<?>>emptyList());
assertThat(methodDelegationBinder.compile(targetMethod).bind(implementationTarget, sourceMethod, terminationHandler, methodInvoker, assigner).isValid(), is(false));
verifyZeroInteractions(assigner);
verifyZeroInteractions(implementationTarget);
verifyZeroInteractions(sourceMethod);
}
Aggregations