Skip to content

Commit 4f87aec

Browse files
committed
#932 Add missing documentation for ClassFileUtilities#getMethod
1 parent 5fdeb1c commit 4f87aec

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

hartshorn-shared/src/main/java/org/dockbox/hartshorn/util/types/ClassFileUtilities.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.dockbox.hartshorn.util.types;
1818

19+
import org.dockbox.hartshorn.util.collections.GathererUtilities;
20+
import org.dockbox.hartshorn.util.option.Option;
21+
1922
import java.io.IOException;
2023
import java.io.InputStream;
2124
import java.lang.classfile.Annotation;
@@ -33,8 +36,6 @@
3336
import java.util.List;
3437
import java.util.Map;
3538
import java.util.stream.Collectors;
36-
import org.dockbox.hartshorn.util.collections.GathererUtilities;
37-
import org.dockbox.hartshorn.util.option.Option;
3839

3940
/**
4041
* Utility class for working with Java's {@link ClassFile} API, primarily focused on extracting
@@ -89,7 +90,22 @@ public static Option<ClassModel> getClassModel(String resourceOrClassName) {
8990
}
9091
}
9192

92-
public static Option<MethodModel> getMethod(ClassModel model, String name, Class<?>... parameterTypes) {
93+
/**
94+
* Get a specific method from a {@link ClassModel} by its name and parameter types. The method
95+
* must have exactly the same name and parameter types as specified, otherwise an empty
96+
* {@link Option} is returned.
97+
*
98+
* @param model the {@link ClassModel} to search for the method
99+
* @param name the name of the method to look for
100+
* @param parameterTypes the parameter types of the method to look for
101+
* @return an {@link Option} containing the {@link MethodModel} if found, otherwise an empty
102+
* {@link Option}
103+
*/
104+
public static Option<MethodModel> getMethod(
105+
ClassModel model,
106+
String name,
107+
Class<?>... parameterTypes
108+
) {
93109
methods:
94110
for (MethodModel method : model.methods()) {
95111
if (!method.methodName().equalsString(name)) {
@@ -102,7 +118,10 @@ public static Option<MethodModel> getMethod(ClassModel model, String name, Class
102118
ClassDesc[] parameters = descriptor.parameterArray();
103119
for (int i = 0; i < parameters.length; i++) {
104120
ClassDesc parameter = parameters[i];
105-
if (!matchesConstantPoolName(parameter.descriptorString(), parameterTypes[i].getName())) {
121+
if (!matchesConstantPoolName(
122+
parameter.descriptorString(),
123+
parameterTypes[i].getName()
124+
)) {
106125
continue methods;
107126
}
108127
}

0 commit comments

Comments
 (0)