Bug 526917 - Allow all indexing to complete before query starts

getJavaElementMatches is doing a Java search - via
the OpenFromClipboardAction.

The SearchEngine tests which have some similar functionality all wait
for the index before trying to do the search. See most of the tests under
org.eclipse.jdt.core.tests.model.AbstractJavaSearchTests.
Code like one of these patterns is common:
1)
 IndexManager indexManager = JavaModelManager.getIndexManager();
 indexManager.indexAll(project.getProject());
 waitUntilIndexesReady();
2)
 JavaModelManager.getIndexManager().waitForIndex(false, null);
3)
 refresh(project);
 waitForAutoBuild();
 waitUntilIndexesReady();

By adding the waitForIndex it is hoped the flaky test becomes stable.

Change-Id: Ic31ed2e5dc9d5541e49f455c87b04bdf7f1e1f7b
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/192113
Tested-by: Sarika Sinha <sarika.sinha@in.ibm.com>
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Reviewed-by: Sarika Sinha <sarika.sinha@in.ibm.com>
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java
index 83fff3f..9e3300e 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/OpenFromClipboardTests.java
@@ -30,6 +30,7 @@
 import org.eclipse.jdt.debug.testplugin.JavaProjectHelper;
 import org.eclipse.jdt.debug.tests.TestAgainException;
 import org.eclipse.jdt.debug.tests.TestUtil;
+import org.eclipse.jdt.internal.core.JavaModelManager;
 import org.eclipse.jdt.internal.debug.ui.actions.OpenFromClipboardAction;
 import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.JavaRuntime;
@@ -140,6 +141,7 @@
 	}
 
 	private List<?> getJavaElementMatches(final String textData) {
+		JavaModelManager.getIndexManager().waitForIndex(false, null);
 		final List<?> matches = new ArrayList<>();
 		Display.getDefault().syncExec(new Runnable() {
 			@Override