@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { return isAnnotatedWith(Timed.class); }
@Override protected ElementMatcher.Junction<TypeDescription> getNarrowTypesMatcher() { return isAnnotatedWith(MonitorGauges.class); }
@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { return isAnnotatedWith(ExceptionMetered.class); }
@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { return isAnnotatedWith(Metered.class); }
@Override protected ElementMatcher.Junction<TypeDescription> getNarrowTypesMatcher() { return isAnnotatedWith(Path.class); }
/** * Matches an {@link AnnotationSource} for declared annotations. * This matcher does not match inherited annotations which only exist for classes. Use * {@link net.bytebuddy.matcher.ElementMatchers#inheritsAnnotation(Class)} for matching inherited annotations. * * @param type The annotation type to match against. * @param <T> The type of the matched object. * @return A matcher that validates that an annotated element is annotated with an annotation of {@code type}. */ public static <T extends AnnotationSource> ElementMatcher.Junction<T> isAnnotatedWith(Class<? extends Annotation> type) { return isAnnotatedWith(TypeDescription.ForLoadedType.of(type)); }
/** * Matches an {@link AnnotationSource} for declared annotations. * This matcher does not match inherited annotations which only exist for classes. Use * {@link net.bytebuddy.matcher.ElementMatchers#inheritsAnnotation(TypeDescription)} * for matching inherited annotations. * * @param type The annotation type to match against. * @param <T> The type of the matched object. * @return A matcher that validates that an annotated element is annotated with an annotation of {@code type}. */ public static <T extends AnnotationSource> ElementMatcher.Junction<T> isAnnotatedWith(TypeDescription type) { return isAnnotatedWith(is(type)); }
@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { return isAnnotatedWith(SLA.class).or(isAnnotatedWith(SLAs.class)); }
@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { return isAnnotatedWith(GET.class) .or(isAnnotatedWith(POST.class)) .or(isAnnotatedWith(PUT.class)) .or(isAnnotatedWith(DELETE.class)) .or(isAnnotatedWith(HEAD.class)); }
public static FieldList<FieldDescription.InDefinedShape> getFieldsWithAnnotation(Class<?> c, Class<? extends Annotation> a) { return getAllFields(c) .filter(ElementMatchers.isAnnotatedWith(a)); }
public static FieldList<FieldDescription.InDefinedShape> getFieldsWithAnnotation(Class<?> c, Class<? extends Annotation> a) { return getAllFields(c) .filter(ElementMatchers.isAnnotatedWith(a)); }
@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { ElementMatcher.Junction<MethodDescription> matcher = isAnnotatedWith(Traced.class) // TODO maybe add a configuration to disable super method search as it is relatively costly // InstrumentationPerformanceTest without: ~20ms with: ~420ms // 0,5s is relatively much compared to other matchers but not really noticeable on startup .or(overridesSuperMethodThat(isAnnotatedWith(Traced.class)).onSuperClassesThat(isInsideMonitoredProject())); for (Class<? extends Annotation> annotation : asyncCallAnnotations) { matcher = matcher.or(isAnnotatedWith(annotation)); } return matcher; }
@Override protected ElementMatcher.Junction<TypeDescription> getNarrowTypesMatcher() { return isAnnotatedWith(Remote.class).or(implementsInterfaceWhichIsAnnotatedWithRemote()); }
/** * Creates a plugin for caching method return values. */ public CachedReturnPlugin() { super(declaresMethod(isAnnotatedWith(Enhance.class))); randomString = new RandomString(); classFileLocator = ClassFileLocator.ForClassLoader.of(CachedReturnPlugin.class.getClassLoader()); TypePool typePool = TypePool.Default.of(classFileLocator); adviceByType = new HashMap<TypeDescription, TypeDescription>(); for (Class<?> type : new Class<?>[]{ boolean.class, byte.class, short.class, char.class, int.class, long.class, float.class, double.class, Object.class }) { adviceByType.put(TypeDescription.ForLoadedType.ForLoadedType.of(type), typePool.describe(CachedReturnPlugin.class.getName() + ADVICE_INFIX + type.getSimpleName()).resolve()); } }
/** * Creates a dispatcher for inlined advice method. * * @param adviceMethod The advice method. */ protected Inlining(MethodDescription.InDefinedShape adviceMethod) { this.adviceMethod = adviceMethod; namedTypes = new HashMap<String, TypeDefinition>(); for (ParameterDescription parameterDescription : adviceMethod.getParameters().filter(isAnnotatedWith(Local.class))) { String name = parameterDescription.getDeclaredAnnotations().ofType(Local.class).loadSilent().value(); TypeDefinition previous = namedTypes.put(name, parameterDescription.getType()); if (previous != null && !previous.equals(parameterDescription.getType())) { throw new IllegalStateException("Local variable for " + name + " is defined with inconsistent types"); } } }
@Override protected ElementMatcher.Junction<MethodDescription> getExtraMethodElementMatcher() { return isPublic().and(not(isAnnotatedWith(Traced.class))); }
/** * {@inheritDoc} */ public Dispatcher.Resolved.ForMethodExit asMethodExit(List<? extends OffsetMapping.Factory<?>> userFactories, ClassReader classReader, Unresolved methodEnter) { Map<String, TypeDefinition> namedTypes = methodEnter.getNamedTypes(); for (ParameterDescription parameterDescription : adviceMethod.getParameters().filter(isAnnotatedWith(Local.class))) { String name = parameterDescription.getDeclaredAnnotations().ofType(Local.class).loadSilent().value(); TypeDefinition typeDefinition = namedTypes.get(name); if (typeDefinition == null) { throw new IllegalStateException(adviceMethod + " attempts use of undeclared local variable " + name); } else if (!typeDefinition.equals(parameterDescription.getType())) { throw new IllegalStateException(adviceMethod + " does not read variable " + name + " as " + typeDefinition); } } return Resolved.ForMethodExit.of(adviceMethod, namedTypes, userFactories, methodEnter.getAdviceType()); }
@Override public boolean matches(TypeDescription target) { return !target.getInterfaces().asErasures().filter(isAnnotatedWith(Remote.class)).isEmpty(); } }
@Override public boolean matches(MethodDescription target) { return target.getDeclaringType().getInterfaces().asErasures() .filter(isAnnotatedWith(Remote.class)) .filter(isDeclaredInInterfaceHierarchy(target)).size() > 0; } }
/** * {@inheritDoc} */ public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) { Enhance enhance = typeDescription.getDeclaredAnnotations().ofType(Enhance.class).loadSilent(); if (typeDescription.getDeclaredMethods().filter(isToString()).isEmpty()) { builder = builder.method(isToString()).intercept(ToStringMethod.prefixedBy(enhance.prefix().getPrefixResolver()) .withIgnoredFields(enhance.includeSyntheticFields() ? ElementMatchers.<FieldDescription>none() : ElementMatchers.<FieldDescription>isSynthetic()) .withIgnoredFields(isAnnotatedWith(Exclude.class))); } return builder; }