1616
1717package org .dockbox .hartshorn .util .types ;
1818
19+ import org .dockbox .hartshorn .util .collections .GathererUtilities ;
20+ import org .dockbox .hartshorn .util .option .Option ;
21+
1922import java .io .IOException ;
2023import java .io .InputStream ;
2124import java .lang .classfile .Annotation ;
3336import java .util .List ;
3437import java .util .Map ;
3538import 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