Test & fix for Bug 372433 - [refactoring][dom] extract method in a
callin with tunneled base result throws NPE
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
index 0419c6a..b671de6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/AstGenerator.java
@@ -139,7 +139,9 @@
 	}
 
 	public SingleNameReference singleNameReference(char[] name) {
-		return new SingleNameReference(name, this.pos);
+		SingleNameReference ref = new SingleNameReference(name, this.pos);
+		ref.bits |= ASTNode.IsGenerated;
+		return ref;
 	}
 	public QualifiedNameReference qualifiedNameReference(char[][] tokens) {
 		long[] poss = new long[tokens.length];
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index b303876..c2aa0cd 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -2617,6 +2617,13 @@
 		final ReturnStatement returnStatement = new ReturnStatement(this.ast);
 		returnStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
 		if (statement.expression != null) {
+//{ObjectTeams: don't convert synthetic _OT$result in return statement:
+		  org.eclipse.jdt.internal.compiler.ast.Expression expr = statement.expression;
+		  if (expr.isGenerated() && expr instanceof SingleNameReference) {
+			  if (CharOperation.equals(((SingleNameReference)expr).token, IOTConstants.OT_RESULT))
+				  return returnStatement;
+		  }
+// SH}
 			returnStatement.setExpression(convert(statement.expression));
 		}
 		return returnStatement;
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/src/org/eclipse/objectteams/otdt/ui/tests/dom/converter/BaseCallMessageSendTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/src/org/eclipse/objectteams/otdt/ui/tests/dom/converter/BaseCallMessageSendTest.java
index 2ff830d..ccd3c67 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/src/org/eclipse/objectteams/otdt/ui/tests/dom/converter/BaseCallMessageSendTest.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/src/org/eclipse/objectteams/otdt/ui/tests/dom/converter/BaseCallMessageSendTest.java
@@ -41,6 +41,7 @@
 import org.eclipse.jdt.core.dom.IMethodBinding;
 import org.eclipse.jdt.core.dom.IfStatement;
 import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.ReturnStatement;
 import org.eclipse.jdt.core.dom.SimpleName;
 import org.eclipse.jdt.core.dom.TypeDeclaration;
 import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
@@ -302,4 +303,12 @@
                 expected, actual);
     }
     
+    // see http://bugs.eclipse.org/372433 - [refactoring][dom] extract method in a callin with tunneled base result throws NPE
+	public void testReturnWithHiddenExpression1() {
+		MethodDeclaration method = _role.getMethods()[1];
+		ReturnStatement returnStatement = (ReturnStatement) method.getBody().statements().get(1);
+
+		assertNull("Return should not show hidden expression: "+returnStatement.getExpression(),
+				returnStatement.getExpression());
+	}
 }
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team1.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team1.java
index a96bdeb..67e3c11 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team1.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team1.java
@@ -14,6 +14,7 @@
         callin void roleMethod1()
         {
             base.roleMethod1();
+            return; // for testReturnWithHiddenExpression1()
         }
         
         callin int roleMethod2()
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team2.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team2.java
index 5af50f5..b765dd9 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team2.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.dom/workspace/DOM_AST/src/basecall/teampkg/Team2.java
@@ -2,7 +2,7 @@
 
 import basecall.basepkg.MyClass;
 
-public team class Team1 
+public team class Team2
 {
 	public class Role1<S,T> playedBy MissingBaseclass
     {