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