Bug 409075 - [compiler] base constructor call fails to resolve to role
of an outer enclosing team
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseAllocationExpression.java
index b432684..aedfb7d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseAllocationExpression.java
@@ -159,10 +159,15 @@
 		        	receiver = gen.qualifiedNameReference(tokens);
 	        	}
         	} else {
-        		if (this.enclosingInstance != null)
-        			receiver= this.enclosingInstance;
-        		else
-        			receiver = gen.thisReference(); // creating a role of the same team as base instance??
+        		if (this.enclosingInstance != null) {
+					receiver= this.enclosingInstance;
+				}
+				else {
+					if (baseclass.enclosingType() == enclType.enclosingType())
+						receiver = gen.thisReference(); // creating a role of the same team as base instance??
+					else
+						receiver = gen.qualifiedThisReference(gen.typeReference(baseclass.enclosingType()));
+				}
         	}
             char[] selector = CharOperation.concat(CREATOR_PREFIX_NAME, baseclass.sourceName());
 
diff --git a/releng/map/otdt.map.in b/releng/map/otdt.map.in
index ffba79d..96443a2 100644
--- a/releng/map/otdt.map.in
+++ b/releng/map/otdt.map.in
@@ -3,11 +3,11 @@
 !-- Don't set version numbers for features, otherwise pdebuild would complain about a non-existent Basedir: -- 

 feature@org.eclipse.objectteams.otdt=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=features/org.eclipse.objectteams.otdt.feature

 feature@org.eclipse.objectteams.otdt.source.feature=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=features/org.eclipse.objectteams.otdt.source.feature

-feature@org.eclipse.objectteams.otdt.core.patch=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=features/org.eclipse.objectteams.otdt.core.patch,tag=builds/201305210612

+feature@org.eclipse.objectteams.otdt.core.patch=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=features/org.eclipse.objectteams.otdt.core.patch

 feature@org.eclipse.objectteams.otequinox=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=features/org.eclipse.objectteams.otequinox.feature,tag=builds/201305210612

 

 !-- Also don't use version numbers for those plugins that hold the various otre jars: --

-plugin@org.eclipse.jdt.core,3.9.0.v_OTDT_r220_qualifier=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=org.eclipse.jdt.core,tag=builds/201305210612

+plugin@org.eclipse.jdt.core,3.9.0.v_OTDT_r220_qualifier=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=org.eclipse.jdt.core

 

 !next plug-in don't specify version so that org.eclipse.objectteams.runtime/customBuildCallbacks.xml will find the plug-in directory:

 plugin@org.eclipse.objectteams.otdt=GIT,repo=git://git.eclipse.org/gitroot/objectteams/org.eclipse.objectteams.git,path=plugins/org.eclipse.objectteams.otdt,tag=builds/201305210612

diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AllTests.java
index 4114362..cecec70 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AllTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AllTests.java
@@ -34,6 +34,7 @@
 import org.eclipse.objectteams.otdt.tests.otjld.other.Misc;
 import org.eclipse.objectteams.otdt.tests.otjld.other.Modifiers;
 import org.eclipse.objectteams.otdt.tests.otjld.regression.CompilationOrder;
+import org.eclipse.objectteams.otdt.tests.otjld.regression.ComplexStructures;
 import org.eclipse.objectteams.otdt.tests.otjld.regression.DevelopmentExamples;
 import org.eclipse.objectteams.otdt.tests.otjld.regression.ReportedBugs;
 import org.eclipse.objectteams.otdt.tests.otjld.roleplaying.AllBindingAmbiguitiesTests;
@@ -136,6 +137,9 @@
 		/*B.1*/suite.addTest(ReportedBugs.suite());
 		/*B.2*/suite.addTest(CompilationOrder.suite());
 		/*X.2*/suite.addTest(DevelopmentExamples.suite());
+		
+		suite.addTest(ComplexStructures.suite());
+		
 		return suite;
 	}
 }
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ComplexStructures.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ComplexStructures.java
new file mode 100644
index 0000000..d5292d9
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/ComplexStructures.java
@@ -0,0 +1,82 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2013 GK Software AG.
+ * 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ * 
+ * Contributors:
+ * 	  Stephan Herrmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.tests.otjld.regression;
+
+import junit.framework.Test;
+
+import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest;
+
+public class ComplexStructures extends AbstractOTJLDTest {
+	
+	public ComplexStructures(String name) {
+		super(name);
+	}
+
+	// Static initializer to specify tests subset using TESTS_* static variables
+	// All specified tests which do not belong to the class are skipped...
+	static {
+//		TESTS_NAMES = new String[] { "testBug391876"};
+//		TESTS_NUMBERS = new int[] { 1459 };
+//		TESTS_RANGE = new int[] { 1097, -1 };
+	}
+
+	public static Test suite() {
+		return buildComparableTestSuite(testClass());
+	}
+
+	public static Class testClass() {
+		return ComplexStructures.class;
+	}
+	
+	public void testRoleCtor01() {
+		runConformTest(
+			new String[] {
+				"SomeTeam.java",
+				"public team class SomeTeam {\n" + 
+				"\n" + 
+				"	public class BGraph {\n" + 
+				"		public BGraph() { }\n" + 
+				"	}\n" + 
+				"\n" + 
+				"\n" + 
+				"	public void test() {\n" + 
+				"		final Features f = new Features();\n" + 
+				"		BasicGraph<@f> g3 = f.newBasicGraphException();\n" + 
+				"		g3.print();\n" + 
+				"	}\n" + 
+				"\n" + 
+				"	public team class Features {\n" + 
+				"		protected BasicGraph newBasicGraphException() {\n" + 
+				"			return new BasicGraph();\n" + 
+				"		}\n" + 
+				"\n" + 
+				"		public team class BasicGraph playedBy BGraph {\n" + 
+				"			public BasicGraph() { base(); }\n" + 
+				"\n" + 
+				"			public void print() {\n" + 
+				"				System.out.println(\"I am a basic graph ...\");\n" + 
+				"			}\n" + 
+				"		}\n" + 
+				"	}\n" + 
+				"\n" + 
+				"	public static void main(String[] args) {\n" + 
+				"		new SomeTeam().test();\n" + 
+				"	}\n" + 
+				"}\n"
+			},
+			"I am a basic graph ...");
+	}
+}