From 8e460755a26d78f674c99ac016245018f86352d7 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Fri, 5 Nov 2021 16:42:59 +0100 Subject: [PATCH] Store excluded references in a "IdentitySet" --- src/main/java/sorald/SelectiveForceImport.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/sorald/SelectiveForceImport.java b/src/main/java/sorald/SelectiveForceImport.java index a7d947222..6b28541ac 100644 --- a/src/main/java/sorald/SelectiveForceImport.java +++ b/src/main/java/sorald/SelectiveForceImport.java @@ -1,7 +1,9 @@ package sorald; import java.util.Collection; +import java.util.Collections; import java.util.IdentityHashMap; +import java.util.Set; import spoon.reflect.path.CtRole; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.ForceImportProcessor; @@ -12,20 +14,20 @@ * references. */ public class SelectiveForceImport extends ForceImportProcessor { - // use identity rather than equality to identify existing references to avoid mistaking clones - // for originals - private final IdentityHashMap, Boolean> excludedReferences; + private final Set> excludedReferences; /** @param referencesToIgnore A collection of references to ignore when force-importing. */ public SelectiveForceImport(Collection> referencesToIgnore) { - excludedReferences = new IdentityHashMap<>(); - referencesToIgnore.forEach(ref -> excludedReferences.put(ref, true)); + // use identity rather than equality to identify existing references to avoid mistaking + // clones for originals + excludedReferences = Collections.newSetFromMap(new IdentityHashMap<>()); + excludedReferences.addAll(referencesToIgnore); } @Override protected void handleTypeReference( CtTypeReference reference, LexicalScope nameScope, CtRole role) { - if (!excludedReferences.containsKey(reference)) { + if (!excludedReferences.contains(reference)) { super.handleTypeReference(reference, nameScope, role); } }