Skip to content

Commit 4cfcabe

Browse files
authored
Skip import quickfix hierarchy check if base type is unresolved (eclipse-jdt#2120)
The commit 546a697 extended the import check to compare the interfaces of the suggested types with the interface of the missing type. In case the base type is unresolved, this then skips all suggestions, even though it should let all pass so that the user can decide which one to pick. Fixes eclipse-jdt#2119
1 parent 86514e9 commit 4cfcabe

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsBaseSubProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ private void addSimilarTypeProposals(int kind, ICompilationUnit cu, Name node, i
10071007
if ((elem.getKind() & TypeKinds.ALL_TYPES) != 0) {
10081008
String fullName= elem.getName();
10091009
if (!fullName.equals(resolvedTypeName)) {
1010-
if (simpleBinding != null && !simpleBinding.isPrimitive()) {
1010+
if (simpleBinding != null && !simpleBinding.isPrimitive() && !simpleBinding.isRecovered()) {
10111011
// If we have an expected type, we should verify that any classes we suggest to import
10121012
// inherit directly or indirectly from the type
10131013
ITypeBinding qualifiedTypeBinding= null;

org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,6 +18,7 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Hashtable;
21+
import java.util.List;
2122

2223
import org.junit.After;
2324
import org.junit.Before;
@@ -1788,4 +1789,58 @@ public void foo() {
17881789

17891790
assertExpectedExistInProposals(proposals, expected);
17901791
}
1792+
1793+
@Test
1794+
public void testIssue2119() throws Exception {
1795+
IPackageFragment other = fSourceFolder.createPackageFragment("other", false, null);
1796+
String source1 = """
1797+
package other;
1798+
public interface IPath {}
1799+
""";
1800+
String source2 = """
1801+
package other;
1802+
public class Path implements IPath {}
1803+
""";
1804+
other.createCompilationUnit("IPath.java", source1, false, null);
1805+
other.createCompilationUnit("Path.java", source2, false, null);
1806+
IPackageFragment test= fSourceFolder.createPackageFragment("test", false, null);
1807+
String source = """
1808+
package test;
1809+
class Test {
1810+
private IPath p = new Path();
1811+
}
1812+
""";
1813+
ICompilationUnit cu = test.createCompilationUnit("Test.java", source, false, null);
1814+
CompilationUnit astRoot = getASTRoot(cu);
1815+
1816+
// import java.util.List
1817+
List<IJavaCompletionProposal> proposals1 = collectCorrections(cu, astRoot, 2, 0);
1818+
assertCorrectLabels(proposals1);
1819+
String[] expected1 = new String[1];
1820+
expected1[0] = """
1821+
package test;
1822+
1823+
import other.IPath;
1824+
1825+
class Test {
1826+
private IPath p = new Path();
1827+
}
1828+
""";
1829+
assertExpectedExistInProposals(proposals1, expected1);
1830+
1831+
// import java.util.ArrayList
1832+
List<IJavaCompletionProposal> proposals2 = collectCorrections(cu, astRoot, 2, 1);
1833+
assertCorrectLabels(proposals2);
1834+
String[] expected2 = new String[1];
1835+
expected2[0] = """
1836+
package test;
1837+
1838+
import other.Path;
1839+
1840+
class Test {
1841+
private IPath p = new Path();
1842+
}
1843+
""";
1844+
assertExpectedExistInProposals(proposals2, expected2);
1845+
}
17911846
}

0 commit comments

Comments
 (0)