Bug 436759 [otdre] Finish implementation of OTDRE
- fix testA12_genericRoleFeature16
- improve test isolation be avoiding identical file names
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticRoleBridgeMethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticRoleBridgeMethodBinding.java
index d1471cd..9550c3b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticRoleBridgeMethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticRoleBridgeMethodBinding.java
@@ -17,10 +17,12 @@
 package org.eclipse.objectteams.otdt.internal.core.compiler.lookup;
 
 import static org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.*;
+
 import org.eclipse.jdt.core.compiler.CharOperation;
 import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
 import org.eclipse.jdt.internal.compiler.codegen.Opcodes;
 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding;
 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
 import org.eclipse.jdt.internal.compiler.lookup.Scope;
 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
@@ -29,6 +31,7 @@
 import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
 import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
 import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel;
+import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper;
 import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer;
 
 public class SyntheticRoleBridgeMethodBinding extends SyntheticOTMethodBinding {
@@ -36,8 +39,9 @@
 	public static final char[] PRIVATE = "$private$".toCharArray(); //$NON-NLS-1$
 
 	public SyntheticRoleBridgeMethodBinding(SourceTypeBinding declaringRole, ReferenceBinding originalRole, MethodBinding targetMethod, int bridgeKind) {
-		super(declaringRole, AccPublic|AccSynthetic, targetMethod.selector, targetMethod.parameters, targetMethod.returnType);
+		super(declaringRole, AccPublic|AccSynthetic, targetMethod.selector, originalParameters(targetMethod), originalReturnType(targetMethod));
 		this.purpose = bridgeKind;
+		System.err.println(originalRole.toString());
 		switch (bridgeKind) {
 			case RoleMethodBridgeOuter:
 				// correction: this method sits in the team not the role:
@@ -53,15 +57,16 @@
 				break;
 			case RoleMethodBridgeInner:
 				// correction: add role as first parameter:
-				len = targetMethod.parameters.length;
+				len = this.parameters.length;
 				int offset = targetMethod.isStatic()?2:0;
-				this.parameters = new TypeBinding[len+1+offset];
-				this.parameters[0] = originalRole.getRealType();
+				TypeBinding[] newParameters = new TypeBinding[len+1+offset];
+				newParameters[0] = originalRole.getRealType();
 				if (offset > 0) {
-					this.parameters[1] = TypeBinding.INT;				// dummy int
-					this.parameters[2] = originalRole.enclosingType(); // team arg
+					newParameters[1] = TypeBinding.INT;				// dummy int
+					newParameters[2] = originalRole.enclosingType(); // team arg
 				}
-				System.arraycopy(targetMethod.parameters, 0, this.parameters, 1+offset, len);
+				System.arraycopy(this.parameters, 0, newParameters, 1+offset, len);
+				this.parameters = newParameters;
 				// correction: this bridge is static:
 				this.modifiers |= AccStatic;
 				// correction: generate the bridge method name:
@@ -76,6 +81,40 @@
 		this.index = methodId;
 	}
 
+	private static TypeBinding[] originalParameters(MethodBinding targetMethod) {
+		if (!TSuperHelper.isTSuper(targetMethod)) {
+			MethodBinding top = findTopMethod(targetMethod);
+			if (top != null)
+				return top.original().parameters;
+		}
+		return targetMethod.original().parameters;
+	}
+
+	private static TypeBinding originalReturnType(MethodBinding targetMethod) {
+		if (!TSuperHelper.isTSuper(targetMethod)) {
+			MethodBinding top = findTopMethod(targetMethod);
+			if (top != null)
+				return top.original().returnType;
+		}
+		return targetMethod.original().returnType;
+	}
+
+	static MethodBinding findTopMethod(MethodBinding targetMethod) {
+		while (targetMethod.copyInheritanceSrc != null)
+			targetMethod = targetMethod.copyInheritanceSrc;
+		tsupers: if (targetMethod.overriddenTSupers != null) {
+			for (int i = 0; i < targetMethod.overriddenTSupers.length; i++) {
+				MethodBinding cand = targetMethod.overriddenTSupers[i];
+				if (!(cand instanceof ParameterizedMethodBinding)) {
+					targetMethod = cand;
+					break tsupers;
+				}
+			}
+			if (targetMethod.overriddenTSupers.length > 0)
+				targetMethod = targetMethod.overriddenTSupers[0];
+		}
+		return targetMethod;
+	}
 	@Override
 	public void generateInstructions(CodeStream codeStream) {
 		TypeBinding[] arguments = this.parameters;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java
index 7195ef5..57366a0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/copyinheritance/CopyInheritance.java
@@ -1124,9 +1124,6 @@
 	    }
     	if (method.isPrivate()) {
     		newMethodDecl.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't warn unused copied method
-    		MethodBinding synthBinding = SyntheticRoleBridgeMethodBinding.findOuterAccessor(targetRoleDecl.scope, targetRoleDecl.binding, newMethodDecl.binding);
-    		if (synthBinding != null)
-    			synthBinding.parameters[0] = srcRole.getRealType(); // manual weakening of bridge to copy-inherited method
     	}
 
 	    newMethodDecl.binding.copiedInContext = tgtTeam.enclosingType();
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java
index 9c6df41..2c4664b 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java
@@ -1322,22 +1322,22 @@
     public void testA12_genericRoleFeature16a() {
     	runConformTest(
     		new String[] {
-    	"TeamA12grf16_3.java",
-    			"public team class TeamA12grf16_3 extends TeamA12grf16_2<String> {\n" +
+    	"TeamA12grf16a_3.java",
+    			"public team class TeamA12grf16a_3 extends TeamA12grf16a_2<String> {\n" +
 				"   @Override\n" +
-				"	public class R playedBy TA12grf16 {\n" +
+				"	public class R playedBy TA12grf16a {\n" +
 				"		 test <- before test;\n" +
 				"   }\n" +
     			"   public static void main(String... args) {\n" +
-    			"       new TeamA12grf16_3().activate();\n" +
-    			"       System.out.print(new TA12grf16().test(\"K\"));" +
+    			"       new TeamA12grf16a_3().activate();\n" +
+    			"       System.out.print(new TA12grf16a().test(\"K\"));" +
     			"   }\n" +
     			"}\n",
-    	"TeamA12grf16_2.java",
-				"public team class TeamA12grf16_2<U> extends TeamA12grf16_1<U> {\n" +
+    	"TeamA12grf16a_2.java",
+				"public team class TeamA12grf16a_2<U> extends TeamA12grf16a_1<U> {\n" +
 				"}\n",
-    	"TeamA12grf16_1.java",
-    			"public team class TeamA12grf16_1<U> {\n" +
+    	"TeamA12grf16a_1.java",
+    			"public team class TeamA12grf16a_1<U> {\n" +
     			"	public class R {\n" +
 				"        private U test(U u) {\n" +
 				"            System.out.print(\"O\");\n" +
@@ -1345,8 +1345,8 @@
 				"        }\n" +
     			"   }\n" +
     			"}\n",
-    	"TA12grf16.java",
-    			"public class TA12grf16 {\n" +
+    	"TA12grf16a.java",
+    			"public class TA12grf16a {\n" +
     			"   protected String test(String u){ return u;}" +
     			"}\n"
     		},
@@ -1359,40 +1359,40 @@
     public void testA12_genericRoleFeature16f() {
     	runNegativeTest(
     		new String[] {
-    	"TeamA12grf16_3.java",
-    			"public team class TeamA12grf16_3 extends TeamA12grf16_2<String> {\n" +
+    	"TeamA12grf16f_3.java",
+    			"public team class TeamA12grf16f_3 extends TeamA12grf16f_2<String> {\n" +
     			"   public static void main(String... args) {\n" +
-    			"       new TeamA12grf16_3().activate();\n" +
-    			"       System.out.print(new TA12grf16().test(\"K\"));" +
+    			"       new TeamA12grf16f_3().activate();\n" +
+    			"       System.out.print(new TA12grf16f().test(\"K\"));" +
     			"   }\n" +
     			"}\n",
-    	"TeamA12grf16_2.java",
-				"public team class TeamA12grf16_2<U> extends TeamA12grf16_1<U> {\n" +
+    	"TeamA12grf16f_2.java",
+				"public team class TeamA12grf16f_2<U> extends TeamA12grf16f_1<U> {\n" +
 				"   @Override\n" +
-				"	public class R playedBy TA12grf16 {\n" +
+				"	public class R playedBy TA12grf16f {\n" +
 				"		 test <- before test;\n" +
 				"   }\n" +
 				"}\n",
-    	"TeamA12grf16_1.java",
-    			"public team class TeamA12grf16_1<U> {\n" +
+    	"TeamA12grf16f_1.java",
+    			"public team class TeamA12grf16f_1<U> {\n" +
     			"	public class R {\n" +
 				"        private U test(U u) {\n" +
 				"            return u;\n" +
 				"        }\n" +
     			"   }\n" +
     			"}\n",
-    	"TA12grf16.java",
-    			"public class TA12grf16 {\n" +
+    	"TA12grf16f.java",
+    			"public class TA12grf16f {\n" +
     			"   protected String test(String u){ return u;}" +
     			"}\n"
     		},
     		"----------\n" + 
-			"1. ERROR in TeamA12grf16_2.java (at line 4)\n" + 
+			"1. ERROR in TeamA12grf16f_2.java (at line 4)\n" + 
 			"	test <- before test;\n" + 
 			"	^^^^\n" + 
 			(this.weavingScheme == WeavingScheme.OTRE
 			? "Type mismatch: cannot convert from String to U\n"
-			: "The method test(U) in the type TeamA12grf16_2<U>.R is not applicable for the arguments (String)\n"
+			: "The method test(U) in the type TeamA12grf16f_2<U>.R is not applicable for the arguments (String)\n"
 			) +
 			"----------\n");
     }