
uk.co.probablyfine.matchers.function.DescribableFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-8-matchers Show documentation
Show all versions of java-8-matchers Show documentation
Hamcrest matchers for JDK8's Optionals and Streams, and the java.time package
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