Skip to content

Commit

Permalink
Merge pull request #777 from Liyw979/feat_getmethod
Browse files Browse the repository at this point in the history
New API: get method by name
  • Loading branch information
JonasKlauke authored Dec 18, 2023
2 parents 89f4004 + 25d2a54 commit ad962f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sootup.core/src/main/java/sootup/core/model/AbstractClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.collect.Iterables;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import sootup.core.frontend.AbstractClassSource;
import sootup.core.frontend.ResolveException;
Expand Down Expand Up @@ -122,4 +123,18 @@ public Optional<? extends SootMethod> getMethod(
getClassSource().getSourcePath());
});
}

/**
* Attempts to retrieve the method with the given name. This method will return an empty Set if
* there is no method with the given name.
*
* @param name the name of the method
* @return a set of methods that have the given name
*/
@Nonnull
public Set<? extends SootMethod> getMethodsByName(@Nonnull String name) {
return this.getMethods().stream()
.filter(m -> m.getSignature().getName().equals(name))
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public Optional<JavaSootMethod> getMethod(
return (Optional<JavaSootMethod>) super.getMethod(name, parameterTypes);
}

@Nonnull
@Override
public Set<JavaSootMethod> getMethodsByName(@Nonnull String name) {
return (Set<JavaSootMethod>) super.getMethodsByName(name);
}

@Nonnull
@Override
public Optional<JavaSootMethod> getMethod(@Nonnull MethodSubSignature subSignature) {
Expand Down

0 comments on commit ad962f4

Please sign in to comment.