Bug 560606 - Avoiding extra semicolons in import type declarations does
not work in modular context

Change-Id: I9d9a5df97a84555635dbadb48514da95da6432ce
diff --git a/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
index 851e327..d89498d 100644
--- a/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.core.tests.model;singleton:=true
-Bundle-Version: 3.10.1100.qualifier
+Bundle-Version: 3.10.1200.qualifier
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Export-Package: org.eclipse.jdt.core.tests,
diff --git a/org.eclipse.jdt.core.tests.model/pom.xml b/org.eclipse.jdt.core.tests.model/pom.xml
index c4ba6a5..c2cd4c9 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -20,7 +20,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.core.tests.model</artifactId>
-  <version>3.10.1100-SNAPSHOT</version>
+  <version>3.10.1200-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
index 3dbfe28..bd0dbec 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016, 2019 IBM Corporation and others.
+ * Copyright (c) 2016, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -1624,4 +1624,26 @@
 		deleteProject(project1);
 	}
 }
+public void testBug560606() throws CoreException {
+	IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL19_LIB", "org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, "bin", "9");
+	try  {
+		project1.open(null);
+		createFile("/Completion9_1/src/module-info.java",
+				"module first {}\n");
+
+		CompletionResult result = complete(
+	            "/Completion9_1/src/bug560606/Test.java",
+	            "package bug560606;\n" +
+	            "import java.util.Coll;\n" +
+	            "public class Test {\n" +
+	            "}\n",
+	            "import java.util.Coll");
+
+	    assertResults(
+	            "Collection[TYPE_REF]{Collection, java.util, Ljava.util.Collection;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED)+"}",
+	            result.proposals);
+	} finally {
+		deleteProject(project1);
+	}
+}
 }
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index f1fbccd..be8a27c 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -1667,13 +1667,22 @@
 	}
 	
 	private char[] appendUnlessNextToken(char[] completionName, char[] suffix, int nextToken) {
-		this.parser.scanner.resetTo(this.endPosition, Integer.MAX_VALUE);
+		if (this.source == null)
+			return CharOperation.concat(completionName, suffix);
+
+		AssistParser assistParser = getParser();
+		Object parserState = assistParser.becomeSimpleParser();
+
+		assistParser.scanner.setSource(this.source);
+		assistParser.scanner.resetTo(this.endPosition, Integer.MAX_VALUE);
 		try {
-			if (this.parser.scanner.getNextToken() != nextToken) {
+			if (assistParser.scanner.getNextToken() != nextToken) {
 				return CharOperation.concat(completionName, suffix);
 			}
 		} catch (InvalidInputException e) {
 			// ignore
+		} finally {
+			assistParser.restoreAssistParser(parserState);
 		}
 		return completionName;
 	}
@@ -2059,7 +2068,8 @@
 			this.actualCompletionPosition = completionPosition - 1;
 			this.offset = pos;
 			this.typeRoot = root;
-			
+			this.source = sourceUnit.getContents();
+
 			this.checkCancel();
 			
 			// for now until we can change the UI.
@@ -2259,7 +2269,6 @@
 						this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
 
 						if ((this.unitScope = parsedUnit.scope) != null) {
-							this.source = sourceUnit.getContents();
 							this.lookupEnvironment.completeTypeBindings(parsedUnit, true);
 							parsedUnit.scope.faultInTypes();
 							parseBlockStatements(parsedUnit, this.actualCompletionPosition);