From 9ecc34bf838eae50a356b20c76d35fb62a423563 Mon Sep 17 00:00:00 2001
From: Stephan Herrmann
Date: Tue, 18 Jun 2019 16:28:49 +0200
Subject: Bug 548211 - "Remove" in the Module dependencies tab does not remove
system modules
- more fixes, concerning update on Apply and re-open with only java.base
Change-Id: I39a7a1da6c8ae733010009372fd36a88814e4faf
---
.../ui/wizards/buildpaths/BuildPathsBlock.java | 3 +++
.../ui/wizards/buildpaths/CPListElement.java | 24 +++++++++++++++-------
.../wizards/buildpaths/ModuleDependenciesPage.java | 13 ++++++++++++
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java
index 3fec77d579..37229a834b 100644
--- a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java
+++ b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java
@@ -395,6 +395,9 @@ public class BuildPathsBlock {
}
protected void doUpdateUI() {
+ if (fModulesPage.needReInit()) {
+ init(fCurrJProject, null, null); // extent of system modules was changed, re-init fClassPathList
+ }
fBuildPathDialogField.refresh();
fClassPathList.refresh();
boolean is9OrHigherAfter= JavaModelUtil.is9OrHigher(fCurrJProject);
diff --git a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java
index a3c475e7ea..c670c0770f 100644
--- a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java
+++ b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java
@@ -42,6 +42,7 @@ import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.provisional.JavaModelAccess;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
@@ -207,13 +208,22 @@ public class CPListElement {
boolean modulesAdded= false;
if (containerEntry != null) {
IPackageFragmentRoot[] fragmentRoots= fProject.findPackageFragmentRoots(containerEntry);
- if (fragmentRoots != null && fragmentRoots.length > 1) {
- for (IPackageFragmentRoot fragmentRoot : fragmentRoots) {
- IModuleDescription currModule= fragmentRoot.getModuleDescription();
- if (currModule != null) {
- CPListElement curr= create(this, pseudoEntry, currModule, true, fProject);
- fChildren.add(curr);
- modulesAdded= true;
+ if (fragmentRoots != null) {
+ // detect if system library:
+ boolean addChildren= false;
+ if (fragmentRoots.length > 0) {
+ IModuleDescription module= fragmentRoots[0].getModuleDescription();
+ if (module != null && JavaModelAccess.isSystemModule(module))
+ addChildren= true;
+ }
+ if (addChildren) {
+ for (IPackageFragmentRoot fragmentRoot : fragmentRoots) {
+ IModuleDescription currModule= fragmentRoot.getModuleDescription();
+ if (currModule != null) {
+ CPListElement curr= create(this, pseudoEntry, currModule, true, fProject);
+ fChildren.add(curr);
+ modulesAdded= true;
+ }
}
}
}
diff --git a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java
index b813d22956..e9f1c9feff 100644
--- a/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java
+++ b/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/ModuleDependenciesPage.java
@@ -164,6 +164,7 @@ public class ModuleDependenciesPage extends BuildPathBasePage {
private Collection<String> fAllDefaultSystemModules; // if current is unnamed module: transitive closure of default root modules (names)
public final Map<String,String> fPatchMap= new HashMap<>();
+ private boolean needReInit= false;
public ModuleDependenciesPage(IStatusChangeListener context, CheckedListDialogField<CPListElement> classPathList) {
fClassPathList= classPathList;
@@ -530,6 +531,7 @@ public class ModuleDependenciesPage extends BuildPathBasePage {
}
updateLimitModules(cpListElement.findAttributeElement(CPListElement.MODULE));
fModuleList.refresh();
+ this.needReInit= true;
}
public void addToSystemModules(List<IModuleDescription> modulesToAdd) throws JavaModelException {
@@ -655,8 +657,19 @@ public class ModuleDependenciesPage extends BuildPathBasePage {
}
}
}
+ this.needReInit= true;
}
+ /** Destructively reed the needReInit flag.
+ * @return {@code true} if the classpath needs to be reinitialized due to change of extent of the system library
+ */
+ public boolean needReInit() {
+ try {
+ return this.needReInit;
+ } finally {
+ this.needReInit= false;
+ }
+ }
private Set<String> computeForwardClosure(List<String> seeds) {
Set<String> closure= new HashSet<>();
collectForwardClosure(seeds, closure);
--
cgit v1.2.1