Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer feature name for method references in hasFeature #6

Open
markhobson opened this issue Jul 24, 2015 · 2 comments
Open

Infer feature name for method references in hasFeature #6

markhobson opened this issue Jul 24, 2015 · 2 comments

Comments

@markhobson
Copy link
Owner

When using ComposeMatchers.hasFeature(Function, Matcher) the feature name defaults to the string representation of the supplied function. For method references this results in something unwieldy like the following:

org.hobsoft.hamcrest.compose.demo.Main$$Lambda$1/424058530@31befd9f

Ideally we would infer the method name from the method reference and use that instead. Furthermore we could translate method names to English property names, e.g. getFirstName to first name.

@markhobson
Copy link
Owner Author

Java currently has no official mechanism of obtaining the method name from a method reference. I'm aware of two possible workarounds:

  1. Invoke the method reference function with a spy proxy to obtain the function name. The proxy can be created with CGLib and Objenesis but the problem is determining the proxy's superclass from the method reference. This would either need to be supplied to hasFeature (making this method less convenient) or be obtained in a non-portable way from the bytecode by using a library such as TypeTools.
  2. Use SerializedLambda to obtain the method reference name. This is reliant on lambda's being serializable which they aren't by default. The type intersection required to make a serializable lambda would again make this approach less convenient.

Neither of these approaches seem suitable but I'm open to ideas.

@markhobson
Copy link
Owner Author

#21 addresses inferring the method reference name.

Remaining task is to derive a friendly name from the method name, e.g. first name from getFirstName.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant