/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return typeDescription.getDeclaredAnnotations(); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return delegate.getDeclaredAnnotations(); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return delegate().getDeclaredAnnotations(); }
/** * {@inheritDoc} */ public boolean matches(TypeDescription target) { return target.getDeclaredAnnotations().isAnnotationPresent(Enhance.class); }
/** * {@inheritDoc} */ public boolean matches(TypeDescription target) { return target.getDeclaredAnnotations().isAnnotationPresent(Enhance.class); }
@Override public boolean hasAnnotation(Class<? extends Annotation> annotationType) { return typeDescription.getDeclaredAnnotations().isAnnotationPresent( annotationType ); }
/** * {@inheritDoc} */ public boolean isDocumented() { return getAnnotationType().getDeclaredAnnotations().isAnnotationPresent(Documented.class); }
/** * {@inheritDoc} */ public boolean isInherited() { return getAnnotationType().getDeclaredAnnotations().isAnnotationPresent(Inherited.class); }
/** * {@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 void register(DynamicType dynamicType, ClassLoader classLoader, InjectorFactory injectorFactory) { Map<TypeDescription, byte[]> auxiliaryTypes = dynamicType.getAuxiliaryTypes(); Map<TypeDescription, byte[]> independentTypes = new LinkedHashMap<TypeDescription, byte[]>(auxiliaryTypes); for (TypeDescription auxiliaryType : auxiliaryTypes.keySet()) { if (!auxiliaryType.getDeclaredAnnotations().isAnnotationPresent(AuxiliaryType.SignatureRelevant.class)) { independentTypes.remove(auxiliaryType); } } if (!independentTypes.isEmpty()) { ClassInjector classInjector = injectorFactory.resolve(); Map<TypeDescription, LoadedTypeInitializer> loadedTypeInitializers = dynamicType.getLoadedTypeInitializers(); for (Map.Entry<TypeDescription, Class<?>> entry : classInjector.inject(independentTypes).entrySet()) { loadedTypeInitializers.get(entry.getKey()).onLoad(entry.getValue()); } } } }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { Resolution resolution = typePool.describe(name + "." + PackageDescription.PACKAGE_CLASS_NAME); return resolution.isResolved() ? resolution.resolve().getDeclaredAnnotations() : new AnnotationList.Empty(); }
/** * {@inheritDoc} */ public RetentionPolicy getRetention() { AnnotationDescription.Loadable<Retention> retention = getAnnotationType().getDeclaredAnnotations().ofType(Retention.class); return retention == null ? RetentionPolicy.CLASS : retention.loadSilent().value(); }
/** * Creates a new differentiating type attribute appender. * * @param typeDescription The type for which to resolve all exclusion indices. */ public Differentiating(TypeDescription typeDescription) { this(typeDescription.getDeclaredAnnotations().size(), typeDescription.getTypeVariables().size(), typeDescription.getInterfaces().size()); }
@Override protected HashCodeMethod hashCodeMethod(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); return superClass != null && superClass.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class) ? HashCodeMethod.usingSuperClassOffset() : HashCodeMethod.usingDefaultOffset(); }
@Override protected EqualsMethod equalsMethod(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); return superClass != null && superClass.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class) ? EqualsMethod.requiringSuperClassEquality() : EqualsMethod.isolated(); } },
private static TypeDescription.Generic target(AnnotatedFieldDescription persistentField) { AnnotationDescription.Loadable<Access> access = persistentField.getDeclaringType().asErasure().getDeclaredAnnotations().ofType( Access.class ); if ( access != null && access.loadSilent().value() == AccessType.FIELD ) { return persistentField.getType(); } else { Optional<MethodDescription> getter = persistentField.getGetter(); if ( getter.isPresent() ) { return getter.get().getReturnType(); } else { return persistentField.getType(); } } }
/** * {@inheritDoc} */ public void apply(ClassVisitor classVisitor, TypeDescription instrumentedType, AnnotationValueFilter annotationValueFilter) { AnnotationAppender annotationAppender = new AnnotationAppender.Default(new AnnotationAppender.Target.OnType(classVisitor)); annotationAppender = AnnotationAppender.ForTypeAnnotations.ofTypeVariable(annotationAppender, annotationValueFilter, AnnotationAppender.ForTypeAnnotations.VARIABLE_ON_TYPE, instrumentedType.getTypeVariables()); TypeDescription.Generic superClass = instrumentedType.getSuperClass(); if (superClass != null) { annotationAppender = superClass.accept(AnnotationAppender.ForTypeAnnotations.ofSuperClass(annotationAppender, annotationValueFilter)); } int interfaceIndex = 0; for (TypeDescription.Generic interfaceType : instrumentedType.getInterfaces()) { annotationAppender = interfaceType.accept(AnnotationAppender.ForTypeAnnotations.ofInterfaceType(annotationAppender, annotationValueFilter, interfaceIndex++)); } for (AnnotationDescription annotation : instrumentedType.getDeclaredAnnotations()) { annotationAppender = annotationAppender.append(annotation, annotationValueFilter); } }
@Override protected HashCodeMethod hashCodeMethod(TypeDescription instrumentedType) { TypeDefinition typeDefinition = instrumentedType.getSuperClass(); while (typeDefinition != null && !typeDefinition.represents(Object.class)) { if (typeDefinition.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class)) { return HashCodeMethod.usingSuperClassOffset(); } MethodList<?> hashCode = typeDefinition.getDeclaredMethods().filter(isHashCode()); if (!hashCode.isEmpty()) { return hashCode.getOnly().isAbstract() ? HashCodeMethod.usingDefaultOffset() : HashCodeMethod.usingSuperClassOffset(); } typeDefinition = typeDefinition.getSuperClass(); } return HashCodeMethod.usingDefaultOffset(); }
@Override protected EqualsMethod equalsMethod(TypeDescription instrumentedType) { TypeDefinition typeDefinition = instrumentedType.getSuperClass(); while (typeDefinition != null && !typeDefinition.represents(Object.class)) { if (typeDefinition.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class)) { return EqualsMethod.requiringSuperClassEquality(); } MethodList<?> hashCode = typeDefinition.getDeclaredMethods().filter(isHashCode()); if (!hashCode.isEmpty()) { return hashCode.getOnly().isAbstract() ? EqualsMethod.isolated() : EqualsMethod.requiringSuperClassEquality(); } typeDefinition = typeDefinition.getSuperClass().asErasure(); } return EqualsMethod.isolated(); } },
/** * {@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; }