Bug 573301 - ClassCastException in InternalExtendedCompletionContext

Fixed wrong elements put into non-generified maps.

Change-Id: Ia3dd8e300ae6c4816ca7b97d85ae3d79f1c44635
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183352
Tested-by: JDT Bot <jdt-bot@eclipse.org>
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java
index 0db23c7..25d3f9e 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java
@@ -42,6 +42,7 @@
 import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
 import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+import org.eclipse.jdt.internal.compiler.lookup.Binding;
 import org.eclipse.jdt.internal.compiler.parser.Parser;
 import org.eclipse.jdt.internal.core.AnnotatableInfo;
 import org.eclipse.jdt.internal.core.Annotation;
@@ -59,22 +60,22 @@
 import org.eclipse.jdt.internal.core.SourceType;
 import org.eclipse.jdt.internal.core.TypeParameter;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
+@SuppressWarnings({"rawtypes"})
 public class CompletionUnitStructureRequestor extends CompilationUnitStructureRequestor {
 	private ASTNode assistNode;
 
-	private Map bindingCache;
-	private Map elementCache;
-	private Map elementWithProblemCache;
+	private Map<JavaElement, Binding> bindingCache;
+	private Map<Binding, JavaElement> elementCache;
+	private Map<ASTNode, JavaElement> elementWithProblemCache;
 
 	public CompletionUnitStructureRequestor(
 			ICompilationUnit unit,
 			CompilationUnitElementInfo unitInfo,
 			Parser parser,
 			ASTNode assistNode,
-			Map bindingCache,
-			Map elementCache,
-			Map elementWithProblemCache,
+			Map<JavaElement, Binding> bindingCache,
+			Map<Binding, JavaElement> elementCache,
+			Map<ASTNode, JavaElement> elementWithProblemCache,
 			Map newElements) {
 		super(unit, unitInfo, newElements);
 		this.parser = parser;
@@ -113,10 +114,10 @@
 		};
 		FieldDeclaration decl = (FieldDeclaration) (compInfo.node);
 		if (decl.binding != null) {
-			this.bindingCache.put(compName, decl.binding);
-			this.elementCache.put(decl.binding, compName);
+			this.bindingCache.put(comp, decl.binding);
+			this.elementCache.put(decl.binding, comp);
 		} else {
-			this.elementWithProblemCache.put(compInfo.node, compName);
+			this.elementWithProblemCache.put(compInfo.node, comp);
 		}
 		return comp;
 	}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java
index 7b87657..253234c 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java
@@ -70,7 +70,7 @@
 import org.eclipse.jdt.internal.core.LocalVariable;
 import org.eclipse.jdt.internal.core.util.Util;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
+@SuppressWarnings({"rawtypes"})
 public class InternalExtendedCompletionContext {
 	private static Util.BindingsToNodesMap EmptyNodeMap = new Util.BindingsToNodesMap() {
 		@Override
@@ -99,8 +99,8 @@
 	private ObjectVector visibleMethods;
 
 	private boolean hasComputedEnclosingJavaElements;
-	private Map bindingsToHandles;
-	private Map nodesWithProblemsToHandles;
+	private Map<Binding, JavaElement> bindingsToHandles;
+	private Map<ASTNode, JavaElement> nodesWithProblemsToHandles;
 	private ICompilationUnit compilationUnit;
 
 	public InternalExtendedCompletionContext(
@@ -132,10 +132,10 @@
 		if (this.typeRoot.getElementType() == IJavaElement.COMPILATION_UNIT) {
 	 		ICompilationUnit original = (org.eclipse.jdt.core.ICompilationUnit)this.typeRoot;
 
-			HashMap handleToBinding = new HashMap();
-			HashMap bindingToHandle = new HashMap();
-			HashMap nodeWithProblemToHandle = new HashMap();
-			HashMap handleToInfo = new HashMap();
+			HashMap<JavaElement, Binding> handleToBinding = new HashMap<>();
+			HashMap<Binding, JavaElement> bindingToHandle = new HashMap<>();
+			HashMap<ASTNode, JavaElement> nodeWithProblemToHandle = new HashMap<>();
+			HashMap<ICompilationUnit, CompilationUnitElementInfo> handleToInfo = new HashMap<ICompilationUnit, CompilationUnitElementInfo>();
 
 			org.eclipse.jdt.core.ICompilationUnit handle = new AssistCompilationUnit(original, this.owner, handleToBinding, handleToInfo);
 			CompilationUnitElementInfo info = new CompilationUnitElementInfo();
@@ -298,7 +298,7 @@
 			computeEnclosingJavaElements();
 		}
 		if (this.bindingsToHandles == null) return null;
-		return (JavaElement)this.bindingsToHandles.get(binding);
+		return this.bindingsToHandles.get(binding);
 	}
 
 	private JavaElement getJavaElementOfCompilationUnit(ASTNode node, Binding binding) {
@@ -307,10 +307,10 @@
 		}
 		if (binding != null) {
 			if (this.bindingsToHandles == null) return null;
-			return (JavaElement)this.bindingsToHandles.get(binding);
+			return this.bindingsToHandles.get(binding);
 		} else {
 			if (this.nodesWithProblemsToHandles == null) return null;
-			return (JavaElement)this.nodesWithProblemsToHandles.get(node);
+			return this.nodesWithProblemsToHandles.get(node);
 		}
 	}