Skip to content

Commit f0ac4be

Browse files
committed
Streamline compile error resolution proposals and strengthen typing
1 parent 8de0b27 commit f0ac4be

File tree

4 files changed

+130
-198
lines changed

4 files changed

+130
-198
lines changed

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/FindClassResolutionsOperation.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2008, 2019 IBM Corporation and others.
2+
* Copyright (c) 2008, 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
@@ -41,6 +41,7 @@
4141
import org.eclipse.jdt.core.search.SearchParticipant;
4242
import org.eclipse.jdt.core.search.SearchPattern;
4343
import org.eclipse.jdt.core.search.SearchRequestor;
44+
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
4445
import org.eclipse.jface.operation.IRunnableWithProgress;
4546
import org.eclipse.osgi.service.resolver.BundleDescription;
4647
import org.eclipse.osgi.service.resolver.BundleSpecification;
@@ -59,9 +60,9 @@
5960
*/
6061
public class FindClassResolutionsOperation implements IRunnableWithProgress {
6162

62-
String fClassName = null;
63-
IProject fProject = null;
64-
AbstractClassResolutionCollector fCollector = null;
63+
private String fClassName = null;
64+
private IProject fProject = null;
65+
private AbstractClassResolutionCollector fCollector = null;
6566
private CompilationUnit fCompilationUnit;
6667

6768
/**
@@ -78,7 +79,9 @@ public static abstract class AbstractClassResolutionCollector {
7879
* Import-Package. The proposals can be created with the help of the
7980
* JavaResolutionFactory
8081
*/
81-
abstract public void addResolutionModification(IProject project, ExportPackageDescription desc);
82+
public void addResolutionModification(IProject project, ExportPackageDescription desc) {
83+
addResolutionModification(project, desc, null, ""); //$NON-NLS-1$
84+
}
8285

8386
/**
8487
* This method is meant to be sub-classed. The subclass should decide if
@@ -93,11 +96,15 @@ abstract public void addResolutionModification(IProject project, ExportPackageDe
9396
* Adds an export package proposal. Subclasses should implement the
9497
* actual adding to the collection.
9598
*/
96-
public Object addExportPackageResolutionModification(IPackageFragment aPackage) {
99+
public IJavaCompletionProposal addExportPackageResolutionModification(IPackageFragment aPackage) {
97100
if (aPackage.exists()) {
101+
// TODO: try (and check null inbetween)
102+
// aPackage.getJavaProject().getProject();
98103
IResource packageResource = aPackage.getResource();
99104
if (packageResource != null) {
100-
return JavaResolutionFactory.createExportPackageProposal(packageResource.getProject(), aPackage, JavaResolutionFactory.TYPE_JAVA_COMPLETION, 100);
105+
IProject project = packageResource.getProject();
106+
var change = JavaResolutionFactory.createExportPackageChange(project, aPackage);
107+
return JavaResolutionFactory.createJavaCompletionProposal(change, 100);
101108
}
102109
}
103110
return null;
@@ -114,13 +121,16 @@ public Object addRequireBundleModification(IProject project, ExportPackageDescri
114121
* Adds a require bundle proposal. Subclasses should implement the
115122
* actual adding to the collection.
116123
*/
117-
public Object addRequireBundleModification(IProject project, ExportPackageDescription desc, int relevance,
118-
CompilationUnit cu, String qualifiedTypeToImport) {
119-
return JavaResolutionFactory.createRequireBundleProposal(project, desc,
120-
JavaResolutionFactory.TYPE_JAVA_COMPLETION, relevance, cu, qualifiedTypeToImport);
124+
public IJavaCompletionProposal addRequireBundleModification(IProject project, ExportPackageDescription desc,
125+
int relevance, CompilationUnit cu, String qualifiedTypeToImport) {
126+
BundleDescription exporter = desc.getExporter();
127+
if (exporter == null) {
128+
return null;
129+
}
130+
var change = JavaResolutionFactory.createRequireBundleChange(project, exporter, cu, qualifiedTypeToImport);
131+
return JavaResolutionFactory.createJavaCompletionProposal(change, relevance);
121132
}
122133

123-
124134
/**
125135
* Adds a search repositories proposal. Subclasses should implement the actual adding to the collection.
126136
*/

0 commit comments

Comments
 (0)