Bug 397867 - [compiler] illegal access to invisible method via callin
binding not detected
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 eb55f16..5765e0b 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
@@ -1,10 +1,9 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
  * 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
- * $Id: ProblemReporter.java 23405 2010-02-03 17:02:18Z stephan $
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
@@ -11288,6 +11287,20 @@
 	String[] args = { new String(binding.readableName()) };
 	this.handle(IProblem.CallinToDeprecated, args, args, spec.sourceStart, spec.sourceEnd);
 }
+
+public void invisibleMethod(MethodSpec spec, MethodBinding method) {
+	this.handle(
+		IProblem.NotVisibleMethod,
+		new String[] {
+			new String(method.declaringClass.readableName()),
+			new String(method.selector), typesAsString(method, false)},
+		new String[] {
+			new String(method.declaringClass.shortReadableName()),
+			new String(method.selector), typesAsString(method, true)},
+		spec.sourceStart,
+		spec.sourceEnd);
+}
+
 // -- 4.2 --
 public void callinInNonRole(ReferenceBinding declaringClass, AbstractMethodDeclaration method) {
 	String[] args = new String[] {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java
index d254881..5015535 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java
@@ -1,10 +1,10 @@
 /**********************************************************************
  * This file is part of "Object Teams Development Tooling"-Software
  *
- * Copyright 2003, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * Copyright 2003, 2013 Fraunhofer Gesellschaft, Munich, Germany,
  * for its Fraunhofer Institute for Computer Architecture and Software
  * Technology (FIRST), Berlin, Germany and Technical University Berlin,
- * Germany.
+ * Germany, and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -324,8 +324,20 @@
 				receiverClass = receiverClass.enclosingType();
 			}
    		}
-		if (this.resolvedMethod != null && !this.resolvedMethod.isValidBinding() && this.resolvedMethod.declaringClass == null)
-			this.resolvedMethod.declaringClass = receiverClass; // needed for computeUniqueKey (via CallinCalloutBinding.computeUniqueKey)
+		if (this.resolvedMethod != null) {
+			if (this.resolvedMethod.isValidBinding()) {
+				// check visibility of role-side in callin:
+				if (!isBaseSide 
+						&& scope.referenceContext() instanceof CallinMappingDeclaration 
+						&& !this.resolvedMethod.canBeSeenBy(this, scope)) 
+				{
+					scope.problemReporter().invisibleMethod(this, this.resolvedMethod);
+					this.resolvedMethod = new ProblemMethodBinding(this.resolvedMethod, this.selector, this.parameters, ProblemReasons.NotVisible);
+				}				
+			}
+			if (!this.resolvedMethod.isValidBinding() && this.resolvedMethod.declaringClass == null)
+				this.resolvedMethod.declaringClass = receiverClass; // needed for computeUniqueKey (via CallinCalloutBinding.computeUniqueKey)
+		}
 		return this.resolvedMethod;
 	}
 
@@ -724,7 +736,7 @@
 		return null;
 	}
 	public boolean isSuperAccess() {
-		return false;
+		return true; // grant access to inherited methods
 	}
 	
 	public boolean isTypeAccess() {
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/CallinMethodBinding.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/CallinMethodBinding.java
index c511c86..894628e 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/CallinMethodBinding.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/callinbinding/CallinMethodBinding.java
@@ -1,13 +1,12 @@
 /**********************************************************************
  * This file is part of "Object Teams Development Tooling"-Software
  * 
- * Copyright 2004, 2010 IT Service Omikron GmbH and others.
+ * Copyright 2004, 2013 IT Service Omikron GmbH and others.
  * 
  * 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
- * $Id$
  * 
  * Please visit http://www.eclipse.org/objectteams for updates and contact.
  * 
@@ -34,7 +33,7 @@
 	// Static initializer to specify tests subset using TESTS_* static variables
 	// All specified tests which does not belong to the class are skipped...
 	static {
-//		TESTS_NAMES = new String[] { "testBug387996a" };
+//		TESTS_NAMES = new String[] { "test4143J_callinToTeamMethod4" };
 //		TESTS_NUMBERS = new int[] { 1459 };
 //		TESTS_RANGE = new int[] { 1097, -1 };
 	}
@@ -7689,7 +7688,44 @@
             customOptions,
             null/*no custom requestor*/);
     }
-    
+
+    // an after callin binding refers to a package-private method of a super team
+    // https://bugs.eclipse.org/397867 - [compiler] illegal access to invisible method via callin binding not detected
+    public void test4143_callinToTeamMethod4() {
+       runNegativeTest(
+            new String[] {
+		"p2/Team4143cttm4_2.java",
+			    "package p2;\n" +
+			    "import base p0.T4143cttm4;\n" +
+			    "public team class Team4143cttm4_2 extends p1.Team4143cttm4_1 {\n" +
+			    "    protected class R playedBy T4143cttm4 {\n" +
+			    "        void k(String s) <- after void test()\n" +
+			    "            with { s <- \"K\" }\n" +
+			    "    }\n" +
+			    "}\n",
+		"p1/Team4143cttm4_1.java",
+			    "package p1;\n" +
+			    "public team class Team4143cttm4_1 {\n" +
+			    "    void k(String s) {\n" +
+			    "        System.out.print(s);\n" +
+			    "    }\n" +
+			    "}\n",
+		"p0/T4143cttm4.java",
+			    "package p0;\n" +
+			    "public class T4143cttm4 {\n" +
+			    "    public void test() {\n" +
+			    "        System.out.print(\"O\");\n" +
+			    "    }\n" +
+			    "}\n"
+            },
+            "----------\n" + 
+    		"1. ERROR in p2\\Team4143cttm4_2.java (at line 5)\n" + 
+    		"	void k(String s) <- after void test()\n" + 
+    		"	     ^\n" + 
+    		"The method k(String) from the type Team4143cttm4_1 is not visible\n" + 
+    		"----------\n");
+    }
+
     // implicitly inherited role method requires weakening
     public void test4144_callinToInherited1() {
     	runConformTest(