Bug 390146 - [compiler] Better support outer & inner teams adapting
different bundles
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index aac3dc2..303a95b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -809,7 +809,7 @@
 
 1201308 = Illegal base import: this package is not provided by the declared base plug-in(s) {0} (OT/Equinox).
 1201309 = Illegal base import: this package is not provided by the declared base plug-in {0} but by plug-in {1} (OT/Equinox).
-1201310 = Illegal base import: no aspect binding declared for team {0} (OT/Equinox).
+1201310 = Illegal base import: no aspect binding declared for team {0} or any nested team (OT/Equinox).
 1201311 = Decapsulating base class {0} by means of a forced export. Note, that additionally a corresponing declaration is needed in config.ini (OTJLD 2.1.2(c) + OT/Equinox).
 1201312 = This messages should never be seen ({0}).
 1201313 = The forced-exported type {0} cannot be accessed other than as a role's base class (OT/Equinox).
diff --git a/plugins/org.eclipse.objectteams.otdt.compiler.adaptor/src/org/eclipse/objectteams/otdt/internal/compiler/adaptor/BaseImportChecker.java b/plugins/org.eclipse.objectteams.otdt.compiler.adaptor/src/org/eclipse/objectteams/otdt/internal/compiler/adaptor/BaseImportChecker.java
index c34505e..d5b7984 100644
--- a/plugins/org.eclipse.objectteams.otdt.compiler.adaptor/src/org/eclipse/objectteams/otdt/internal/compiler/adaptor/BaseImportChecker.java
+++ b/plugins/org.eclipse.objectteams.otdt.compiler.adaptor/src/org/eclipse/objectteams/otdt/internal/compiler/adaptor/BaseImportChecker.java
@@ -19,8 +19,11 @@
  **********************************************************************/
 package org.eclipse.objectteams.otdt.internal.compiler.adaptor;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import org.eclipse.jdt.core.Flags;
@@ -150,13 +153,21 @@
 			if (location instanceof ImportReference) {
 				ImportReference imp= (ImportReference)location;
 				if (imp.isBase()) {
-					String teamName= getReferenceTeam();
-					if (teamName == null) 
+					List<String> teamNames= getReferenceTeams();
+					if (teamNames.isEmpty()) {
 						baseImportInRegularClass(getPublicType(), imp);
+						return false;
+					}
 					
-					Set<String> basePlugins= aspectBindingReader.getBasePlugins(teamName);
-					if (basePlugins == null || basePlugins.isEmpty()) {
-						illegalBaseImportNoAspectBinding(imp, teamName);
+					Set<String> basePlugins= new HashSet<String>();
+					for (String teamName : teamNames) {
+						Set<String> currentBasePlugins = aspectBindingReader.getBasePlugins(teamName);
+						if (currentBasePlugins != null && !currentBasePlugins.isEmpty())
+							basePlugins.addAll(currentBasePlugins);
+					}
+					
+					if (basePlugins.isEmpty()) {
+						illegalBaseImportNoAspectBinding(imp, teamNames.isEmpty() ? null : teamNames.get(0));
 						return false;
 					}
 					String baseString = flattenSet(basePlugins);
@@ -165,14 +176,16 @@
 					if (rule.aspectBindingData != null) {
 						for (Object data : rule.aspectBindingData) {
 							AdaptedBaseBundle info= (AdaptedBaseBundle) data;
-							if (info.isAdaptedBy(teamName)) {
-								// OK, no error
-								if (info.hasPackageSplit) {
-									ReferenceContext contextSave = getReferenceContext();
-									baseImportFromSplitPackage(imp, baseString); // just a warning
-									setReferenceContext(contextSave);
+							for (String teamName : teamNames) {
+								if (info.isAdaptedBy(teamName)) {
+									// OK, no error
+									if (info.hasPackageSplit) {
+										ReferenceContext contextSave = getReferenceContext();
+										baseImportFromSplitPackage(imp, baseString); // just a warning
+										setReferenceContext(contextSave);
+									}
+									return true;
 								}
-								return true;
 							}
 							actualBases.add(info.getSymbolicName());
 						}
@@ -212,11 +225,20 @@
 			}
 			return DecapsulationState.NONE;
 		}
-		private String getReferenceTeam() {
+		private List<String> getReferenceTeams() {
 			TypeDeclaration type= getPublicType();
-			if (type != null && type.isTeam())
-				return new String(type.binding.readableName());
-			return null;
+			if (type != null && type.isTeam()) {
+				List<String> names = new ArrayList<String>();
+				addTeamNames(type.binding, names);
+				return names;
+			}
+			return Collections.emptyList();
+		}
+		private void addTeamNames(ReferenceBinding type, List<String> names) {
+			names.add(String.valueOf(type.readableName()));
+			for (ReferenceBinding member : type.memberTypes())
+				if (member != null && member.isTeam())
+					addTeamNames(member, names);
 		}
 		private TypeDeclaration getPublicType() {
 			ReferenceContext context= getReferenceContext();
diff --git a/testplugins/org.eclipse.objectteams.otdt.test.builder/src/org/eclipse/objectteams/otdt/test/builder/OTEquinoxBuilderTests.java b/testplugins/org.eclipse.objectteams.otdt.test.builder/src/org/eclipse/objectteams/otdt/test/builder/OTEquinoxBuilderTests.java
index 56d1b8e..cf6b323 100644
--- a/testplugins/org.eclipse.objectteams.otdt.test.builder/src/org/eclipse/objectteams/otdt/test/builder/OTEquinoxBuilderTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.test.builder/src/org/eclipse/objectteams/otdt/test/builder/OTEquinoxBuilderTests.java
@@ -180,7 +180,7 @@
 		fullBuild();
 		expectingNoProblemsFor(trac18b.getPath());
 		expectingOnlySpecificProblemsFor(aspectPlugin.getPath(), new Problem[] {
-			new Problem("", "Illegal base import: no aspect binding declared for team MissingAspectBindingTeam (OT/Equinox).",
+			new Problem("", "Illegal base import: no aspect binding declared for team MissingAspectBindingTeam or any nested team (OT/Equinox).",
 						aspectPlugin.getPath().append(new Path("src/MissingAspectBindingTeam.java")),
 						12, 34,
 						CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_ERROR)