Test & fix for Bug 366976 - [compiler] Fup of Bug 366597: StackOverflow
w/ RoleModel.implementMethodBindingsFromSuperinterfaces
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
index 5503250..f5c6f6a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java
@@ -690,8 +690,7 @@
             	StateHelper.setStateRecursive(model.getAst(), nextState, true);
             	continue;
             }
-
-            model._state.startProcessing(nextState);
+            int previousProcessingState = model._state.startProcessing(nextState);
 
             if (model._isLocalType)
             {
@@ -783,6 +782,8 @@
                     	success &= ensureTeamState(model.getTeamModel(), nextState);
                     break;
                 case STATE_LATE_ATTRIBUTES_EVALUATED:
+                	if (previousProcessingState >= STATE_LATE_ATTRIBUTES_EVALUATED) // see http://bugs.eclipse.org/366976
+                		break;
         			// more attributes after fields and methods are in place:
         			// (notably copyInheritanceSrc must be evaluated before resolving)
         			model.evaluateLateAttributes(STATE_LATE_ATTRIBUTES_EVALUATED);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateMemento.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateMemento.java
index d970583..ce83aa5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateMemento.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/StateMemento.java
@@ -247,9 +247,13 @@
 			throw new InternalCompilerError(msg);
 	}
 
-	/** Signal that processing for `state' has begun. */
-	public void startProcessing(int state) {
+	/** Signal that processing for `state' has begun.
+	 * @return the previous processing state
+	 */
+	public int startProcessing(int state) {
+		int previous = this._currentlyProcessingState;
 		this._currentlyProcessingState = Math.max(this._currentlyProcessingState, state);
+		return previous;
 	}
 
 
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/RoleModel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/RoleModel.java
index 507684f..904ed87 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/RoleModel.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/RoleModel.java
@@ -1332,7 +1332,8 @@
 				continue;
 			if (superInterface.roleModel.getState() < ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED-1)
 				continue; // not yet prepared
-			Dependencies.ensureBindingState(superInterface, ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED);
+			if (!Dependencies.ensureBindingState(superInterface, ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED))
+				continue;
 			CallinCalloutBinding[] methodMappings = superInterface.callinCallouts;
 			if (methodMappings != null)
 				for (CallinCalloutBinding mapping : methodMappings)
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/AllTests.java
index 1e8115c..0aa1460 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/AllTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/AllTests.java
@@ -51,6 +51,7 @@
 		suite.addTest(OTSuperTypeHierarchyTest013.suite());
 		suite.addTest(OTSuperTypeHierarchyTest014.suite());
 		suite.addTest(OTSuperTypeHierarchyTest015.suite());
+		suite.addTest(OTSuperTypeHierarchyTest016_Regression.suite());
 		//$JUnit-END$
 		return suite;
 	}
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/OTSuperTypeHierarchyTest016_Regression.java b/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/OTSuperTypeHierarchyTest016_Regression.java
new file mode 100644
index 0000000..956f332
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/hierarchy/org/eclipse/objectteams/otdt/tests/superhierarchy/OTSuperTypeHierarchyTest016_Regression.java
@@ -0,0 +1,79 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute and Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ * 
+ * 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: OTSuperTypeHierarchyTest007_Stress.java 23494 2010-02-05 23:06:44Z stephan $
+ * 
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ * 
+ * Contributors:
+ * 	  Fraunhofer FIRST - Initial API and implementation
+ * 	  Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.tests.superhierarchy;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.objectteams.otdt.core.hierarchy.OTTypeHierarchies;
+import org.eclipse.objectteams.otdt.tests.hierarchy.FileBasedHierarchyTest;
+
+public class OTSuperTypeHierarchyTest016_Regression extends FileBasedHierarchyTest
+{
+    private IType _T1;    
+	private IType _T1_IR;
+
+	public OTSuperTypeHierarchyTest016_Regression(String name)
+	{
+		super(name);
+	}
+	
+	@SuppressWarnings("unused") // variants to statically choose from
+	public static Test suite()
+	{
+		if (true)
+		{
+			return new Suite(OTSuperTypeHierarchyTest016_Regression.class);
+		}
+		junit.framework.TestSuite suite = 
+			new Suite(OTSuperTypeHierarchyTest016_Regression.class.getName());
+		return suite;
+	}
+	
+	public void setUpSuite() throws Exception
+	{
+		setTestProjectDir("HierarchyRegression");
+		super.setUpSuite();
+		
+		String srcFolder = "src";
+		String pkg = "t";
+		
+        _T1 = getType(getTestProjectDir(), srcFolder, pkg, "T1");
+        
+        _T1_IR = getRole(_T1, "T1.IR");
+	}
+	
+	// see http://bugs.eclipse.org/366976
+	public void testInterfaceAtSyntaxError()
+        throws JavaModelException
+	{
+        _focusType = _T1_IR;
+        _testObj = createSuperTypeHierarchy(_focusType);
+
+        // due to severe syntax errors, T1.IR is not connected:
+        IType [] actual = OTTypeHierarchies.getInstance().getAllSuperInterfaces(_testObj, _focusType);
+        assertEquals(0, actual.length);
+        
+        actual = OTTypeHierarchies.getInstance().getSuperclasses(_testObj, _focusType);
+        assertEquals(0, actual.length);        
+    }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/.classpath b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/.classpath
new file mode 100644
index 0000000..3e9f06f
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>	
+	<classpathentry kind="var" path="JCL_LIB" sourcepath="JCL_SRC" rootpath="JCL_SRCROOT"/>
+    <classpathentry kind="output" path="bin"/>
+ 	<classpathentry kind="con" path="OTRE"/>
+</classpath>
+
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/.project b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/.project
new file mode 100644
index 0000000..dfd0069
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/.project
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>HierarchyRegression</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.objectteams.otdt.builder.OTJBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.objectteams.otdt.OTJavaNature</nature>
+	</natures>
+</projectDescription>
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/src/b/Base.java b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/src/b/Base.java
new file mode 100644
index 0000000..201dc8b
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/src/b/Base.java
@@ -0,0 +1,5 @@
+package b;
+
+public class Base {
+
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/src/t/T1.java b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/src/t/T1.java
new file mode 100644
index 0000000..c6fefdc
--- /dev/null
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/workspace/HierarchyRegression/src/t/T1.java
@@ -0,0 +1,16 @@
+package t;
+
+import base b.Base;
+
+/**
+* @author stephan
+*
+*/
+public team class T1 {
+//	protected abstract class IR {
+//	abstract org.Missing foo();
+//	}
+protected interface IR
+protected class R implements IR playedBy Base {
+}
+}