/** * {@inheritDoc} */ public boolean matches(TypeDescription target) { return target.getDeclaredAnnotations().isAnnotationPresent(Enhance.class); }
<T extends Annotation> AnnotationDescription.Loadable<T> getAnnotation(Class<T> annotationType) { return getAnnotations().ofType( annotationType ); }
private void createChecks(String fullMethodSignature, AnnotationList declaredAnnotations, TimerNames timerNames) { if (declaredAnnotations.isAnnotationPresent(SLA.class)) { createSlaCheck(declaredAnnotations.ofType(SLA.class).loadSilent(), fullMethodSignature, timerNames); } if (declaredAnnotations.isAnnotationPresent(SLAs.class)) { for (SLA sla : declaredAnnotations.ofType(SLAs.class).loadSilent().value()) { createSlaCheck(sla, fullMethodSignature, timerNames); } } }
@Nullable private Object getAnnotationValue(MethodDescription instrumentedMethod, AnnotationValueExtractor annotationValueExtractor) { for (TypeDescription typeDescription : instrumentedMethod.getDeclaredAnnotations().asTypeList()) { if (named(annotationValueExtractor.annotationClassName()).matches(typeDescription)) { for (MethodDescription.InDefinedShape annotationMethod : typeDescription.getDeclaredMethods()) { if (annotationMethod.getName().equals(annotationValueExtractor.method())) { return instrumentedMethod.getDeclaredAnnotations().ofType(typeDescription).getValue(annotationMethod).resolve(); } } } } return null; }
/** * @see me.seeber.gradle.ide.eclipse.annotations.Nullability#getParameterNullability(net.bytebuddy.description.method.ParameterDescription) */ @Override public Nullness getParameterNullability(ParameterDescription parameter) { PackageDescription pakkage = parameter.getDeclaringMethod().getDeclaringType().asErasure().getPackage(); Optional<AnnotationDescription> packageAnnotation = pakkage.getDeclaredAnnotations().stream() .filter(a -> a.getAnnotationType().getName().equals(this.nonnullParameterDefaultAnnotation)).findAny(); Nullness defaultNullness = Validate .notNull(packageAnnotation.map(a -> Nullness.NONNULL).orElse(Nullness.UNDEFINED)); Nullness nullability = getNullability(parameter.getDeclaredAnnotations()); return defaultNullness.override(nullability); }
AnnotationAppender.ForTypeAnnotations.VARIABLE_ON_INVOKEABLE, methodDescription.getTypeVariables()); for (AnnotationDescription annotation : methodDescription.getDeclaredAnnotations().filter(not(annotationType(nameStartsWith("jdk.internal."))))) { annotationAppender = annotationAppender.append(annotation, annotationValueFilter);
@Override protected NamingParameters getNamingParameters(MethodDescription instrumentedMethod) { if (instrumentedMethod.getDeclaredAnnotations().isAnnotationPresent(Timed.class)) { final Timed timed = instrumentedMethod.getDeclaredAnnotations().ofType(Timed.class).loadSilent(); return new NamingParameters(timed.name(), timed.absolute()); } else { return new NamingParameters("", false); } }
/** * @see me.seeber.gradle.ide.eclipse.annotations.Nullability#getParameterNullability(net.bytebuddy.description.method.ParameterDescription) */ @Override public Nullness getParameterNullability(ParameterDescription parameter) { PackageDescription pakkage = parameter.getDeclaringMethod().getDeclaringType().asErasure().getPackage(); Optional<AnnotationDescription> packageAnnotation = pakkage.getDeclaredAnnotations().stream() .filter(a -> a.getAnnotationType().getName().equals(this.nonnullParameterDefaultAnnotation)).findAny(); Nullness defaultNullness = Validate .notNull(packageAnnotation.map(a -> Nullness.NONNULL).orElse(Nullness.UNDEFINED)); Nullness nullability = getNullability(parameter.getDeclaredAnnotations()); return defaultNullness.override(nullability); }
/** * {@inheritDoc} */ public Set<ElementType> getElementTypes() { AnnotationDescription.Loadable<Target> target = getAnnotationType().getDeclaredAnnotations().ofType(Target.class); return new HashSet<ElementType>(Arrays.asList(target == null ? DEFAULT_TARGET : target.loadSilent().value())); }
/** * {@inheritDoc} */ public boolean matches(TypeDescription target) { return target.getDeclaredAnnotations().isAnnotationPresent(Enhance.class); }
@Override public boolean matches(MethodDescription targetMethod) { final AnnotationList declaredAnnotationsOfType = targetMethod.getDeclaringType().asErasure().getDeclaredAnnotations(); if (declaredAnnotationsOfType.isAnnotationPresent(Remote.class)) { final Class[] remoteInterfaces = declaredAnnotationsOfType.ofType(Remote.class).loadSilent().value(); if (!new TypeList.ForLoadedTypes(remoteInterfaces).filter(isDeclaredInInterfaceHierarchy(targetMethod)).isEmpty()) { return true; } } return false; } }
/** * {@inheritDoc} */ public boolean matches(FieldDescription target) { AnnotationDescription.Loadable<ValueHandling> annotation = target.getDeclaredAnnotations().ofType(ValueHandling.class); return annotation != null && annotation.loadSilent().value() == sort; } }
/** * Validates if a method should be ignored for binding. * * @param methodDescription The method to validate. * @return {@code true} if the method should not be considered for binding. */ public static boolean check(MethodDescription methodDescription) { return methodDescription.getDeclaredAnnotations().isAnnotationPresent(IgnoreForBinding.class); } }
@Override public boolean matches(MethodDescription.InDefinedShape targetMethod) { final AnnotationList declaredAnnotationsOfType = targetMethod.getDeclaringType().getDeclaredAnnotations(); if (declaredAnnotationsOfType.isAnnotationPresent(Remote.class)) { final Class[] remoteInterfaces = declaredAnnotationsOfType.ofType(Remote.class).loadSilent().value(); if (!new TypeList.ForLoadedTypes(remoteInterfaces).filter(isDeclaredInInterfaceHierarchy(targetMethod)).isEmpty()) { return true; } } return false; } }
/** * {@inheritDoc} */ public Resolution resolve(MethodDescription source, MethodDelegationBinder.MethodBinding left, MethodDelegationBinder.MethodBinding right) { int leftPriority = resolve(left.getTarget().getDeclaredAnnotations().ofType(BindingPriority.class)); int rightPriority = resolve(right.getTarget().getDeclaredAnnotations().ofType(BindingPriority.class)); if (leftPriority == rightPriority) { return Resolution.AMBIGUOUS; } else if (leftPriority < rightPriority) { return Resolution.RIGHT; } else { return Resolution.LEFT; } } }
@Override public boolean hasAnnotation(Class<? extends Annotation> annotationType) { return typeDescription.getDeclaredAnnotations().isAnnotationPresent( annotationType ); }
/** * {@inheritDoc} */ public int compare(FieldDescription.InDefinedShape left, FieldDescription.InDefinedShape right) { AnnotationDescription.Loadable<Sorted> leftAnnotation = left.getDeclaredAnnotations().ofType(Sorted.class); AnnotationDescription.Loadable<Sorted> rightAnnotation = right.getDeclaredAnnotations().ofType(Sorted.class); int leftValue = leftAnnotation == null ? Sorted.DEFAULT : leftAnnotation.loadSilent().value(); int rightValue = rightAnnotation == null ? Sorted.DEFAULT : rightAnnotation.loadSilent().value(); if (leftValue > rightValue) { return -1; } else if (leftValue < rightValue) { return 1; } else { return 0; } } }
@Override public boolean hasAnnotation(Class<? extends Annotation> annotationType) { return getAnnotations().isAnnotationPresent( annotationType ); }
/** * 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"); } } }
/** * {@inheritDoc} */ public int getActualModifiers() { return getModifiers() | (getDeclaredAnnotations().isAnnotationPresent(Deprecated.class) ? Opcodes.ACC_DEPRECATED : EMPTY_MASK); }