本文整理汇总了Java中java.lang.reflect.Method.isAnnotationPresent方法的典型用法代码示例。如果您正苦于以下问题:Java Method.isAnnotationPresent方法的具体用法?Java Method.isAnnotationPresent怎么用?Java Method.isAnnotationPresent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Method
的用法示例。
在下文中一共展示了Method.isAnnotationPresent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public boolean execute(CommandSender arg0, String arg1, String[] arg2) {
for (Method m : c.getDeclaredMethods()) {
if (m.isAnnotationPresent(Command.Subcommand.class) && CommandConstruct.match(arg2, m.getAnnotation(Command.Subcommand.class).args())) {
try {
if (m.getAnnotation(Command.Subcommand.class).permission().equals("_")) {
m.invoke(ins, arg0, arg1, arg2);
return true;
} else if (arg0.hasPermission(m.getAnnotation(Command.Subcommand.class).permission())) {
m.invoke(ins, arg0, arg1, arg2);
return true;
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {e.printStackTrace();}
}
}
arg0.sendMessage(CommandConstruct.getNoArgsMessage());
return true;
}
示例2: isAnnotationPresent
import java.lang.reflect.Method; //导入方法依赖的package包/类
private static boolean isAnnotationPresent(boolean isAll, Method method, Class<? extends Annotation>... annotationClasses)
{
for (Class c : annotationClasses)
{
if (method.isAnnotationPresent(c))
{
if (!isAll)
{
return true;
}
} else if (isAll)
{
return false;
}
}
return isAll;
}
示例3: registerEventSubscribers
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Register objects that have methods annotated as EventSubscriber.
*
* @param subscribers The subscribers object
* @return EventManager for chaining.
*/
@SuppressWarnings("unchecked")
public EventManager registerEventSubscribers(Object... subscribers) {
this.subscribers.addAll(Arrays.asList(subscribers));
for (Object obj : subscribers) {
for (Method method : obj.getClass().getMethods()) {
if (method.isAnnotationPresent(EventSubscriber.class)) {
Class<?>[] parameters = method.getParameterTypes();
if (parameters.length == 1 && Event.class.isAssignableFrom(parameters[0])) {
Class<? extends Event> event = (Class<? extends Event>) parameters[0];
methods.put(method, new MethodContainer(obj, event));
}
}
}
}
return this;
}
示例4: getMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
private Method getMethod(Class<? extends Annotation> an, Object obj) {
if (an == null) {
return null;
}
if (obj == null) {
return null;
}
Method[] methods = obj.getClass().getMethods();
if (methods != null && methods.length > 0) {
for (Method m : methods) {
if (m.isAnnotationPresent(an)) {
return m;
}
}
}
return null;
}
示例5: around
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Around("mapperCheckPoint()")
private Object around(ProceedingJoinPoint point) throws Throwable {
if(! check(point)) {
return point.proceed();
}
if (! (point.getSignature() instanceof MethodSignature)) {
return point.proceed();
}
MethodSignature methodSignature = (MethodSignature) point.getSignature();
Method method = methodSignature.getMethod();
if (! method.isAnnotationPresent(KeyParam.class)) {
return point.proceed();
}
KeyParam keyParam = method.getAnnotation(KeyParam.class);
String[] ognl = keyParam.value();
String mapper = method.getDeclaringClass().getSimpleName() + "." + method.getName();
RequestHolder.initRequestHolder(mapper, ognl);
Object result = point.proceed();
RequestHolder.resetRequest();
return result;
}
示例6: storeSession
import java.lang.reflect.Method; //导入方法依赖的package包/类
private static <T> void storeSession(
final RoutingContext context,
final T data,
final Method method
) {
final Session session = context.session();
if (null != session && null != data && method.isAnnotationPresent(SessionData.class)) {
final Annotation annotation = method.getAnnotation(SessionData.class);
final String key = Instance.invoke(annotation, "value");
final String field = Instance.invoke(annotation, "field");
// Data Storage
Object reference = data;
if (Types.isJObject(data) && StringUtil.notNil(field)) {
final JsonObject target = (JsonObject) data;
reference = target.getValue(field);
}
// Session Put
session.put(key, reference);
}
}
示例7: callEvent
import java.lang.reflect.Method; //导入方法依赖的package包/类
public final void callEvent(PacketEvent event) {
for (PacketListener listener : packetlisteners) {
for (Method m : listener.getClass().getMethods()) {
if (!m.isAnnotationPresent(PacketHandler.class))
continue;
if (m.getParameterTypes().length != 1)
continue;
Class<?> clazz = m.getParameterTypes()[0];
if (!clazz.equals(event.getClass()) && !clazz.equals(PacketEvent.class))
continue;
PacketHandler ph = m.getAnnotation(PacketHandler.class);
if (!ph.value().equals(event.getEventType()) && !ph.value().equals(PacketEventType.ALL))
continue;
try {
m.setAccessible(true);
m.invoke(listener, event);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
示例8: register
import java.lang.reflect.Method; //导入方法依赖的package包/类
public <T> void register(Class<T> tClass){
for(Method method : tClass.getDeclaredMethods()){
if(method.isAnnotationPresent(FlowAction.class)){
actions.add(new Action(tClass, method));
}
}
}
示例9: handleActionMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void handleActionMethod(Class<?> controllerClass, Method controllerMethod, Map<Requestor, Handler> commonControllerMap, Map<Requestor, Handler> regexpControllerMap) {
// 判断当前 Action 方法是否带有 RequestMapping 注解
if (controllerMethod.isAnnotationPresent(RequestMapping.class)) {
String requestPath = controllerMethod.getAnnotation(RequestMapping.class).value();
RequestMethod requestMethod[] = controllerMethod.getAnnotation(RequestMapping.class).method();
for(RequestMethod e : requestMethod){
putActionMap(e.name(), requestPath, controllerClass, controllerMethod, commonControllerMap, regexpControllerMap);
}
}
}
示例10: getActions
import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Map<Item.ActionType, Method> getActions(Class<?> c) {
Map<Item.ActionType, Method> a = new HashMap<Item.ActionType, Method>();
for (Method m : c.getMethods()) {
if (m.isAnnotationPresent(Item.Action.class)) {
a.put(m.getAnnotation(Item.Action.class).type(), m);
}
}
return a;
}
示例11: run
import java.lang.reflect.Method; //导入方法依赖的package包/类
void run(String[] args) throws Exception {
int passed = 0, failed = 0;
final Pattern p = (args != null && args.length > 0)
? Pattern.compile(args[0])
: null;
for (Method m : this.getClass().getDeclaredMethods()) {
boolean selected = (p == null)
? m.isAnnotationPresent(Test.class)
: p.matcher(m.getName()).matches();
if (selected) {
try {
m.invoke(this, (Object[]) null);
System.out.println(m.getName() + ": OK");
passed++;
} catch (Throwable ex) {
System.out.printf("Test %s failed: %s %n", m, ex.getCause());
failed++;
}
}
}
System.out.printf("Passed: %d, Failed %d%n", passed, failed);
if (failed > 0) {
throw new RuntimeException("Tests failed: " + failed);
}
if (passed == 0 && failed == 0) {
throw new AssertionError("No test(s) selected: passed = " +
passed + ", failed = " + failed + " ??????????");
}
}
示例12: hasWeixinAnnotationType
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* 判断方法是否有合法的微信注解
* @param method
* @return
*/
public static boolean hasWeixinAnnotationType(Method method){
for(Class<? extends Annotation> at : weixinAnnotationTypes){
if(method.isAnnotationPresent(at)){
return true;
}
}
return false;
}
示例13: isValid
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Check if method can listen to events,
*
* @param method
* @return
*/
private boolean isValid(Method method) {
//@formatter:off
return
// Check parameter for event type
method.getParameterCount() == 1 &&
Event.class.isAssignableFrom(method.getParameterTypes()[0]) &&
// Check if listener annotation exists
method.isAnnotationPresent(Listener.class);
//@formatter:on
}
示例14: performMethodInjection
import java.lang.reflect.Method; //导入方法依赖的package包/类
private void performMethodInjection(final Object instance, final Class authorizerClass) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
for (final Method method : authorizerClass.getMethods()) {
if (method.isAnnotationPresent(AuthorizerContext.class)) {
// make the method accessible
final boolean isAccessible = method.isAccessible();
method.setAccessible(true);
try {
final Class<?>[] argumentTypes = method.getParameterTypes();
// look for setters (single argument)
if (argumentTypes.length == 1) {
final Class<?> argumentType = argumentTypes[0];
// look for well known types
if (NiFiRegistryProperties.class.isAssignableFrom(argumentType)) {
// nifi properties injection
method.invoke(instance, properties);
}
}
} finally {
method.setAccessible(isAccessible);
}
}
}
final Class parentClass = authorizerClass.getSuperclass();
if (parentClass != null && Authorizer.class.isAssignableFrom(parentClass)) {
performMethodInjection(instance, parentClass);
}
}
示例15: initialize
import java.lang.reflect.Method; //导入方法依赖的package包/类
private void initialize() {
synchronized(initLock) {
if(transformMethods != null) {
return;
}
final Class<? extends AbstractDataTransformer> clazz = this.getClass();
transformMethods = new HashMap<>();
for(final Method method : clazz.getMethods()) {
if(method.isAnnotationPresent(Transform.class)) {
final Transform annotation = method.getAnnotation(Transform.class);
Map<Class<?>, Method> from = transformMethods.get(annotation.from());
if(from == null) {
from = new HashMap<>();
transformMethods.put(annotation.from(), from);
}
from.put(annotation.to(), method);
}
}
transformMethods = Collections.unmodifiableMap(transformMethods);
}
}