View | Details | Raw Unified | Return to bug 429012 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java (+109 lines)
Lines 37-42 Link Here
37
import org.eclipse.jdt.internal.core.JavaModelManager;
37
import org.eclipse.jdt.internal.core.JavaModelManager;
38
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
38
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
39
import org.eclipse.jdt.internal.core.search.matching.AndPattern;
39
import org.eclipse.jdt.internal.core.search.matching.AndPattern;
40
import org.eclipse.jdt.internal.core.search.matching.MethodPattern;
40
41
41
/**
42
/**
42
 * Non-regression tests for bugs fixed in Java Search engine.
43
 * Non-regression tests for bugs fixed in Java Search engine.
Lines 160-165 Link Here
160
	suite.addTest(new JavaSearchBugs8Tests("test430159b"));
161
	suite.addTest(new JavaSearchBugs8Tests("test430159b"));
161
	suite.addTest(new JavaSearchBugs8Tests("test430159c"));
162
	suite.addTest(new JavaSearchBugs8Tests("test430159c"));
162
	suite.addTest(new JavaSearchBugs8Tests("test430159d"));
163
	suite.addTest(new JavaSearchBugs8Tests("test430159d"));
164
	suite.addTest(new JavaSearchBugs8Tests("testBug429012_001"));
165
	suite.addTest(new JavaSearchBugs8Tests("testBug429012_002"));
166
	suite.addTest(new JavaSearchBugs8Tests("testBug429012_003"));
167
	suite.addTest(new JavaSearchBugs8Tests("testBug429012_004"));
163
	return suite;
168
	return suite;
164
}
169
}
165
class TestCollector extends JavaSearchResultCollector {
170
class TestCollector extends JavaSearchResultCollector {
Lines 3770-3775 Link Here
3770
	assertSearchResults(""
3775
	assertSearchResults(""
3771
	);
3776
	);
3772
}
3777
}
3778
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions
3779
public void testBug429012_001() throws CoreException {
3780
	this.workingCopies = new ICompilationUnit[1];
3781
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b429498/X.java",
3782
			"interface I {\n" +
3783
			"	public void doit();\n" +
3784
			"}\n" +
3785
			"public class X {\n" +
3786
			"   static void foo() {}\n" +
3787
			"   static void foo(int i) {}\n" +
3788
			"	I i = X :: foo;\n" +
3789
			"}\n"
3790
	);
3791
	String str = this.workingCopies[0].getSource();
3792
	String selection = "foo";
3793
	int start = str.indexOf(selection);
3794
	int length = selection.length();
3795
3796
	IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
3797
	MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], JAVA8_METHOD_REFERENCE, ERASURE_RULE);
3798
3799
	new SearchEngine(this.workingCopies).search(pattern,
3800
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
3801
			getJavaSearchWorkingCopiesScope(),
3802
			this.resultCollector,
3803
			null);
3804
	assertSearchResults(
3805
		"src/b429498/X.java b429498.X.i [X :: foo] EXACT_MATCH"
3806
	);
3807
}
3808
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions
3809
public void testBug429012_002() throws CoreException {
3810
	this.workingCopies = new ICompilationUnit[1];
3811
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java",
3812
			"interface I { \n" +
3813
			"	int thrice(int p);\n" +
3814
			"}\n" +
3815
			"class Y {\n" +
3816
			"	int goo(int x) { return 3 * x; } \n" +
3817
			"}\n" +
3818
			"public class X extends Y {\n" +
3819
			"	public void main(String[] args) { \n" +
3820
			"		I i = this::goo;\n" +
3821
			"       i = super::goo;\n" +
3822
			"	}\n" +
3823
			"}\n"
3824
	);
3825
3826
	search(this.workingCopies[0].getType("Y").getMethod("goo", new String[] { "I" }), JAVA8_METHOD_REFERENCE);
3827
	assertSearchResults(
3828
		"src/test/Test.java void test.X.main(String[]) [this::goo] EXACT_MATCH\n" + 
3829
		"src/test/Test.java void test.X.main(String[]) [super::goo] EXACT_MATCH"
3830
	);
3831
}
3832
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions
3833
public void testBug429012_003() throws CoreException {
3834
	this.workingCopies = new ICompilationUnit[1];
3835
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java",
3836
			"interface I { \n" +
3837
			"	int thrice(int p);\n" +
3838
			"}\n" +
3839
			"class Y {\n" +
3840
			"	int goo(int x) { return 3 * x; } \n" +
3841
			"}\n" +
3842
			"public class X extends Y {\n" +
3843
			"	public void main(String[] args) { \n" +
3844
			"		I i = this::goo;\n" +
3845
			"       i = super::goo;\n" +
3846
			"	}\n" +
3847
			"}\n"
3848
	);
3849
3850
	search(this.workingCopies[0].getType("Y").getMethod("goo", new String[] { "I" }), THIS_REFERENCE | JAVA8_METHOD_REFERENCE);
3851
	assertSearchResults(
3852
		"src/test/Test.java void test.X.main(String[]) [this::goo] EXACT_MATCH\n" +
3853
		"src/test/Test.java void test.X.main(String[]) [super::goo] EXACT_MATCH"
3854
	);
3855
}
3856
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=429012, [1.8][search] Add finegrain (limitTo) option for method reference expressions
3857
public void testBug429012_004() throws CoreException {
3858
	this.workingCopies = new ICompilationUnit[1];
3859
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java",
3860
			"interface I { \n" +
3861
			"	int thrice(int p);\n" +
3862
			"}\n" +
3863
			"class Y {\n" +
3864
			"	static class Z {\n" +
3865
			"		static int goo(int x) { return 3 * x; }   \n" +
3866
			"		I i = Z::goo;\n" +
3867
			"   }\n" +
3868
			"}\n" +
3869
			"public class X extends Y.Z {\n" +
3870
			"	public void main(String[] args) { \n" +
3871
			"		I i = Y.Z::goo;\n" +
3872
			"	}\n" +
3873
			"}\n"
3874
	);
3875
3876
	search(this.workingCopies[0].getType("Y").getType("Z").getMethod("goo", new String[] { "I" }), JAVA8_METHOD_REFERENCE);
3877
	assertSearchResults(
3878
		"src/test/Test.java test.Y$Z.i [Z::goo] EXACT_MATCH\n" + 
3879
		"src/test/Test.java void test.X.main(String[]) [Y.Z::goo] EXACT_MATCH"
3880
);
3881
}
3773
// Add new tests in JavaSearchBugs8Tests
3882
// Add new tests in JavaSearchBugs8Tests
3774
}
3883
}
3775
3884
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1050-1056 Link Here
1050
		"QUALIFIED_REFERENCE | " +
1050
		"QUALIFIED_REFERENCE | " +
1051
		"THIS_REFERENCE | " +
1051
		"THIS_REFERENCE | " +
1052
		"IMPLICIT_THIS_REFERENCE | " +
1052
		"IMPLICIT_THIS_REFERENCE | " +
1053
		" | " + // unused slots
1053
		"JAVA8_METHOD_REFERENCE | " + // unused slots
1054
		" | " +
1054
		" | " +
1055
		" | ",
1055
		" | ",
1056
		searchPattern);
1056
		searchPattern);
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 466-471 Link Here
466
	 */
466
	 */
467
	int IMPLICIT_THIS_REFERENCE = 0x8000000;
467
	int IMPLICIT_THIS_REFERENCE = 0x8000000;
468
468
469
	/**
470
	 * Return only Java 8 style method references, ie A::foo.
471
	 * <p>
472
	 * When this flag is set, only {@link MethodReferenceMatch} which are 
473
	 * java 8 method references will be returned.
474
	 *</p>
475
	 * @since 3.10
476
	 * @category limitTo
477
	 */
478
	int JAVA8_METHOD_REFERENCE = 0x10000000;
479
469
	/* Syntactic match modes */
480
	/* Syntactic match modes */
470
481
471
	/**
482
	/**
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchPattern.java (-2 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1544-1549 Link Here
1544
 *     			<tr>
1544
 *     			<tr>
1545
 *         		<td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE}
1545
 *         		<td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE}
1546
 *         		<td>Return only field accesses or method invocations without any qualification.
1546
 *         		<td>Return only field accesses or method invocations without any qualification.
1547
 *				<tr>
1548
 *         		<td>{@link IJavaSearchConstants#JAVA8_METHOD_REFERENCE JAVA8_METHOD_REFERENCE}
1549
 *         		<td>Return only Java 8 method references (e.g. <code>A :: foo</code>).
1547
 * 			</table>
1550
 * 			</table>
1548
 *		</li>
1551
 *		</li>
1549
 *	</ul>
1552
 *	</ul>
Lines 1721-1727 Link Here
1721
 *     			<tr>
1724
 *     			<tr>
1722
 *         		<td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE}
1725
 *         		<td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE}
1723
 *         		<td>Return only field accesses or method invocations without any qualification.
1726
 *         		<td>Return only field accesses or method invocations without any qualification.
1724
 * 			</table>
1727
*				<tr>
1728
 *         		<td>{@link IJavaSearchConstants#JAVA8_METHOD_REFERENCE JAVA8_METHOD_REFERENCE}
1729
 *         		<td>Return only Java 8 method references (e.g. <code>A :: foo</code>).
1730
* 			</table>
1725
 *		</li>
1731
 *		</li>
1726
 *	</ul>
1732
 *	</ul>
1727
 * @return a search pattern for a Java element or <code>null</code> if the given element is ill-formed
1733
 * @return a search pattern for a Java element or <code>null</code> if the given element is ill-formed
Lines 1830-1835 Link Here
1830
 *     			<tr>
1836
 *     			<tr>
1831
 *         		<td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE}
1837
 *         		<td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE}
1832
 *         		<td>Return only field accesses or method invocations without any qualification.
1838
 *         		<td>Return only field accesses or method invocations without any qualification.
1839
 *     			<tr>
1840
 *         		<td>{@link IJavaSearchConstants#JAVA8_METHOD_REFERENCE JAVA8_METHOD_REFERENCE}
1841
 *         		<td>Return only Java 8 method references (e.g. <code>A :: foo</code>).
1842
 *     			<tr>
1833
 * 			</table>
1843
 * 			</table>
1834
 * 	</li>
1844
 * 	</li>
1835
 *	</ul>
1845
 *	</ul>
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorPattern.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 52-58 Link Here
52
	IJavaSearchConstants.SUPER_REFERENCE |
52
	IJavaSearchConstants.SUPER_REFERENCE |
53
	IJavaSearchConstants.QUALIFIED_REFERENCE |
53
	IJavaSearchConstants.QUALIFIED_REFERENCE |
54
	IJavaSearchConstants.THIS_REFERENCE |
54
	IJavaSearchConstants.THIS_REFERENCE |
55
	IJavaSearchConstants.IMPLICIT_THIS_REFERENCE;
55
	IJavaSearchConstants.IMPLICIT_THIS_REFERENCE |
56
	IJavaSearchConstants.JAVA8_METHOD_REFERENCE;
56
57
57
58
58
/**
59
/**
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchPattern.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
2
 * Copyright (c) 2004, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 157-162 Link Here
157
				case IJavaSearchConstants.IMPLICIT_THIS_REFERENCE:
157
				case IJavaSearchConstants.IMPLICIT_THIS_REFERENCE:
158
					buffer.append("IMPLICIT_THIS_REFERENCE"); //$NON-NLS-1$
158
					buffer.append("IMPLICIT_THIS_REFERENCE"); //$NON-NLS-1$
159
					break;
159
					break;
160
				case IJavaSearchConstants.JAVA8_METHOD_REFERENCE:
161
					buffer.append("JAVA8_METHOD_REFERENCE"); //$NON-NLS-1$
162
					break;
160
			}
163
			}
161
		}
164
		}
162
		return buffer.toString();
165
		return buffer.toString();
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java (+2 lines)
Lines 524-529 Link Here
524
	super.consumeReferenceExpression(referenceExpression);
524
	super.consumeReferenceExpression(referenceExpression);
525
	if (this.patternFineGrain == 0) {
525
	if (this.patternFineGrain == 0) {
526
		this.patternLocator.match(referenceExpression, this.nodeSet);
526
		this.patternLocator.match(referenceExpression, this.nodeSet);
527
	} else if ((this.patternFineGrain & IJavaSearchConstants.JAVA8_METHOD_REFERENCE) != 0) {
528
		this.patternLocator.match(referenceExpression, this.nodeSet);
527
	} else if (referenceExpression.lhs.isThis()) {
529
	} else if (referenceExpression.lhs.isThis()) {
528
		if ((this.patternFineGrain & IJavaSearchConstants.THIS_REFERENCE) != 0) {
530
		if ((this.patternFineGrain & IJavaSearchConstants.THIS_REFERENCE) != 0) {
529
			this.patternLocator.match(referenceExpression, this.nodeSet);
531
			this.patternLocator.match(referenceExpression, this.nodeSet);
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 56-62 Link Here
56
	IJavaSearchConstants.SUPER_REFERENCE |
56
	IJavaSearchConstants.SUPER_REFERENCE |
57
	IJavaSearchConstants.QUALIFIED_REFERENCE |
57
	IJavaSearchConstants.QUALIFIED_REFERENCE |
58
	IJavaSearchConstants.THIS_REFERENCE |
58
	IJavaSearchConstants.THIS_REFERENCE |
59
	IJavaSearchConstants.IMPLICIT_THIS_REFERENCE;
59
	IJavaSearchConstants.IMPLICIT_THIS_REFERENCE |
60
	IJavaSearchConstants.JAVA8_METHOD_REFERENCE;
60
61
61
/**
62
/**
62
 * Method entries are encoded as selector '/' Arity:
63
 * Method entries are encoded as selector '/' Arity:

Return to bug 429012