/** * Creates a {@link net.bytebuddy.implementation.DefaultMethodCall} implementation which searches the given list * of interface types for a suitable default method in their order. If no such prioritized interface is suitable, * because it is either not defined on the instrumented type or because it does not define a suitable default method, * any remaining interface is searched for a suitable default method. If no or more than one method defines a * suitable default method, an exception is thrown. * * @param prioritizedInterfaces A list of prioritized default method interfaces in their prioritization order. * @return An implementation which calls an instrumented method's compatible default method that considers the given * interfaces to be prioritized in their order. */ public static Implementation prioritize(Iterable<? extends Class<?>> prioritizedInterfaces) { List<Class<?>> list = new ArrayList<Class<?>>(); for (Class<?> prioritizedInterface : prioritizedInterfaces) { list.add(prioritizedInterface); } return prioritize(new TypeList.ForLoadedTypes(list)); }
@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; } }
/** * Creates a method handles representation of a loaded method handle which is analyzed using the given lookup context. * A method handle can only be analyzed on virtual machines that support the corresponding API (Java 7+). For virtual machines before Java 8+, * a method handle instance can only be analyzed by taking advantage of private APIs what might require a access context. * * @param methodHandle The loaded method handle to represent. * @param lookup The lookup object to use for analyzing the method handle. * @return A representation of the loaded method handle */ public static MethodHandle ofLoaded(Object methodHandle, Object lookup) { if (!JavaType.METHOD_HANDLE.getTypeStub().isInstance(methodHandle)) { throw new IllegalArgumentException("Expected method handle object: " + methodHandle); } else if (!JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isInstance(lookup)) { throw new IllegalArgumentException("Expected method handle lookup object: " + lookup); } Dispatcher dispatcher = DISPATCHER.initialize(); Object methodHandleInfo = dispatcher.reveal(lookup, methodHandle); Object methodType = dispatcher.getMethodType(methodHandleInfo); return new MethodHandle(HandleType.of(dispatcher.getReferenceKind(methodHandleInfo)), TypeDescription.ForLoadedType.of(dispatcher.getDeclaringClass(methodHandleInfo)), dispatcher.getName(methodHandleInfo), TypeDescription.ForLoadedType.of(dispatcher.returnType(methodType)), new TypeList.ForLoadedTypes(dispatcher.parameterArray(methodType))); }
@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; } }
/** * Creates a {@link net.bytebuddy.implementation.DefaultMethodCall} implementation which searches the given list * of interface types for a suitable default method in their order. If no such prioritized interface is suitable, * because it is either not defined on the instrumented type or because it does not define a suitable default method, * any remaining interface is searched for a suitable default method. If no or more than one method defines a * suitable default method, an exception is thrown. * * @param prioritizedInterface A list of prioritized default method interfaces in their prioritization order. * @return An implementation which calls an instrumented method's compatible default method that considers the given * interfaces to be prioritized in their order. */ public static Implementation prioritize(Class<?>... prioritizedInterface) { return prioritize(new TypeList.ForLoadedTypes(prioritizedInterface)); }
/** * Returns a method type description of the given return type and parameter types. * * @param returnType The return type to represent. * @param parameterType The parameter types to represent. * @return A method type of the given return type and parameter types. */ public static MethodType of(Class<?> returnType, Class<?>... parameterType) { return of(TypeDescription.ForLoadedType.of(returnType), new TypeList.ForLoadedTypes(parameterType)); }
/** * {@inheritDoc} */ public TypeList asErasures() { return new TypeList.ForLoadedTypes(method.getExceptionTypes()); }
/** * {@inheritDoc} */ public TypeList asErasures() { return new TypeList.ForLoadedTypes(type.getInterfaces()); }
/** * {@inheritDoc} */ public Builder<S> nestMembers(List<? extends Class<?>> types) { return nestMembers(new TypeList.ForLoadedTypes(types)); }
/** * {@inheritDoc} */ public Builder<S> declaredTypes(List<? extends Class<?>> type) { return declaredTypes(new TypeList.ForLoadedTypes(type)); }
/** * {@inheritDoc} */ public TypeList getDeclaredTypes() { return new TypeList.ForLoadedTypes(type.getDeclaredClasses()); }
/** * Matches an iteration of generic types' erasures against the provided types. As a wildcard does not define an erasure, a runtime * exception is thrown when this matcher is applied to a wildcard. * * @param type The types to match. * @param <T> The type of the matched object. * @return A matcher that matches an iteration of generic types' raw types against the provided non-generic types. */ public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> erasures(Class<?>... type) { return erasures(new TypeList.ForLoadedTypes(type)); }
/** * {@inheritDoc} */ public TypeList getNestMembers() { return new TypeList.ForLoadedTypes(DISPATCHER.getNestMembers(type)); }
/** * {@inheritDoc} */ public TypeList asErasures() { return new TypeList.ForLoadedTypes(constructor.getExceptionTypes()); }
/** * Passes {@code null} values of the given types to the bootstrapped method. * * @param type The type that the {@code null} values should represent. * @return This invoke dynamic implementation where the bootstrapped method is passed the specified arguments. */ public InvokeDynamic withNullValue(Class<?>... type) { return withNullValue(new TypeList.ForLoadedTypes(type).toArray(new TypeDescription[type.length])); }
/** * Passes references to {@code this} onto the operand stack where the instance is represented as * the given types. * * @param type The types as which the {@code this} reference of the intercepted method should be masked. * @return This implementation where {@code this} references are passed as the next arguments. */ public InvokeDynamic withThis(Class<?>... type) { return withThis(new TypeList.ForLoadedTypes(type).toArray(new TypeDescription[type.length])); }
/** * Returns a builder with the additional type array property. * * @param property The name of the property to define. * @param type The types that should be contained by the array. * @return A builder with the additional type array property. */ public Builder defineTypeArray(String property, Class<?>... type) { return defineTypeArray(property, new TypeList.ForLoadedTypes(type).toArray(new TypeDescription[type.length])); }