<commit_before>package org.axonframework.common.annotation;

import org.axonframework.common.Assert;
import org.axonframework.domain.Message;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;

/**
 * Abstract superclass for annotation based Message handlers. Handlers can be compared with on another to decide upon
 * their priority. Handlers that deal with unrelated payloads (i.e. have no parent-child relationship) are ordered
 * based on their payload type's class name.
 * <p/>
 * Handler invokers should always evaluate the first (smallest) suitable handler before evaluating the next.
 *
 * @author <NAME>
 * @since 2.0
 */
public abstract class AbstractMessageHandler implements Comparable<AbstractMessageHandler> {

    private final Score score;
    private final Class payloadType;
    private final ParameterResolver[] parameterValueResolvers;

    /**
     * Initializes the MessageHandler to handle messages with the given <code>payloadType</code>, declared in the given
     * <code>declaringClass</code> and using the given <code>parameterValueResolvers</code>.
     *
     * @param payloadType             The type of payload this handlers deals with
     * @param declaringClass          The class on which the handler is declared
     * @param parameterValueResolvers The resolvers for each of the handlers' parameters
     */
    protected AbstractMessageHandler(Class<?> payloadType, Class<?> declaringClass,
                                     ParameterResolver[] parameterValueResolvers) {
        score = new Score(payloadType, declaringClass);
        this.payloadType = payloadType;
        this.parameterValueResolvers = parameterValueResolvers;
    }

    /**
     * Indicates whether this Handler is suitable for the given <code>message</code>.
     *
     * @param message The message to inspect
     * @return <code>true</code> if this handler can handle the message, otherwise <code>false</code>.
     */
    public boolean matches(Message message) {
        Assert.notNull(message, "Event may not be null");
        for (ParameterResolver parameterResolver : parameterValueResolvers) {
            if (!parameterResolver.matches(message)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Invokes this handler for the given <code>target</code> instance, using the given <code>message</code> as
     * source object to provide parameter values.
     *
     * @param target  The target instance to invoke the Handler on.
     * @param message The message providing parameter values
     * @return The result of the handler invocation
     *
     * @throws InvocationTargetException when the handler throws a checked exception
     * @throws IllegalAccessException    if the SecurityManager refuses the handler invocation
     */
    public abstract Object invoke(Object target, Message message)
            throws InvocationTargetException, IllegalAccessException;

    /**
     * Returns the type of payload this handler expects.
     *
     * @return the type of payload this handler expects
     */
    public Class getPayloadType() {
        return payloadType;
    }

    @Override
    public int compareTo(AbstractMessageHandler o) {
        return score.compareTo(o.score);
    }

    /**
     * Finds ParameterResolvers for the given Member details. The returning array contains as many elements as the
     * given <code>parameterTypes</code>, where each ParameterResolver corresponds with the parameter type at the same
     * location.
     *
     * @param memberAnnotations    The annotations on the member (e.g. method)
     * @param parameterTypes       The parameter type of the member
     * @param parameterAnnotations The annotations on each of the parameters
     * @return the parameter resolvers for the given Member details
     *
     * @see java.lang.reflect.Method
     * @see java.lang.reflect.Constructor
     */
    protected static ParameterResolver[] findResolvers(Annotation[] memberAnnotations, Class<?>[] parameterTypes,
                                                       Annotation[][] parameterAnnotations) {
        int parameters = parameterTypes.length;
        ParameterResolver[] parameterValueResolvers = new ParameterResolver[parameters];
        for (int i = 0; i < parameters; i++) {
            parameterValueResolvers[i] = ParameterResolverFactory.findParameterResolver(memberAnnotations,
                                                                                        parameterTypes[i],<commit_msg>Code style<commit_after>package org.axonframework.common.annotation;

import org.axonframework.common.Assert;
import org.axonframework.domain.Message;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;

/**
 * Abstract superclass for annotation based Message handlers. Handlers can be compared with on another to decide upon
 * their priority. Handlers that deal with unrelated payloads (i.e. have no parent-child relationship) are ordered
 * based on their payload type's class name.
 * <p/>
 * Handler invokers should always evaluate the first (smallest) suitable handler before evaluating the next.
 *
 * @author <NAME>
 * @since 2.0
 */
public abstract class AbstractMessageHandler implements Comparable<AbstractMessageHandler> {

    private final Score score;
    private final Class payloadType;
    private final ParameterResolver[] parameterValueResolvers;

    /**
     * Initializes the MessageHandler to handle messages with the given <code>payloadType</code>, declared in the given
     * <code>declaringClass</code> and using the given <code>parameterValueResolvers</code>.
     *
     * @param payloadType             The type of payload this handlers deals with
     * @param declaringClass          The class on which the handler is declared
     * @param parameterValueResolvers The resolvers for each of the handlers' parameters
     */
    protected AbstractMessageHandler(Class<?> payloadType, Class<?> declaringClass,
                                     ParameterResolver[] parameterValueResolvers) {
        score = new Score(payloadType, declaringClass);
        this.payloadType = payloadType;
        this.parameterValueResolvers = parameterValueResolvers;
    }

    /**
     * Indicates whether this Handler is suitable for the given <code>message</code>.
     *
     * @param message The message to inspect
     * @return <code>true</code> if this handler can handle the message, otherwise <code>false</code>.
     */
    public boolean matches(Message message) {
        Assert.notNull(message, "Event may not be null");
        for (ParameterResolver parameterResolver : parameterValueResolvers) {
            if (!parameterResolver.matches(message)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Invokes this handler for the given <code>target</code> instance, using the given <code>message</code> as
     * source object to provide parameter values.
     *
     * @param target  The target instance to invoke the Handler on.
     * @param message The message providing parameter values
     * @return The result of the handler invocation
     *
     * @throws InvocationTargetException when the handler throws a checked exception
     * @throws IllegalAccessException    if the SecurityManager refuses the handler invocation
     */
    public abstract Object invoke(Object target, Message message)
            throws InvocationTargetException, IllegalAccessException;

    /**
     * Returns the type of payload this handler expects.
     *
     * @return the type of payload this handler expects
     */
    public Class getPayloadType() {
        return payloadType;
    }

    @Override
    public int compareTo(AbstractMessageHandler o) {
        return score.compareTo(o.score);
    }

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof AbstractMessageHandler)
                && ((AbstractMessageHandler) obj).score.equals(score);
    }

    /**
     * Finds ParameterResolvers for the given Member details. The returning array contains as many elements as the
     * given <code>parameterTypes</code>, where each ParameterResolver corresponds with the parameter type at the same
     * location.
     *
     * @param memberAnnotations    The annotations on the member (e.g. method)
     * @param parameterTypes       The parameter type of the member
     * @param parameterAnnotations The annotations on each of the parameters
     * @return the parameter resolvers for the given Member details
     *
     * @see java.lang.reflect.Method
     * @see java.lang.reflect.Constructor
     */
    protected static ParameterResolver[] findResolvers(Annotation[] memberAnnotations, Class<?>[] parameterTypes,
                                                       Annotation[][] parameterAnnotations) {
        int parameters = parameterTypes.length;
        ParameterResolver[] parameterValueResolvers = new ParameterResolver[parameters];
        for (int i = 0; i < parameters; i++) {
            parameterValueResolvers[i] = ParameterResolverFactory.findParameterResolver(memberAnnotations,
                                                                                        parameterTypes[i],
{'fraction_non_alphanumeric': 0.07104643697838647, 'fraction_numerical': 0.0006419858763107211, 'mean_word_length': 2.819779321618308, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1922405', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2114, 'n_words': 795}