Bug 429012 - [1.8][search] Add finegrain (limitTo) option for method reference expressions
Summary: [1.8][search] Add finegrain (limitTo) option for method reference expressions
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 431488
  Show dependency tree
 
Reported: 2014-02-25 09:28 EST by Markus Keller CLA
Modified: 2014-04-29 04:43 EDT (History)
3 users (show)

See Also:
daniel_megert: pmc_approved+
srikanth_sankaran: review+
markus.kell.r: review+


Attachments
Proposed Patch (14.15 KB, patch)
2014-03-26 12:02 EDT, Manoj N Palat CLA
no flags Details | Diff
Proposed Patch (32.06 KB, patch)
2014-04-19 08:02 EDT, Manoj N Palat CLA
no flags Details | Diff
Proposed Patch - part 2 (8.39 KB, patch)
2014-04-25 04:09 EDT, Manoj N Palat CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2014-02-25 09:28:07 EST
The search engine should support a new 'limitTo' option in IJavaSearchConstants to limit matches to Java-8-style method reference expressions.

E.g. only one reference to Integer#toHexString(int) should be found in this code when the flag is set:

	Function<Integer, String> hexer= Integer::toHexString; // yep
	System.out.println(hexer.apply(666));
	System.out.println(Integer.toHexString(666)); // nope
Comment 1 Markus Keller CLA 2014-03-14 06:19:54 EDT
This would be good to have for 4.4
Comment 2 Srikanth Sankaran CLA 2014-03-21 11:03:17 EDT
Please co-ordinate with the UI team for UI updates,
Comment 3 Srikanth Sankaran CLA 2014-03-25 23:03:39 EDT
Manoj, this is requested by the UI team. Please work on this for M7
Comment 4 Manoj N Palat CLA 2014-03-26 12:02:51 EDT
Created attachment 241272 [details]
Proposed Patch
Comment 5 Srikanth Sankaran CLA 2014-04-14 04:36:30 EDT
Dani, would we get approval for this API change coming in at M7 ? Otherwise we
will have to move this out to 4.5. IMO, this is not critical, but Markus may
differ.

Manoj, please post the relevant portions of the API change including javadocs
and such so people can form an informed judgement. Thanks.
Comment 6 Manoj N Palat CLA 2014-04-14 19:04:08 EDT
/**
 * Return only Java 8 style method references, ie A::foo.
 * <p>
 * When this flag is set, only {@link MethodReferenceMatch} which are 
 * java 8 method references will be returned.
 *</p>
 * @since 3.10
 * @category limitTo
 */
int JAVA8_METHOD_REFERENCE = 0x10000000;

This is the new category that is added to the search pattern. Strictly from an API point of view, there are no additional methods that are requested for. Would we need an approval for this?
Comment 7 Dani Megert CLA 2014-04-15 07:24:52 EDT
(In reply to Manoj Palat from comment #6)
> /**
>  * Return only Java 8 style method references, ie A::foo.
>  * <p>
>  * When this flag is set, only {@link MethodReferenceMatch} which are 
>  * java 8 method references will be returned.
     ^
==> Java


> This is the new category that is added to the search pattern. Strictly from
> an API point of view, there are no additional methods that are requested
> for. Would we need an approval for this?

Any API changed needs approval after M6 (API freeze).
Comment 8 Srikanth Sankaran CLA 2014-04-16 02:31:53 EDT
Here are some comments after a quick glance through the patch - I didn't
review it yet:

    - It appears there aren't any tests that show only method references
being selected and presented while other types of references to the target
method are filtered ? 

   - Include tests for different flavors of reference expressions. e.g:
constructor references don't feature in the tests at all ? 

   - JAVA8_METHOD_REFERENCE - I am not we should encode version number
in the API ? did you see a precedence and chose this ?
Comment 9 Markus Keller CLA 2014-04-16 12:51:38 EDT
Let's use this API:

/**
 * Return only method reference expressions, e.g. <code>A::foo</code>.
 * <p>
 * When this flag is set, only {@link MethodReferenceMatch} matches will be
 * returned.
 *</p>
 * @since 3.10
 * @category limitTo
 */
int METHOD_REFERENCE_EXPRESSION = 0x10000000;

I agree the Java version shouldn't be part of the API name. The obvious "METHOD_REFERENCE" would indeed be problematic, since "reference" is already widely used. But the full name from JLS8 15.13 should work.
Comment 10 Manoj N Palat CLA 2014-04-19 08:02:18 EDT
Created attachment 242142 [details]
Proposed Patch

- Thanks Srikanth and Markus for the suggestions - incorporated the same, and made current to the latest ToT. 
- API modified to as mentioned in comment 9
Comment 11 Srikanth Sankaran CLA 2014-04-24 02:29:41 EDT
Patch looks good to me.
Comment 13 Markus Keller CLA 2014-04-24 13:18:11 EDT
Hmm, was too quick. The example for a constructor reference expression in org.eclipse.jdt.core.tests.model.JavaSearchBugs8Tests#testBug429012_0015() has various compile errors and doesn't test the interesting case where other matches could show up (but shouldn't). Here's a better example:

import java.util.function.Supplier;

/**
 * @see Y#Y()
 */
public class X  {
    public static void main(String [] args) {
        Supplier<Y<String>> s = Y<String>::<Integer>new;
        s.get().equals(new Y<String>()); 
    }
}
class Y<E> {
    <T> Y() {
        System.out.println("Y<E>::<T>new");
    }
}

However, I somehow don't get any search result if I change the test to use this one.
Comment 14 Manoj N Palat CLA 2014-04-25 04:09:35 EDT
Created attachment 242311 [details]
Proposed Patch - part 2

Thanks Markus. Here is the proposed patch with the following additions:
- incorporated Markus' testcase plus the solution for the issue.
- Additional modifications done to test cases to show explicit filtering.
Comment 15 Markus Keller CLA 2014-04-25 06:36:47 EDT
(In reply to Manoj Palat from comment #14)
> Created attachment 242311 [details] [diff]
> Proposed Patch - part 2

Looks good and works fine.
Comment 16 Manoj N Palat CLA 2014-04-25 09:39:43 EDT
(In reply to Markus Keller from comment #15)
> Looks good and works fine.
Markus: Thanks for the review.

Committed via : http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=bf2199048d434ee8a7461950468d3a2335a30990
Comment 17 Jay Arthanareeswaran CLA 2014-04-29 04:43:06 EDT
Verified for 4.4 M7 with build I20140428-2000