Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) Flux Capacitor IP B.V. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fluxcapacitor.common.handling;
import io.fluxcapacitor.common.reflection.DefaultMemberInvoker;
import io.fluxcapacitor.common.reflection.MemberInvoker;
import io.fluxcapacitor.common.reflection.ReflectionUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.SneakyThrows;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;
import static io.fluxcapacitor.common.handling.HandlerInspector.MethodHandlerMatcher.comparator;
import static io.fluxcapacitor.common.reflection.ReflectionUtils.ensureAccessible;
import static io.fluxcapacitor.common.reflection.ReflectionUtils.getAllMethods;
import static java.util.Arrays.stream;
import static java.util.Comparator.reverseOrder;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Stream.concat;
public class HandlerInspector {
public static boolean hasHandlerMethods(Class> targetClass,
HandlerConfiguration> handlerConfiguration) {
return concat(getAllMethods(targetClass).stream(), stream(targetClass.getConstructors()))
.anyMatch(m -> handlerConfiguration.methodMatches(targetClass, m));
}
public static Handler createHandler(Object target, Class extends Annotation> methodAnnotation) {
return createHandler(target, methodAnnotation, List.of((p, a) -> o -> o));
}
public static Handler createHandler(Object target, Class extends Annotation> methodAnnotation,
List> parameterResolvers) {
return createHandler(target, parameterResolvers,
HandlerConfiguration.builder().methodAnnotation(methodAnnotation).build());
}
public static Handler createHandler(Object target, List> parameterResolvers,
HandlerConfiguration super M> config) {
return createHandler(m -> target, target.getClass(), parameterResolvers, config);
}
public static Handler createHandler(Function targetSupplier, Class> targetClass,
List> parameterResolvers,
HandlerConfiguration super M> config) {
return new DefaultHandler<>(targetClass, targetSupplier, inspect(targetClass, parameterResolvers, config));
}
public static HandlerMatcher