/** * {@inheritDoc} */ public TypeList.Generic getInterfaces() { return typeDescription.getInterfaces(); }
/** * {@inheritDoc} */ public TypeList.Generic getInterfaces() { return delegate().getInterfaces(); }
/** * {@inheritDoc} */ public TypeList.Generic getInterfaces() { return new TypeList.Generic.ForDetachedTypes.WithResolvedErasure(typeDescription.getInterfaces(), Visitor.Reifying.INHERITING); }
/** * {@inheritDoc} */ public TypeList.Generic getInterfaces() { return new ClassLoadingTypeList(delegate.getInterfaces(), classLoader, classLoadingDelegate); }
/** * Filters the relevant prioritized interfaces for a given type, i.e. finds the types that are * directly declared on a given instrumented type. * * @param typeDescription The instrumented type for which the prioritized interfaces are to be filtered. * @return A list of prioritized interfaces that are additionally implemented by the given type. */ private List<TypeDescription> filterRelevant(TypeDescription typeDescription) { List<TypeDescription> filtered = new ArrayList<TypeDescription>(prioritizedInterfaces.size()); Set<TypeDescription> relevant = new HashSet<TypeDescription>(typeDescription.getInterfaces().asErasures()); for (TypeDescription prioritizedInterface : prioritizedInterfaces) { if (relevant.remove(prioritizedInterface)) { filtered.add(prioritizedInterface); } } return filtered; }
/** * Creates a new appender for implementing a {@link net.bytebuddy.implementation.DefaultMethodCall}. * * @param implementationTarget The implementation target of this appender. * @param prioritizedInterfaces The relevant prioritized interfaces to be considered by this appender. */ protected Appender(Target implementationTarget, List<TypeDescription> prioritizedInterfaces) { this.implementationTarget = implementationTarget; this.prioritizedInterfaces = prioritizedInterfaces; this.nonPrioritizedInterfaces = new HashSet<TypeDescription>(implementationTarget.getInstrumentedType().getInterfaces().asErasures()); nonPrioritizedInterfaces.removeAll(prioritizedInterfaces); }
/** * {@inheritDoc} */ public TypeList.Generic getInterfaces() { TypeDescription erasure = asErasure(); if (TypeDescription.AbstractBase.RAW_TYPES) { return erasure.getInterfaces(); } return new TypeList.Generic.ForDetachedTypes.WithResolvedErasure(erasure.getInterfaces(), new Visitor.ForRawType(erasure)); }
/** * Resolves a lazy interface list. * * @param delegate The delegate for which to represent interfaces. * @return A lazy list representing the delegate's interfaces lazily. */ protected static TypeList.Generic of(LazyProjection delegate) { return new LazyInterfaceList(delegate, delegate.asErasure().getInterfaces()); }
private boolean alreadyEnhanced(TypeDescription managedCtClass) { for ( TypeDescription.Generic declaredInterface : managedCtClass.getInterfaces() ) { if ( declaredInterface.asErasure().isAssignableTo( Managed.class ) ) { return true; } } return false; }
/** * {@inheritDoc} */ public TypeList.Generic getInterfaces() { return new TypeList.Generic.ForDetachedTypes.WithResolvedErasure(asErasure().getInterfaces(), new Visitor.Substitutor.ForTypeVariableBinding(this)); }
/** * Extracts the only method from a given type description which is validated for the required properties for * using the type as a proxy base type. * * @param typeDescription The type description to evaluate. * @return The only method which was found to be compatible to the proxy requirements. */ private static MethodDescription.InDefinedShape onlyMethod(TypeDescription typeDescription) { if (!typeDescription.isInterface()) { throw new IllegalArgumentException(typeDescription + " is not an interface"); } else if (!typeDescription.getInterfaces().isEmpty()) { throw new IllegalArgumentException(typeDescription + " must not extend other interfaces"); } else if (!typeDescription.isPublic()) { throw new IllegalArgumentException(typeDescription + " is not public"); } MethodList<MethodDescription.InDefinedShape> methodCandidates = typeDescription.getDeclaredMethods().filter(isAbstract()); if (methodCandidates.size() != 1) { throw new IllegalArgumentException(typeDescription + " must declare exactly one abstract method"); } return methodCandidates.getOnly(); }
/** * {@inheritDoc} */ public SpecialMethodInvocation invokeDefault(MethodDescription.SignatureToken token) { SpecialMethodInvocation specialMethodInvocation = SpecialMethodInvocation.Illegal.INSTANCE; for (TypeDescription interfaceType : instrumentedType.getInterfaces().asErasures()) { SpecialMethodInvocation invocation = invokeDefault(token, interfaceType); if (invocation.isValid()) { if (specialMethodInvocation.isValid()) { return SpecialMethodInvocation.Illegal.INSTANCE; } else { specialMethodInvocation = invocation; } } } return specialMethodInvocation; }
/** * 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 public boolean matches(TypeDescription target) { return !target.getInterfaces().asErasures().filter(isAnnotatedWith(Remote.class)).isEmpty(); } }
/** * Creates a binder by installing a single proxy type where annotating a parameter with {@link FieldProxy} allows * getting and setting values for a given field. * * @param typeDescription A type which declares exactly one abstract getter and an abstract setter for the {@link Object} * type. The type is allowed to be generic. * @return A binder for the {@link FieldProxy} annotation. */ public static TargetMethodAnnotationDrivenBinder.ParameterBinder<FieldProxy> install(TypeDescription typeDescription) { if (!typeDescription.isInterface()) { throw new IllegalArgumentException(typeDescription + " is not an interface"); } else if (!typeDescription.getInterfaces().isEmpty()) { throw new IllegalArgumentException(typeDescription + " must not extend other interfaces"); } else if (!typeDescription.isPublic()) { throw new IllegalArgumentException(typeDescription + " is not public"); } MethodList<MethodDescription.InDefinedShape> methodCandidates = typeDescription.getDeclaredMethods().filter(isAbstract()); if (methodCandidates.size() != 2) { throw new IllegalArgumentException(typeDescription + " does not declare exactly two non-abstract methods"); } MethodList<MethodDescription.InDefinedShape> getterCandidates = methodCandidates.filter(isGetter(Object.class)); if (getterCandidates.size() != 1) { throw new IllegalArgumentException(typeDescription + " does not declare a getter with an Object type"); } MethodList<MethodDescription.InDefinedShape> setterCandidates = methodCandidates.filter(isSetter(Object.class)); if (setterCandidates.size() != 1) { throw new IllegalArgumentException(typeDescription + " does not declare a setter with an Object type"); } return new Binder(typeDescription, getterCandidates.getOnly(), setterCandidates.getOnly()); }
/** * Extracts the only method of a given type and validates to fit the constraints of the morph annotation. * * @param typeDescription The type to extract the method from. * @return The only method after validation. */ private static MethodDescription onlyMethod(TypeDescription typeDescription) { if (!typeDescription.isInterface()) { throw new IllegalArgumentException(typeDescription + " is not an interface"); } else if (!typeDescription.getInterfaces().isEmpty()) { throw new IllegalArgumentException(typeDescription + " must not extend other interfaces"); } else if (!typeDescription.isPublic()) { throw new IllegalArgumentException(typeDescription + " is mot public"); } MethodList<?> methodCandidates = typeDescription.getDeclaredMethods().filter(isAbstract()); if (methodCandidates.size() != 1) { throw new IllegalArgumentException(typeDescription + " must declare exactly one abstract method"); } MethodDescription methodDescription = methodCandidates.getOnly(); if (!methodDescription.getReturnType().asErasure().represents(Object.class)) { throw new IllegalArgumentException(methodDescription + " does not return an Object-type"); } else if (methodDescription.getParameters().size() != 1 || !methodDescription.getParameters().get(0).getType().asErasure().represents(Object[].class)) { throw new IllegalArgumentException(methodDescription + " does not take a single argument of type Object[]"); } return methodDescription; }
/** * {@inheritDoc} */ public MethodDelegationBinder.ParameterBinding<?> bind(AnnotationDescription.Loadable<Default> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner, Assigner.Typing typing) { TypeDescription proxyType = TypeLocator.ForType.of(annotation.getValue(PROXY_TYPE).resolve(TypeDescription.class)).resolve(target.getType()); if (!proxyType.isInterface()) { throw new IllegalStateException(target + " uses the @Default annotation on an invalid type"); } if (source.isStatic() || !implementationTarget.getInstrumentedType().getInterfaces().asErasures().contains(proxyType)) { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } else { return new MethodDelegationBinder.ParameterBinding.Anonymous(new TypeProxy.ForDefaultMethod(proxyType, implementationTarget, annotation.getValue(SERIALIZABLE_PROXY).resolve(Boolean.class))); } }
/** * {@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); } }
/** * {@inheritDoc} */ public void apply(ClassVisitor classVisitor, TypeDescription instrumentedType, AnnotationValueFilter annotationValueFilter) { AnnotationAppender annotationAppender = new AnnotationAppender.Default(new AnnotationAppender.Target.OnType(classVisitor)); AnnotationAppender.ForTypeAnnotations.ofTypeVariable(annotationAppender, annotationValueFilter, AnnotationAppender.ForTypeAnnotations.VARIABLE_ON_TYPE, typeVariableIndex, instrumentedType.getTypeVariables()); TypeList.Generic interfaceTypes = instrumentedType.getInterfaces(); int interfaceTypeIndex = this.interfaceTypeIndex; for (TypeDescription.Generic interfaceType : interfaceTypes.subList(this.interfaceTypeIndex, interfaceTypes.size())) { annotationAppender = interfaceType.accept(AnnotationAppender.ForTypeAnnotations.ofInterfaceType(annotationAppender, annotationValueFilter, interfaceTypeIndex++)); } AnnotationList declaredAnnotations = instrumentedType.getDeclaredAnnotations(); for (AnnotationDescription annotationDescription : declaredAnnotations.subList(annotationIndex, declaredAnnotations.size())) { annotationAppender = annotationAppender.append(annotationDescription, annotationValueFilter); } } }
/** {@inheritDoc} */ public InstrumentedType.WithFlexibleName represent(TypeDescription typeDescription) { return new InstrumentedType.Default(typeDescription.getName(), typeDescription.getModifiers(), typeDescription.getSuperClass(), typeDescription.getTypeVariables().asTokenList(is(typeDescription)), typeDescription.getInterfaces().accept(Generic.Visitor.Substitutor.ForDetachment.of(typeDescription)), typeDescription.getDeclaredFields().asTokenList(is(typeDescription)), typeDescription.getDeclaredMethods().asTokenList(is(typeDescription)), typeDescription.getDeclaredAnnotations(), TypeInitializer.None.INSTANCE, LoadedTypeInitializer.NoOp.INSTANCE, typeDescription.getDeclaringType(), typeDescription.getEnclosingMethod(), typeDescription.getEnclosingType(), typeDescription.getDeclaredTypes(), typeDescription.isAnonymousType(), typeDescription.isLocalType(), typeDescription.isNestHost() ? TargetType.DESCRIPTION : typeDescription.getNestHost(), typeDescription.isNestHost() ? typeDescription.getNestMembers().filter(not(is(typeDescription))) : Collections.<TypeDescription>emptyList()); } },