[331473] Inference mixin support broken
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SyntaxErrorTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SyntaxErrorTest.java
index 4b39592..65c88b1 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SyntaxErrorTest.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SyntaxErrorTest.java
@@ -324,4 +324,58 @@
 		expectedSyntaxErrorDiagnosis,
 		testName);
 }
+
+//public void test06() {
+//	String s = 
+//		"(x=7,y=5)"; 	
+//
+//	String expectedSyntaxErrorDiagnosis =
+//		"";
+//
+//	String testName = "<test06>";
+//	checkParse(
+//		s.toCharArray(),
+//		expectedSyntaxErrorDiagnosis,
+//		testName);
+//}
+//public void test06a() {
+//	String s = 
+//		"x=7,y=5;"; 	
+//
+//	String expectedSyntaxErrorDiagnosis =
+//		"";
+//
+//	String testName = "<test06>";
+//	checkParse(
+//		s.toCharArray(),
+//		expectedSyntaxErrorDiagnosis,
+//		testName);
+//}
+//public void test07() {
+//	String s = 
+//		"{x:7,y:5}"; 	
+//
+//	String expectedSyntaxErrorDiagnosis =
+//		"";
+//
+//	String testName = "<test06>";
+//	checkParse(
+//		s.toCharArray(),
+//		expectedSyntaxErrorDiagnosis,
+//		testName);
+//}
+//public void test08() {
+//	String s = 
+//		"return \"pageXOffset\" in n ? {x:n.pageXOffset,y:n.pageYOffset} : (n=d.doc.documentElement, n.clientHeight ? {x:d._fixIeBiDiScrollLeft(n.scrollLeft),y:n.scrollTop}:(n=d.body(),{x:n.scrollLeft||0,y:n.scrollTop||0}));};"; 	
+//
+//	String expectedSyntaxErrorDiagnosis =
+//		"";
+//
+//	String testName = "<test>";
+//	checkParse(
+//		s.toCharArray(),
+//		expectedSyntaxErrorDiagnosis,
+//		testName);
+//}
+
 }
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java
index dcb0317..3cce032 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -50,10 +50,18 @@
 import org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.wst.jsdt.internal.compiler.batch.CompilationUnit;
 import org.eclipse.wst.jsdt.internal.compiler.batch.FileSystem;
+import org.eclipse.wst.jsdt.internal.compiler.env.AccessRestriction;
+import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryType;
 import org.eclipse.wst.jsdt.internal.compiler.env.ICompilationUnit;
 import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
+import org.eclipse.wst.jsdt.internal.compiler.env.ISourceType;
 import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.wst.jsdt.internal.compiler.impl.ITypeRequestor;
 import org.eclipse.wst.jsdt.internal.compiler.impl.ReferenceContext;
+import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
+import org.eclipse.wst.jsdt.internal.compiler.lookup.CompilationUnitScope;
+import org.eclipse.wst.jsdt.internal.compiler.lookup.LookupEnvironment;
+import org.eclipse.wst.jsdt.internal.compiler.lookup.PackageBinding;
 import org.eclipse.wst.jsdt.internal.compiler.lookup.TypeConstants;
 import org.eclipse.wst.jsdt.internal.compiler.parser.Parser;
 import org.eclipse.wst.jsdt.internal.compiler.problem.AbortCompilation;
@@ -61,6 +69,7 @@
 import org.eclipse.wst.jsdt.internal.compiler.problem.ProblemReporter;
 import org.eclipse.wst.jsdt.internal.core.search.JavaSearchParticipant;
 import org.eclipse.wst.jsdt.internal.core.search.indexing.SourceIndexer;
+import org.eclipse.wst.jsdt.internal.oaametadata.LibraryAPIs;
 
 public abstract class AbstractRegressionTest extends AbstractCompilerTest
 		implements StopableTestCase {
@@ -672,7 +681,7 @@
 				// Compute class name by removing ".java" and replacing slashes
 				// with dots
 				String className = sourceFile.substring(0,
-						sourceFile.length() - 5).replace('/', '.').replace(
+						sourceFile.length() - 3).replace('/', '.').replace(
 						'\\', '.');
 				if (className.endsWith(PACKAGE_INFO_NAME))
 					return;
@@ -1673,12 +1682,32 @@
 			String testName, String expected, InferOptions inferOptions) {
 
 		return runInferTest(s, testName, expected, inferOptions,
-				new DefaultInferrenceProvider());
+				new InferrenceProvider[] {new DefaultInferrenceProvider()});
 	}
-
+	
 	protected CompilationUnitDeclaration runInferTest(String s,
 			String testName, String expected, InferOptions inferOptions,
 			InferrenceProvider inferrenceProvider) {
+		
+		return runInferTest(s, testName, expected, inferOptions, inferrenceProvider, false);
+	}
+	
+	protected CompilationUnitDeclaration runInferTest(String s,
+			String testName, String expected, InferOptions inferOptions,
+			InferrenceProvider inferrenceProvider, boolean useDefaultToo) {
+		
+		InferrenceProvider[] providers;
+		if(useDefaultToo) {
+			providers = new InferrenceProvider[] {new DefaultInferrenceProvider(), inferrenceProvider};
+		} else {
+			providers = new InferrenceProvider[] {inferrenceProvider};
+		}
+		return runInferTest(s, testName, expected, inferOptions, providers);
+	}
+
+	private CompilationUnitDeclaration runInferTest(String s,
+			String testName, String expected, InferOptions inferOptions,
+			InferrenceProvider[] inferrenceProviders) {
 		// Non-javac part
 		try {
 
@@ -1687,10 +1716,7 @@
 					getCompilerOptions());
 			compilerOptions.inferOptions = inferOptions;
 			TestParser parser = new TestParser(new DefaultProblemFactory(Locale
-					.getDefault()), compilerOptions, true/*
-														 * optimize string
-														 * literals
-														 */, false);
+					.getDefault()), compilerOptions, true/* optimize string literals */, false);
 
 			parser.javadocParser.checkDocComment = true;
 
@@ -1700,11 +1726,14 @@
 			CompilationUnitDeclaration compUnit = parser.parseCompilationUnit(
 					sourceUnit, true);
 
-			InferEngine inferEngine = (InferEngine)inferrenceProvider.getInferEngine();
+			for(int i = 0; i < inferrenceProviders.length; ++i) {
+				InferEngine inferEngine = (InferEngine)inferrenceProviders[i].getInferEngine();
 
-			inferEngine.initialize();
-			inferEngine.setCompilationUnit(compUnit);
-			inferEngine.doInfer();
+				inferEngine.initialize();
+				inferEngine.setCompilationUnit(compUnit);
+				inferEngine.doInfer();
+			}
+			
 			if (expected != null) {
 				StringBuffer sb = new StringBuffer();
 				compUnit.printInferredTypes(sb);
@@ -1718,5 +1747,148 @@
 		} finally {
 		}
 	}
+	
+	/**
+	 * <p>Runs a JUnit test which includes inferring and building the type bindings for the given source.</p>
+	 * 
+	 * @param source JS source to infer and build
+	 * @param expectedInfference expected inferred type after inferring and building
+	 * @param inferOptions {@link InferOptions} to use when inferring and building
+	 * @param inferrenceProvider {@link InferrenceProvider} to use when inferring
+	 */
+	protected void runInferAndBuildBindingsTest(String source, String expectedInfference, InferOptions inferOptions,
+			InferrenceProvider inferrenceProvider) {
+		
+		this.runInferAndBuildBindingsTest(
+				new String[] {source},
+				new String[] {expectedInfference},
+				inferOptions,
+				new InferrenceProvider[] {inferrenceProvider});
+	}
+	
+	/**
+	 * <p>Runs a JUnit test which includes inferring and building the type bindings for the given source.</p>
+	 * 
+	 * <p>Can be used to test multiple JS sources together.</p>
+	 * 
+	 * @param sources JS sources to infer and build
+	 * @param expectedInfferences expected inferred types after inferring and building
+	 * @param inferOptions {@link InferOptions} to use when inferring and building
+	 * @param inferrenceProviders {@link InferrenceProvider}s to use when inferring
+	 */
+	protected void runInferAndBuildBindingsTest(String[] sources, String[] expectedInfferences, InferOptions inferOptions,
+			InferrenceProvider[] inferrenceProviders) {
 
+		IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
+		CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions());
+		compilerOptions.inferOptions = inferOptions;
+		TestParser parser = new TestParser(problemFactory, compilerOptions, true, false);
+
+		parser.javadocParser.checkDocComment = true;
+		
+		ProblemReporter reporter = new DoNothingProblemReporter(compilerOptions, problemFactory);
+		INameEnvironment nameEnv = getNameEnvironment(sources, null);
+		ITypeRequestor requestor = new TypeRequestor(inferrenceProviders, compilerOptions, reporter);
+		
+		CompilationUnitDeclaration[] compUnits = new CompilationUnitDeclaration[sources.length];
+		LookupEnvironment env = new LookupEnvironment(requestor, compilerOptions, reporter, nameEnv);
+		for(int i = 0; i < sources.length; ++i) {
+			String fileName = "/Test/" + i + ".js";
+			ICompilationUnit sourceUnit = new CompilationUnit(sources[i].toCharArray(), fileName, null);
+			compUnits[i] = parser.parseCompilationUnit(sourceUnit, true);
+			
+			for(int j = 0; j < inferrenceProviders.length; ++j) {
+				InferEngine inferEngine = (InferEngine)inferrenceProviders[j].getInferEngine();
+
+				inferEngine.initialize();
+				inferEngine.setCompilationUnit(compUnits[i]);
+				inferEngine.doInfer();
+			}
+			
+			compUnits[i].scope = new CompilationUnitScope(compUnits[i], env);
+			env.buildTypeBindings(compUnits[i], null);
+		}
+		
+		env.completeTypeBindings();
+		
+		//assert inferred types equal expected inferred types
+		for(int i = 0; i < compUnits.length; ++i) {
+			if (expectedInfferences[i] != null) {
+				StringBuffer sb = new StringBuffer();
+				compUnits[i].printInferredTypes(sb);
+				String result = sb.toString();
+				assertEquals(expectedInfferences[i], result);
+			}
+		}
+	}
+	
+	private class DoNothingProblemReporter extends ProblemReporter {
+
+		public DoNothingProblemReporter(CompilerOptions options, IProblemFactory problemFactory) {
+			super(DefaultErrorHandlingPolicies.exitAfterAllProblems(), options, problemFactory);
+		}
+
+		public void record(CategorizedProblem problem,
+				CompilationResult unitResult, ReferenceContext context) {
+			
+		}
+	}
+	
+	private class TypeRequestor implements ITypeRequestor {
+
+		private InferrenceProvider[] fInferrenceProviders;
+		private CompilerOptions fOptions;
+		private ProblemReporter fReporter;
+		
+		public TypeRequestor(InferrenceProvider[] inferrenceProviders, CompilerOptions options, ProblemReporter reporter) {
+			
+			this.fInferrenceProviders = inferrenceProviders;
+			this.fOptions = options;
+			this.fReporter = reporter;
+		}
+		
+		public void accept(IBinaryType binaryType,
+				PackageBinding packageBinding,
+				AccessRestriction accessRestriction) {
+		}
+
+		public void accept(ICompilationUnit unit,
+				AccessRestriction accessRestriction) {
+		}
+
+		public void accept(ISourceType[] sourceType,
+				PackageBinding packageBinding,
+				AccessRestriction accessRestriction) {
+		}
+
+		public void accept(LibraryAPIs libraryMetaData) {
+		}
+
+		public CompilationUnitDeclaration doParse(ICompilationUnit unit,
+				AccessRestriction accessRestriction) {
+
+			Parser p = new InferParser();
+			CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, 0);
+			
+			return p.parse(unit,compilationUnitResult);
+		}
+		
+		private class InferParser extends Parser {
+			public InferParser() {
+				super(TypeRequestor.this.fReporter, true);
+			}
+
+			public void initializeInferenceEngine(CompilationUnitDeclaration compilationUnitDeclaration) {
+				this.inferenceEngines = new IInferEngine[TypeRequestor.this.fInferrenceProviders.length];
+				for(int i = 0; i < this.inferenceEngines.length; ++i) {
+					this.inferenceEngines[i] = TypeRequestor.this.fInferrenceProviders[i].getInferEngine();
+				}
+				
+				for (int i = 0; i <  this.inferenceEngines.length; i++) {
+					this.inferenceEngines[i].initializeOptions(this.options.inferOptions);
+				}
+			}
+		}
+	
+	}
 }
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/BasicResolveTests.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/BasicResolveTests.java
index d8b3121..6427011 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/BasicResolveTests.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/BasicResolveTests.java
@@ -10,6 +10,13 @@
  *******************************************************************************/
 package org.eclipse.wst.jsdt.core.tests.compiler.regression;
 
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.core.tests.util.Util;
+import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
+
 
 
 
@@ -1786,5 +1793,22 @@
 					"----------\n"
 			);
 	}
-	
+	public void test326901() {
+		Map options = new HashMap();
+		options.put(CompilerOptions.OPTION_SemanticValidation, CompilerOptions.ENABLED);
+		Util.compile(
+					new String[] {
+								"Z.js",
+								"function Windget(){\n"+
+									"  this.a=5;\n"+
+									"};\n"+
+									"windget = new Windget();\n"+
+									"(function(a2){\n"+
+										"  // operations on a2\n"+
+										" a2.a();\n"+
+										"})(windget);"
+					},
+					options,
+					File.separator);
+	}
 }
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/InferTypesTests.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/InferTypesTests.java
index f5e0a1d..c33ece9 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/InferTypesTests.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/InferTypesTests.java
@@ -1440,4 +1440,16 @@
 				
 			 );
 		}
+		
+		public void test201() {
+			CompilationUnitDeclaration declaration = this.runInferTest(
+				"foo.bar.Awesome = function(){\n"+
+				"this.test = \"\";\n"+
+				"this.func = function(){}\n"+
+				"}\n",
+				"X.js",
+				"class foo.bar.Awesome extends Object{\n  String test;\n  void func()\n  foo.bar.Awesome()\n}\n",
+				getDefaultOptions()
+			);
+		}
 }