Bug 519460 - Allow JDIDebugTarget implementations to filter types from
HCR

Simply moved the (previously private) methods from
JavaHotCodeReplaceManager to JDIDebugTarget. Renamed filterUnloadedTypes
to filterNotLoadedTypes to make more clear what the method is doing.

Change-Id: Ie9dbdae2cede4a1a9fc8b0dfe93d061e98237f60
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java
index ef7576a..040360f 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java
@@ -331,39 +331,6 @@
 	}
 
 	/**
-	 * Filters elements out of the given collections of resources and qualified
-	 * names if there is no type corresponding type loaded in the given debug
-	 * target. This method allows us to avoid bogus HCR attempts and
-	 * "HCR failed" notifications.
-	 *
-	 * @param target
-	 *            the debug target
-	 * @param resources
-	 *            the list of resources to filter
-	 * @param qualifiedNames
-	 *            the list of qualified names to filter, which corresponds to
-	 *            the list of resources on a one-to-one-basis
-	 */
-	private void filterUnloadedTypes(JDIDebugTarget target, List<IResource> resources,
-			List<String> qualifiedNames) {
-		for (int i = 0, numElements = qualifiedNames.size(); i < numElements; i++) {
-			String name = qualifiedNames.get(i);
-			List<ReferenceType> list = target.jdiClassesByName(name);
-			if (list.isEmpty()) {
-				// If no classes with the given name are loaded in the VM, don't
-				// waste
-				// cycles trying to replace.
-				qualifiedNames.remove(i);
-				resources.remove(i);
-				// Decrement the index and number of elements to compensate for
-				// item removal
-				i--;
-				numElements--;
-			}
-		}
-	}
-
-	/**
 	 * Notify the given targets that HCR failed for classes with the given fully
 	 * qualified names.
 	 */
@@ -379,8 +346,7 @@
 				// unloaded types on a per-target basis.
 				List<IResource> resourcesToReplace = new ArrayList<>(resources);
 				List<String> qualifiedNamesToReplace = new ArrayList<>(qualifiedNames);
-				filterUnloadedTypes(target, resourcesToReplace,
-						qualifiedNamesToReplace);
+				target.filterNotLoadedTypes(resourcesToReplace, qualifiedNamesToReplace);
 
 				if (!qualifiedNamesToReplace.isEmpty()) {
 					// Don't notify if the changed types aren't loaded.
@@ -471,13 +437,13 @@
 			List<String> qualifiedNamesToReplace = new ArrayList<>(qualifiedNames);
 
 			// Make sure we only try to replace types from related projects
-			filterUnrelatedResources(target, resourcesToReplace, qualifiedNamesToReplace);
+			target.filterUnrelatedResources(resourcesToReplace, qualifiedNamesToReplace);
 			if (qualifiedNamesToReplace.isEmpty()) {
 				// If none of the changed types are related to our target, do nothing.
 				continue;
 			}
 
-			filterUnloadedTypes(target, resourcesToReplace, qualifiedNamesToReplace);
+			target.filterNotLoadedTypes(resourcesToReplace, qualifiedNamesToReplace);
 			if (qualifiedNamesToReplace.isEmpty()) {
 				// If none of the changed types are loaded, do nothing.
 				continue;
@@ -548,18 +514,6 @@
 		fDeltaCache.clear();
 	}
 
-	private void filterUnrelatedResources(JDIDebugTarget target, List<IResource> resourcesToReplace, List<String> qualifiedNamesToReplace) {
-		Iterator<IResource> resources = resourcesToReplace.iterator();
-		Iterator<String> names = qualifiedNamesToReplace.iterator();
-		while (resources.hasNext()) {
-			boolean supported = target.supportsResource(() -> names.next(), resources.next());
-			if (!supported) {
-				resources.remove();
-				names.remove();
-			}
-		}
-	}
-
 	/**
 	 * Returns whether the given exception, which occurred during HCR, should be
 	 * logged. We anticipate that we can get IncompatibleThreadStateExceptions
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java
index f76bac1..01ae84a 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java
@@ -3339,4 +3339,51 @@
 	public ListenerList<IJavaHotCodeReplaceListener> getHotCodeReplaceListeners() {
 		return fHCRListeners;
 	}
+
+	/**
+	 * Filters elements out of the given collections of resources and qualified names if there is no related resources in the given debug target. This
+	 * method allows us to avoid bogus HCR attempts and "HCR failed" notifications.
+	 *
+	 * @param resourcesToFilter
+	 *            the list of resources to filter
+	 * @param qualifiedNamesToFilter
+	 *            the list of qualified names to filter, which corresponds to the list of resources on a one-to-one-basis
+	 */
+	public void filterUnrelatedResources(List<IResource> resourcesToFilter, List<String> qualifiedNamesToFilter) {
+		Iterator<IResource> resources = resourcesToFilter.iterator();
+		Iterator<String> names = qualifiedNamesToFilter.iterator();
+		while (resources.hasNext()) {
+			boolean supported = supportsResource(() -> names.next(), resources.next());
+			if (!supported) {
+				resources.remove();
+				names.remove();
+			}
+		}
+	}
+
+	/**
+	 * Filters elements out of the given collections of resources and qualified names if there is no type corresponding type loaded in the given debug
+	 * target. This method allows us to avoid bogus HCR attempts and "HCR failed" notifications.
+	 *
+	 * @param resources
+	 *            the list of resources to filter
+	 * @param qualifiedNames
+	 *            the list of qualified names to filter, which corresponds to the list of resources on a one-to-one-basis
+	 */
+	public void filterNotLoadedTypes(List<IResource> resources, List<String> qualifiedNames) {
+		for (int i = 0, numElements = qualifiedNames.size(); i < numElements; i++) {
+			String name = qualifiedNames.get(i);
+			List<ReferenceType> list = jdiClassesByName(name);
+			if (list.isEmpty()) {
+				// If no classes with the given name are loaded in the VM, don't
+				// waste cycles trying to replace.
+				qualifiedNames.remove(i);
+				resources.remove(i);
+				// Decrement the index and number of elements to compensate for
+				// item removal
+				i--;
+				numElements--;
+			}
+		}
+	}
 }