From f2f197fcffb31aca2ce6d26288dd9c8ffd5f76c8 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Sun, 17 Dec 2023 18:59:11 +0800 Subject: [PATCH 1/3] get method by just name --- .../main/java/sootup/core/model/AbstractClass.java | 12 ++++++++++++ .../main/java/sootup/java/core/JavaSootClass.java | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/sootup.core/src/main/java/sootup/core/model/AbstractClass.java b/sootup.core/src/main/java/sootup/core/model/AbstractClass.java index b16e5be9f48..d86afa05725 100644 --- a/sootup.core/src/main/java/sootup/core/model/AbstractClass.java +++ b/sootup.core/src/main/java/sootup/core/model/AbstractClass.java @@ -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; @@ -122,4 +123,15 @@ public Optional 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. + */ + @Nonnull + public Set getMethod(@Nonnull String name) { + return this.getMethods().stream() + .filter(m -> m.getSignature().getName().equals(name)) + .collect(Collectors.toSet()); + } } diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java index 1d30b1c0342..2edc410f304 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java @@ -128,6 +128,12 @@ public Optional getMethod( return (Optional) super.getMethod(name, parameterTypes); } + @Nonnull + @Override + public Set getMethod(@Nonnull String name) { + return (Set) super.getMethod(name); + } + @Nonnull @Override public Optional getMethod(@Nonnull MethodSubSignature subSignature) { From 3cf68dea3f0fb0c560968c68625725263cee3a73 Mon Sep 17 00:00:00 2001 From: Liyw <979621500@qq.com> Date: Mon, 18 Dec 2023 22:52:53 +0800 Subject: [PATCH 2/3] Update sootup.core/src/main/java/sootup/core/model/AbstractClass.java Co-authored-by: Jonas Klauke <97177448+JonasKlauke@users.noreply.github.com> --- sootup.core/src/main/java/sootup/core/model/AbstractClass.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sootup.core/src/main/java/sootup/core/model/AbstractClass.java b/sootup.core/src/main/java/sootup/core/model/AbstractClass.java index d86afa05725..14b7c5e8d3b 100644 --- a/sootup.core/src/main/java/sootup/core/model/AbstractClass.java +++ b/sootup.core/src/main/java/sootup/core/model/AbstractClass.java @@ -127,6 +127,8 @@ public Optional getMethod( /** * 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 getMethod(@Nonnull String name) { From 25d2a54fdc3d2f375e78ec904f4746a0b48509f1 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Mon, 18 Dec 2023 22:56:26 +0800 Subject: [PATCH 3/3] rename --- .../src/main/java/sootup/core/model/AbstractClass.java | 3 ++- .../src/main/java/sootup/java/core/JavaSootClass.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/model/AbstractClass.java b/sootup.core/src/main/java/sootup/core/model/AbstractClass.java index 14b7c5e8d3b..cf6b818fceb 100644 --- a/sootup.core/src/main/java/sootup/core/model/AbstractClass.java +++ b/sootup.core/src/main/java/sootup/core/model/AbstractClass.java @@ -127,11 +127,12 @@ public Optional getMethod( /** * 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 getMethod(@Nonnull String name) { + public Set getMethodsByName(@Nonnull String name) { return this.getMethods().stream() .filter(m -> m.getSignature().getName().equals(name)) .collect(Collectors.toSet()); diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java index 2edc410f304..de4945dad64 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java @@ -130,8 +130,8 @@ public Optional getMethod( @Nonnull @Override - public Set getMethod(@Nonnull String name) { - return (Set) super.getMethod(name); + public Set getMethodsByName(@Nonnull String name) { + return (Set) super.getMethodsByName(name); } @Nonnull