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

[Java8, Kotlin Java8] Support java 8 method references #1140

Merged
merged 2 commits into from
Jun 14, 2017

Conversation

mpkorstanje
Copy link
Contributor

Summary

The ConstantPoolTypeIntrospector did not know how to handle references to an instance method of an arbitrary object of a particular type and Kotlin lambda expression without arguments or closure variables. This lead to issues:

Details

Updated the ConstantPoolTypeIntrospector to check for instance methods by counting the parameters expected by the interface and those bound to the anonymous class. Only iff this is an instance method the result will come up one short.

Resolved Kotlin specific problems by checking if the reference method equals the magic constant "INSTANCE".

How Has This Been Tested?

Extended examples in features to include kotlin and all 4 types of method references.

Still awaiting confirmation from:

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@mpkorstanje mpkorstanje changed the title Support java 8 method references [Java8, Kotlin Java 8] Support java 8 method references Jun 3, 2017
@mpkorstanje mpkorstanje changed the title [Java8, Kotlin Java 8] Support java 8 method references [Java8, Kotlin Java8] Support java 8 method references Jun 3, 2017
The implementation of t he `ConstantPoolTypeIntrospector` supported:
 - Reference to a static method
 - Reference to an instance method of a particular object
 - Reference to a constructor

 But did not support:
  - Reference to an instance method of an arbitrary object of a particular type

Referencing instances methods would result in an index out of bounds exception
as  the step definition interface was expecting exactly 1 more argument then
was bound to the body. We now use this discrepancy to detect if this is an
instance method reference and include the the instance class as the first type.

Related issues:
 - #1123
 - #1126

 This fixes #1126
@mpkorstanje mpkorstanje force-pushed the feature/support-java-8-method-references branch 7 times, most recently from 168bdb3 to 762cafb Compare June 14, 2017 22:13
The implementation of t he `ConstantPoolTypeIntrospector` did not fully
support closures.

Using a closure without  scoped variables would result
in a null pointer exception.  E.g:

```java
Given("^A statement with a body expression$") { assertTrue(true) }
```

 This is resolved check if the member reference method equals the magic
 constant "INSTANCE" and return no type arguments.

Related issues:
 - #1123
 - #1126

 This fixes #1123
@mpkorstanje mpkorstanje force-pushed the feature/support-java-8-method-references branch from 762cafb to cd515d3 Compare June 14, 2017 23:07
@mpkorstanje mpkorstanje merged commit aa4c9a0 into master Jun 14, 2017
@mpkorstanje mpkorstanje deleted the feature/support-java-8-method-references branch June 14, 2017 23:08
mpkorstanje added a commit that referenced this pull request Jul 14, 2017
mpkorstanje added a commit that referenced this pull request Jul 14, 2017
mpkorstanje added a commit that referenced this pull request Jul 14, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140
 -
mpkorstanje added a commit that referenced this pull request Jul 14, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140
mpkorstanje added a commit that referenced this pull request Jul 14, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140
mpkorstanje added a commit that referenced this pull request Jul 14, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140

Closes #937
mpkorstanje added a commit that referenced this pull request Jul 15, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140

Closes #937
Closes #1048
mpkorstanje added a commit that referenced this pull request Jul 23, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140

Closes #937
Closes #1048
mpkorstanje added a commit that referenced this pull request Jul 29, 2017
To determine which argument types a lambda function requires we created a
 ConstantPoolTypeIntrospector. However it has never functioned quite correctly
 (#937, #1140, #957), was prone to breaking (#912, #914) and hasn't been tested
 much (#1048).

It is important to understand that while we will get a properly functioning and
 tested replacement, TypeResolver uses the same ConstantPool and thus has the
 same potential to break. However because TypeResolver is used by a much larger
 audience I expect these problems to be shallow.

Because this change the interface of Java8StepDefinition it made sense to
 refactor all the Java8 related stuff out of cucumber-java. This will make it easier in
 the future to add things like KotlinStepDefintions without creating a separate
 KotlinBackend.

Related issues:
 - #912
 - #914
 - #937
 - #957
 - #1140
 - #1048
 - #1140

Closes #937
Closes #1048
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant