Skip to content

Commit

Permalink
Make findMethodByUniqueName return value optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 24, 2024
1 parent 17cfd0b commit e61a58e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public static List<String> findLambdasInMethod(ClassNode cls, MethodNode method,
return list;
}

public static MethodNode findMethodByUniqueName(ClassNode cls, String name) {
public static Optional<MethodNode> findMethodByUniqueName(ClassNode cls, String name) {
List<MethodNode> methods = cls.methods.stream().filter(m -> m.name.equals(name)).toList();
if (methods.size() != 1) {
throw new IllegalStateException("Multiple candidates found for method " + name + " in class " + cls.name);
return Optional.empty();
}
return methods.getFirst();
return Optional.of(methods.getFirst());
}

public static Multimap<String, MethodInsnNode> getMethodCalls(MethodNode node, List<String> callOrder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ private static Patch.Result handleTargetModification(List<List<AbstractInsnNode>
for (List<AbstractInsnNode> insns : hunkLabels) {
for (AbstractInsnNode insn : insns) {
if (insn instanceof MethodInsnNode minsn && minsn.owner.equals(dirtyTarget.name)) {
MethodNode method = MethodCallAnalyzer.findMethodByUniqueName(dirtyTarget, minsn.name);
if (!methodContext.findInjectionTargetInsns(new MethodContext.TargetPair(dirtyTarget, method)).isEmpty()) {
MethodNode method = MethodCallAnalyzer.findMethodByUniqueName(dirtyTarget, minsn.name).orElse(null);
if (method != null && !methodContext.findInjectionTargetInsns(new MethodContext.TargetPair(dirtyTarget, method)).isEmpty()) {
return BundledMethodTransform.builder().modifyTarget(minsn.name + minsn.desc).apply(methodContext);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodCont
if (candidates.isEmpty()) {
List<MethodNode> nestedLambdas = invocations.stream()
.flatMap(m -> MethodCallAnalyzer.findLambdasInMethod(dirtyTargetClass, m, null).stream())
.map(s -> MethodCallAnalyzer.findMethodByUniqueName(dirtyTargetClass, s))
.flatMap(s -> MethodCallAnalyzer.findMethodByUniqueName(dirtyTargetClass, s).stream())
.toList();
candidates = findInsnsCalls(nestedLambdas, methodContext);
}
Expand Down

0 comments on commit e61a58e

Please sign in to comment.