Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: store excluded references in a set which wraps IdentityHashMap #611

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/main/java/sorald/SelectiveForceImport.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<CtTypeReference<?>, Boolean> excludedReferences;
private final Set<CtTypeReference<?>> excludedReferences;

/** @param referencesToIgnore A collection of references to ignore when force-importing. */
public SelectiveForceImport(Collection<CtTypeReference<?>> 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);
}
}
Expand Down