diff options
author | Andrey Loskutov | 2021-07-25 16:39:56 +0000 |
---|---|---|
committer | Andrey Loskutov | 2021-07-25 17:54:51 +0000 |
commit | 7077784d7252f4bb8d1a4f4efaaa66b302c07930 (patch) | |
tree | 0b4418e6475ddb54992cd7bbd844c599e5b06eca | |
parent | 383a06f887e3867b17731d391c85e98e020de2a6 (diff) | |
download | eclipse.jdt.core-7077784d7252f4bb8d1a4f4efaaa66b302c07930.tar.gz eclipse.jdt.core-7077784d7252f4bb8d1a4f4efaaa66b302c07930.tar.xz eclipse.jdt.core-7077784d7252f4bb8d1a4f4efaaa66b302c07930.zip |
Bug 573301 - ClassCastException in InternalExtendedCompletionContextI20210725-1800
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>
2 files changed, 21 insertions, 20 deletions
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 0db23c7f4f..25d3f9eed2 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.MemberValuePair; 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.SourceMethod; 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 @@ public class CompletionUnitStructureRequestor extends CompilationUnitStructureRe }; 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 7b87657fe7..253234c2b1 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.JavaElement; 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 @@ public class InternalExtendedCompletionContext { 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 @@ public class InternalExtendedCompletionContext { 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 @@ public class InternalExtendedCompletionContext { 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 @@ public class InternalExtendedCompletionContext { } 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); } } |