Bug 521287: [9] Follow up bugs for code select

Change-Id: Id23ecf2d14c20e29013139bbc937e58962221b4a
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
index 576851c..e755fc2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java
@@ -1413,7 +1413,7 @@
 		return null;
 
 	for (int i = 1, packageLength = compoundName.length - 1; i < packageLength; i++)
-		if ((packageBinding = packageBinding.getPackage0(compoundName[i])) == null || packageBinding == TheNotFoundPackage)
+		if ((packageBinding = packageBinding.getPackage0Any(compoundName[i])) == null || packageBinding == TheNotFoundPackage)
 			return null;
 	return packageBinding.getType0(compoundName[compoundName.length - 1]);
 }
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java
index afad980..c4c02ef 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java
@@ -146,17 +146,25 @@
 	addNotFoundPackage(name);
 	return null;
 }
-/* Answer the subpackage named name if it exists in the cache.
+/** Answer the subpackage named name if it exists in the cache.
 * Answer theNotFoundPackage if it could not be resolved the first time
 * it was looked up, otherwise answer null.
-*
+* <p>
+* NOTE: The returned package binding is guaranteed to be complete wrt. SplitPackageBinding,
+* or, if no complete binding is yet available, we shyly answer null.
+* </p><p>
 * NOTE: Senders must convert theNotFoundPackage into a real problem
-* package if its to returned.
+* package if its to returned.</p>
 */
-
 PackageBinding getPackage0(char[] name) {
 	return this.knownPackages.get(name);
 }
+/** Variant (see {@link #getPackage0(char[])}), that may even answer an incompletely
+ *  combined package (in the case of SplitPackageBinding).
+ */
+PackageBinding getPackage0Any(char[] name) {
+	return this.knownPackages.get(name);
+}
 /* Answer the type named name; ask the oracle for the type if its not in the cache.
 * Answer a NotVisible problem type if the type is not visible from the invocationPackage.
 * Answer null if it could not be resolved.
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java
index 672b638..eca945d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SplitPackageBinding.java
@@ -142,6 +142,23 @@
 	}
 
 	@Override
+	PackageBinding getPackage0Any(char[] name) {
+		PackageBinding knownPackage = super.getPackage0(name);
+		if (knownPackage != null)
+			return knownPackage;
+
+		PackageBinding candidate = null;
+		for (PackageBinding incarnation : this.incarnations) {
+			PackageBinding package0 = incarnation.getPackage0(name);
+			if (package0 == null)
+				continue;
+			candidate = combine(package0, candidate, this.enclosingModule);
+		}
+		// don't cache the result, maybe incomplete
+		return candidate;
+	}
+
+	@Override
 	protected PackageBinding findPackage(char[] name, ModuleBinding module) {
 		Set<PackageBinding> candidates = new HashSet<>();
 		for (ModuleBinding candidateModule : this.declaringModules) {