Skip to content

Commit

Permalink
Merge pull request #711 from Liyw979/allow_partial_analysis
Browse files Browse the repository at this point in the history
Allow partial analysis for CallGraphAlgorithm
  • Loading branch information
swissiety authored Oct 18, 2023
2 parents 5140a36 + 74da0de commit 68ce0a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected final <T extends Method> T findMethodInHierarchy(
if (optSc.isPresent()) {
SootClass<?> sc = optSc.get();

List<ClassType> superClasses = view.getTypeHierarchy().superClassesOf(sc.getType());
List<ClassType> superClasses = view.getTypeHierarchy().incompleteSuperClassesOf(sc.getType());
Set<ClassType> interfaces = view.getTypeHierarchy().implementedInterfacesOf(sc.getType());
superClasses.addAll(interfaces);

Expand Down Expand Up @@ -364,7 +364,7 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp
processWorkList(view, workList, processed, updated);

// Step 2: Add edges from old methods to methods overridden in the new class
List<ClassType> superClasses = view.getTypeHierarchy().superClassesOf(classType);
List<ClassType> superClasses = view.getTypeHierarchy().incompleteSuperClassesOf(classType);
Set<ClassType> implementedInterfaces =
view.getTypeHierarchy().implementedInterfacesOf(classType);
Stream<ClassType> superTypes =
Expand All @@ -376,7 +376,9 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp
.collect(Collectors.toSet());

superTypes
.map(view::getClassOrThrow)
.map(view::getClass)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(superType -> superType.getMethods().stream())
.map(Method::getSignature)
.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ default boolean isSubtype(@Nonnull Type supertype, @Nonnull Type potentialSubtyp
return (supertypeName.equals("java.lang.Object")
&& !potentialSubtypeName.equals("java.lang.Object"))
|| supertype.equals(superClassOf((ClassType) potentialSubtype))
|| superClassesOf((ClassType) potentialSubtype).contains(supertype)
|| incompleteSuperClassesOf((ClassType) potentialSubtype).contains(supertype)
|| implementedInterfacesOf((ClassType) potentialSubtype).contains(supertype);
} else if (potentialSubtype instanceof ArrayType) {
// Arrays are subtypes of java.lang.Object, java.io.Serializable and java.lang.Cloneable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ public synchronized Optional<JavaSootClass> getClass(@Nonnull ClassType type) {

Optional<? extends AbstractClassSource<? extends JavaSootClass>> abstractClass =
getAbstractClass(type);
if (!abstractClass.isPresent()) {
return Optional.empty();
}

return buildClassFrom(abstractClass.get());
return abstractClass.flatMap(this::buildClassFrom);
}

/** Returns the amount of classes that are currently stored in the cache. */
Expand Down

0 comments on commit 68ce0a6

Please sign in to comment.