-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from stick-i/v0.0.3-beta
V0.0.3 beta
- Loading branch information
Showing
5 changed files
with
63 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/cn/sticki/validator/spel/manager/AnnotationMethodManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cn.sticki.validator.spel.manager; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* 注解类方法管理器。 | ||
* | ||
* @author 阿杆 | ||
* @version 1.0 | ||
* @since 2024/5/9 | ||
*/ | ||
public class AnnotationMethodManager { | ||
|
||
private final static ConcurrentHashMap<String, Method> METHOD_CACHE = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* 获取方法。 | ||
* | ||
* @param clazz 注解类 | ||
* @param methodName 方法名 | ||
* @return 方法,如果不存在则返回null | ||
*/ | ||
public static Method get(Class<? extends Annotation> clazz, String methodName) { | ||
// 由于注解类的方法无法重载,可以通过注解类和方法名来唯一确定一个方法 | ||
return METHOD_CACHE.computeIfAbsent(clazz.toString() + methodName, s -> { | ||
try { | ||
return clazz.getMethod(methodName); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
} |