All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.co.probablyfine.matchers.function.DescribableFunction Maven / Gradle / Ivy

The newest version!
package uk.co.probablyfine.matchers.function;

import java.lang.invoke.MethodType;
import java.lang.invoke.SerializedLambda;
import java.util.function.Function;

import static uk.co.probablyfine.matchers.internal.DescriptionUtils.withPrefixedArticle;

@FunctionalInterface
public interface DescribableFunction extends Function, SerializedLambdaResolvable, SingleArgumentDescribableFunctionalInterface {

    default String getResultDescription() {
        SerializedLambda lambda = asSerializedLambda();
        MethodType lambdaMethodType = MethodType.fromMethodDescriptorString(lambda.getImplMethodSignature(), getClass().getClassLoader());
        String resultType = lambdaMethodType.returnType().getSimpleName();
        if (! lambda.getImplMethodName().startsWith("lambda$")) {
            return lambda.getImplMethodName() + " (" + withPrefixedArticle(resultType) + ")";
        }
        return resultType;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy