Test and fix for Bug 311339 -  Quickfix "Add Return Statement" inserts invalid code
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
index 477a91b..f7cce87 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
@@ -270,6 +270,10 @@
 					IVariableBinding[] newFields = new IVariableBinding[length];
 					for (int i = 0; i < length; i++) {
 						FieldBinding fieldBinding = fieldBindings[i];
+//{ObjectTeams: skip internal fields:
+						if (CharOperation.prefixEquals(IOTConstants.OT_DOLLAR_NAME, fieldBinding.name))
+							continue;
+// SH}
 						IVariableBinding variableBinding = this.resolver.getVariableBinding(fieldBinding);
 						if (variableBinding != null) {
 							newFields[convertedFieldCount++] = variableBinding;
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/StatementQuickFixTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/StatementQuickFixTest.java
new file mode 100644
index 0000000..25307cc
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests/src/org/eclipse/objectteams/otdt/ui/tests/core/StatementQuickFixTest.java
@@ -0,0 +1,104 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2010 Stephan Herrmann.
+ * 
+ * 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.
+ * 
+ * Contributors:
+ * 	  Stephan Herrmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.ui.tests.core;
+
+import java.util.ArrayList;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class StatementQuickFixTest extends OTQuickFixTest {
+	
+	private static final Class THIS= StatementQuickFixTest.class;
+
+	public StatementQuickFixTest(String name) {
+		super(name);
+	}
+
+	public static Test allTests() {
+		return setUpTest(new TestSuite(THIS));
+	}
+	
+	public static Test setUpTest(Test test) {
+		return new ProjectTestSetup(test);
+	}
+	
+	public static Test suite() {
+		return allTests();
+	}
+	
+	/* add a return statement to a role method (callin).
+	 * See https://bugs.eclipse.org/311339
+	 */
+	public void testAddReturnInCallinMethod() throws Exception {
+		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
+		StringBuffer buf= new StringBuffer();
+		buf = new StringBuffer();
+		buf.append("package test1;\n");
+		buf.append("public class B1 {\n");
+		buf.append("    public void foo() {};\n");
+		buf.append("}\n");
+		pack1.createCompilationUnit("B1.java", buf.toString(), false, null);
+
+		buf = new StringBuffer();
+		buf.append("package test1;\n");	
+		buf.append("public team class T1 {\n");
+		buf.append("    protected class R playedBy B1 {\n");
+		buf.append("        @SuppressWarnings(\"basecall\")\n");
+		buf.append("        callin boolean foo(){\n");
+		buf.append("		}\n");
+		buf.append("    }\n");
+		buf.append("}\n");
+		ICompilationUnit cuteam = pack1.createCompilationUnit("T1.java", buf.toString(), false, null);
+		
+		CompilationUnit astRoot= getASTRoot(cuteam);
+		ArrayList proposals= collectCorrections(cuteam, astRoot);
+		assertNumberOfProposals(proposals, 2);
+		assertCorrectLabels(proposals);
+
+		String[] expectedProposals = new String[2];
+		buf= new StringBuffer();
+		buf.append("package test1;\n");	
+		buf.append("public team class T1 {\n");
+		buf.append("    protected class R playedBy B1 {\n");
+		buf.append("        @SuppressWarnings(\"basecall\")\n");
+		buf.append("        callin boolean foo(){\n");
+		buf.append("            return false;\n"); // don't propose internal fields like _OT$cacheInitTrigger
+		buf.append("		}\n");
+		buf.append("    }\n");
+		buf.append("}\n");
+		expectedProposals[0] = buf.toString();
+		buf= new StringBuffer();
+		buf.append("package test1;\n");	
+		buf.append("public team class T1 {\n");
+		buf.append("    protected class R playedBy B1 {\n");
+		buf.append("        @SuppressWarnings(\"basecall\")\n");
+		buf.append("        callin void foo(){\n");
+		buf.append("		}\n");
+		buf.append("    }\n");
+		buf.append("}\n");
+		expectedProposals[1] = buf.toString();
+
+
+		assertExpectedExistInProposals(proposals, expectedProposals);
+	}
+
+}