Fix for Bug 461025 [1.8][search] Search for constructor reference
expressions reports other constructors also
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
index 9df7ed8..f780f76 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
@@ -4638,6 +4638,47 @@
}
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=461025
+//[1.8][search] Constructor reference not found in search
+public void testBug461025_001() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
+ "@FunctionalInterface\n" +
+ "interface Y<T> {\n" +
+ " T get();\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " public X() {}\n" +
+ " public X(int i) {}\n" +
+ "\n" +
+ " private void m1() {\n" +
+ " Y<X> s1 = X::new;\n" +
+ "\n" +
+ " Y<X> s2 = new Y<X>() {\n" +
+ "\n" +
+ " @Override\n" +
+ " public X get() {\n" +
+ " return null;\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}\n");
+SearchPattern pattern = SearchPattern.createPattern(
+ "*",
+ CONSTRUCTOR,
+ METHOD_REFERENCE_EXPRESSION,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/X.java void X.m1() [X::new] EXACT_MATCH"
+);
+}
+
// Add new tests in JavaSearchBugs8Tests
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java
index a234f40..fb6d3fb 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.internal.compiler.ast.*;
@@ -44,6 +45,7 @@
return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
}
public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) {
+ if (this.pattern.fineGrain != 0 && !this.pattern.findDeclarations) return IMPOSSIBLE_MATCH;
int referencesLevel = this.pattern.findReferences ? matchLevelForReferences(node) : IMPOSSIBLE_MATCH;
int declarationsLevel = this.pattern.findDeclarations ? matchLevelForDeclarations(node) : IMPOSSIBLE_MATCH;
@@ -100,6 +102,10 @@
public int match(TypeDeclaration node, MatchingNodeSet nodeSet) {
if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
+ if (this.pattern.fineGrain != 0 &&
+ (this.pattern.fineGrain & ~IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION) == 0 )
+ return IMPOSSIBLE_MATCH;
+
// need to look for a generated default constructor
return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
}