Bug 526040: Merge Java 9 related changes from JDT
- fix compile errors so far
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
index 54c8a07..d243465 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
@@ -739,19 +739,34 @@
 
 			public boolean visit(IntersectionTypeBinding18 intersectionTypeBinding18) {
 				Arrays.sort(intersectionTypeBinding18.intersectingTypes, (t1, t2) -> t1.id - t2.id);
+//{ObjectTeams: respect intermediate class:
+/* orig:
 				scope.problemReporter().anonymousDiamondWithNonDenotableTypeArguments(QualifiedAllocationExpression.this.type, allocationType);
+  :giro */
+				scope.problemReporter().anonymousDiamondWithNonDenotableTypeArguments(AbstractQualifiedAllocationExpression.this.type, allocationType);
+// SH}
 				return this.noErrors = false;  // stop traversal
 			}
 			public boolean visit(TypeVariableBinding typeVariable) {
 				if (typeVariable.isCapture()) {
+//{ObjectTeams: respect intermediate class:
+/* orig:
 					scope.problemReporter().anonymousDiamondWithNonDenotableTypeArguments(QualifiedAllocationExpression.this.type, allocationType);
+  :giro */
+					scope.problemReporter().anonymousDiamondWithNonDenotableTypeArguments(AbstractQualifiedAllocationExpression.this.type, allocationType);
+// SH}
 					return this.noErrors = false;  // stop traversal
 				}
 				return true; // continue traversal
 			}
 			public boolean visit(ReferenceBinding ref) {
 				if (!ref.canBeSeenBy(scope)) {
+//{ObjectTeams: respect intermediate class:
+/* orig:
 					scope.problemReporter().invalidType(QualifiedAllocationExpression.this.anonymousType, new ProblemReferenceBinding(ref.compoundName, ref, ProblemReasons.NotVisible));
+  :giro */
+					scope.problemReporter().invalidType(AbstractQualifiedAllocationExpression.this.anonymousType, new ProblemReferenceBinding(ref.compoundName, ref, ProblemReasons.NotVisible));
+// SH}
 					return this.noErrors = false;
 				}
 				return true;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
index f4256e9..bdc8aea 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java
@@ -425,7 +425,7 @@
 	if (needFieldsAndMethods)
 		cachePartsFrom(binaryType, true);
 //{ObjectTeams: ROFI if this is a team, record the package that contains its role files.
-	maybeSetTeamPackage(this.compoundName, this.fPackage, environment);
+	maybeSetTeamPackage(this.compoundName, this.fPackage, environment, this.fPackage.enclosingModule);
 // SH}
 }
 public boolean canBeSeenBy(Scope sco) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
index 4538b87..095319d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java
@@ -815,7 +815,7 @@
 		while (i < length) {
 //{ObjectTeams: For a team with team package we need to give precedence to the type:
 			if (i == length -1) {
-				ReferenceBinding type = packageBinding.getType(compoundName[i]);
+				ReferenceBinding type = packageBinding.getType(compoundName[i], module);
 				if (type != null) {
 					if (!type.canBeSeenBy(this.fPackage))
 						return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible);
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 5b8def2..0df185b 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
@@ -365,13 +365,13 @@
 	if (answers == null)
 		return null;
 
-//{ObjectTeams: if we were looking specifically for a source type, and if this is satisfied now, reset to normal:
-	if (!answer.isBinaryType() && Config.hasConfig())
-		Config.setSourceTypeRequired(false);
-// SH}
 	ReferenceBinding candidate = null;
 	for (NameEnvironmentAnswer answer : answers) {
 		if (answer == null) continue;
+//{ObjectTeams: if we were looking specifically for a source type, and if this is satisfied now, reset to normal:
+		if (!answer.isBinaryType() && Config.hasConfig())
+			Config.setSourceTypeRequired(false);
+// SH}
 		ModuleBinding answerModule = answer.moduleBinding != null ? answer.moduleBinding : this.UnNamedModule;
 		PackageBinding answerPackage = packageBinding;
 		
@@ -674,8 +674,7 @@
 // for use by Dependiencies only:
 public int internalCompleteTypeBindings(CompilationUnitDeclaration parsedUnit) {
 	if (this != this.root) {
-		this.root.internalCompleteTypeBindings(parsedUnit);
-		return;
+		return this.root.internalCompleteTypeBindings(parsedUnit);
 	}
 	if (this.unitBeingCompleted == parsedUnit) 
 		return 0; // avoid re-entrance
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 58cba14..7e68b91 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
@@ -397,11 +397,12 @@
 		public TeamPackageBinding(
 				char[][] compoundName,
 				PackageBinding parent,
-				LookupEnvironment environment)
+				LookupEnvironment environment,
+				ModuleBinding enclosingModule)
 		{
-			super(adjustTeamPackageName(compoundName), parent, environment);
+			super(adjustTeamPackageName(compoundName), parent, environment, enclosingModule);
 			if (parent != null && parent.isValidBinding())
-				parent.addPackage(this);
+				parent.addPackage(this, enclosingModule, false); // TODO(SHMODOT): split siblings??
 		}
 	
 		/** For nested role files the compoundName may contain '$' and '__OT__' delimitors.
@@ -454,9 +455,9 @@
 						name);
 				char[][] roleCompoundName = CharOperation.arrayConcat(this.compoundName, name);
 				// TODO(SH): are all three attempts needed?
-				if (   (binding = this.environment.askForType(this.parent, roleName)) == null
-					&& (binding = this.environment.askForType(this, name)) == null
-					&& (binding = this.environment.askForType(roleCompoundName)) == null)
+				if (   (binding = this.environment.askForType(this.parent, roleName, this.enclosingModule)) == null
+					&& (binding = this.environment.askForType(this, name, this.enclosingModule)) == null
+					&& (binding = this.environment.askForType(roleCompoundName, this.enclosingModule)) == null)
 				{
 					// not found so remember a problem type binding in the cache for future lookups
 					addNotFoundType(name);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
index a7d0a93..d4255ce 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
@@ -3669,7 +3669,7 @@
 			unitScope.recordReference(currentPackage.compoundName, name);
 //{ObjectTeams: to avoid team / team package conflicts prefer types if suitable:
 			if ((mask & (Binding.TYPE | Binding.PACKAGE)) == Binding.TYPE) {
-				ReferenceBinding type = currentPackage.getType(name);
+				ReferenceBinding type = currentPackage.getType(name, module());
 				if (type != null && type.isValidBinding())
 					return type; // type is always visible to its own package
 			}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index 0ae0923..043b782 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -204,7 +204,7 @@
 	this.scope = scope;
 	this.environment = scope.environment();
 //{ObjectTeams: ROFI create a package binding for our role files (if any):
-	maybeSetTeamPackage(compoundName, fPackage, scope.environment());
+	maybeSetTeamPackage(compoundName, fPackage, scope.environment(), scope.compilationUnitScope().module());
 // SH}
 
 	// expect the fields & methods to be initialized correctly later
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index 2a66699..4c06437 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -84,7 +84,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.eclipse.jdt.core.compiler.CategorizedProblem;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AbstractOTReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AbstractOTReferenceBinding.java
index d36a115..88913ef 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AbstractOTReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AbstractOTReferenceBinding.java
@@ -31,6 +31,7 @@
 import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
 import org.eclipse.jdt.internal.compiler.lookup.PackageBinding.TeamPackageBinding;
 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
 import org.eclipse.jdt.internal.compiler.lookup.TagBits;
@@ -173,7 +174,7 @@
 	 *  Do not use a specific sub class because several subclasses of ReferenceBinding need this feature!
 	 */
 	public TeamPackageBinding teamPackage;
-	protected void maybeSetTeamPackage(char[][] compoundName, PackageBinding parentPackage, LookupEnvironment environment) {
+	protected void maybeSetTeamPackage(char[][] compoundName, PackageBinding parentPackage, LookupEnvironment environment, ModuleBinding enclosingModule) {
 		if (isTeam()) {
 			char[][] packageName;
 			char[][] segments = CharOperation.splitOn('$', compoundName[compoundName.length-1]);
@@ -187,7 +188,7 @@
 				packageName = parentPackage.compoundName;
 			}
 			if (environment.nameEnvironment.isPackage(packageName, sourceName()))
-				this.teamPackage = new TeamPackageBinding(compoundName, parentPackage, environment);
+				this.teamPackage = new TeamPackageBinding(compoundName, parentPackage, environment, enclosingModule);
 		}
 	}
 	/**