From 6fbfe63457b9862fdb759c585434762b0e3f95d2 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sat, 30 Nov 2024 09:54:55 -0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Ben Liblit --- .../cast/ipa/cha/CrossLanguageClassHierarchy.java | 4 +--- .../ibm/wala/ipa/callgraph/cha/CHACallGraph.java | 15 ++++++--------- .../com/ibm/wala/ipa/cha/IClassHierarchy.java | 4 ++-- .../ipa/summaries/LambdaMethodTargetSelector.java | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cast/src/main/java/com/ibm/wala/cast/ipa/cha/CrossLanguageClassHierarchy.java b/cast/src/main/java/com/ibm/wala/cast/ipa/cha/CrossLanguageClassHierarchy.java index 86997bcea..b647efe46 100644 --- a/cast/src/main/java/com/ibm/wala/cast/ipa/cha/CrossLanguageClassHierarchy.java +++ b/cast/src/main/java/com/ibm/wala/cast/ipa/cha/CrossLanguageClassHierarchy.java @@ -281,8 +281,6 @@ public Set getUnresolvedClasses() { @Override public void clearCaches() { - for (IClassHierarchy cha : hierarchies.values()) { - cha.clearCaches(); - } + hierarchies.values().forEach(IClassHierarchy::clearCaches); } } diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/cha/CHACallGraph.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/cha/CHACallGraph.java index 1b58ad181..06ad4cba1 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/cha/CHACallGraph.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/cha/CHACallGraph.java @@ -153,14 +153,12 @@ public void init(Iterable entrypoints) throws CancelException { cha.clearCaches(); for (CGNode n : this) { for (CallSiteReference site : Iterator2Iterable.make(n.iterateCallSites())) { - Iterator methods = getOrUpdatePossibleTargets(n, site); - while (methods.hasNext()) { - IMethod target = methods.next(); + for (IMethod target : Iterator2Iterable.make(getOrUpdatePossibleTargets(n, site))) { if (isRelevantMethod(target)) { CGNode callee = getNode(target, Everywhere.EVERYWHERE); if (callee == null) { throw new RuntimeException( - "should have already created CGNode for " + target.toString()); + "should have already created CGNode for " + target); } edgeManager.addEdge(n, callee); } @@ -178,8 +176,9 @@ public IClassHierarchy getClassHierarchy() { /** * Cache of possible targets for call sites. * - *

In the future, this cache could be keyed on (MethodReference,isDispatch) pairs to save space - * and possibly time, where isDispatch indicates whether the call site is a virtual dispatch. + *

In the future, this cache could be keyed on ({@link com.ibm.wala.types.MethodReference}, + * {@code isDispatch}) pairs to save space and possibly time, where {@code isDispatch} indicates + * whether the call site is a virtual dispatch. */ private final Map> targetCache = HashMapFactory.make(); @@ -347,9 +346,7 @@ private void closure() throws CancelException { while (!newNodes.isEmpty()) { CGNode n = newNodes.pop(); for (CallSiteReference site : Iterator2Iterable.make(n.iterateCallSites())) { - Iterator methods = getOrUpdatePossibleTargets(n, site); - while (methods.hasNext()) { - IMethod target = methods.next(); + for (IMethod target : Iterator2Iterable.make(getOrUpdatePossibleTargets(n, site))) { if (isRelevantMethod(target)) { CGNode callee = getNode(target, Everywhere.EVERYWHERE); if (callee == null) { diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/IClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/IClassHierarchy.java index 786deda47..f1323de48 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/IClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/IClassHierarchy.java @@ -188,8 +188,8 @@ public interface IClassHierarchy extends Iterable { boolean isAssignableFrom(IClass c1, IClass c2); /** - * clear internal caches that may be invalidated by addition of new classes, e.g., a cache of the - * results of {@link #getPossibleTargets(MethodReference)} + * Clear internal caches that may be invalidated by addition of new classes, e.g., a cache of the + * results of {@link #getPossibleTargets(MethodReference)}. */ void clearCaches(); } diff --git a/core/src/main/java/com/ibm/wala/ipa/summaries/LambdaMethodTargetSelector.java b/core/src/main/java/com/ibm/wala/ipa/summaries/LambdaMethodTargetSelector.java index 7c1c13b9f..5474bd2ce 100644 --- a/core/src/main/java/com/ibm/wala/ipa/summaries/LambdaMethodTargetSelector.java +++ b/core/src/main/java/com/ibm/wala/ipa/summaries/LambdaMethodTargetSelector.java @@ -100,11 +100,11 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec } /** - * Get the summary class for a lambda factory, if it has already been created. + * Gets the summary class for a lambda factory, if it has already been created. * * @param caller the caller node * @param site the call site reference - * @return the summary class for the lambda factory, or null if it has not been created + * @return the summary class for the lambda factory, or {@code null} if it has not been created */ public LambdaSummaryClass getLambdaSummaryClass(CGNode caller, CallSiteReference site) { IR ir = caller.getIR();