From 69578b26e7347d9017377d82c41699195b51995c Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Thu, 23 Jan 2025 23:30:39 +0800 Subject: [PATCH 1/2] streamify --- .../callgraph/RapidTypeAnalysisAlgorithm.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java index 185d68de3f..b773b2354f 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java @@ -36,6 +36,7 @@ import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; +import sootup.core.util.StreamUtils; import sootup.core.views.View; /** @@ -88,11 +89,7 @@ public CallGraph initialize(@Nonnull List entryPoints) { * * @param method this object contains the method body which is inspected. */ - protected List collectInstantiatedClassesInMethod(SootMethod method) { - if (method == null || method.isAbstract() || method.isNative()) { - return Collections.emptyList(); - } - + protected Stream collectInstantiatedClassesInMethod(SootMethod method) { Set instantiated = method.getBody().getStmts().stream() .filter(stmt -> stmt instanceof JAssignStmt) @@ -100,12 +97,8 @@ protected List collectInstantiatedClassesInMethod(SootMethod method) .filter(value -> value instanceof JNewExpr) .map(value -> ((JNewExpr) value).getType()) .collect(Collectors.toSet()); - List newInstantiatedClassTypes = - instantiated.stream() - .filter(classType -> !instantiatedClasses.contains(classType)) - .collect(Collectors.toList()); instantiatedClasses.addAll(instantiated); - return newInstantiatedClassTypes; + return instantiated.stream().filter(classType -> !instantiatedClasses.contains(classType)); } /** @@ -223,17 +216,10 @@ protected void preProcessingMethod( MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg) { - SootMethod method = - view.getClass(sourceMethod.getDeclClassType()) - .flatMap(c -> c.getMethod(sourceMethod.getSubSignature())) - .orElse(null); - if (method == null) { - return; - } - - List newInstantiatedClasses = collectInstantiatedClassesInMethod(method); - newInstantiatedClasses.forEach( - classType -> includeIgnoredCallsToClass(classType, cg, workList)); + StreamUtils.optionalToStream(view.getMethod(sourceMethod)) + .filter(SootMethod::isConcrete) + .flatMap(this::collectInstantiatedClassesInMethod) + .forEach(classType -> includeIgnoredCallsToClass(classType, cg, workList)); } /** From 001784edce6857c26287a2d58310d3a7f5708549 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Thu, 23 Jan 2025 23:39:46 +0800 Subject: [PATCH 2/2] remove orElse --- .../callgraph/RapidTypeAnalysisAlgorithm.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java index b773b2354f..76740a08bc 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java @@ -236,17 +236,15 @@ protected void includeIgnoredCallsToClass( if (newEdges != null) { newEdges.forEach( call -> { - MethodSignature concreteTarget = - resolveConcreteDispatch(view, call.getTargetMethodSignature()).orElse(null); - if (concreteTarget == null) { - return; - } - addCallToCG( - call.getSourceMethodSignature(), - concreteTarget, - call.getInvokableStmt(), - cg, - workList); + resolveConcreteDispatch(view, call.getTargetMethodSignature()) + .ifPresent( + concreteTarget -> + addCallToCG( + call.getSourceMethodSignature(), + concreteTarget, + call.getInvokableStmt(), + cg, + workList)); }); // can be removed because the instantiated class will be considered in future resolves ignoredCalls.remove(classType);