當前位置: 首頁>>代碼示例>>Java>>正文


Java Method.isAnnotationPresent方法代碼示例

本文整理匯總了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;
}
 
開發者ID:GigaGamma,項目名稱:McLink,代碼行數:21,代碼來源:VCommand.java

示例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;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:18,代碼來源:AnnoUtil.java

示例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;
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:24,代碼來源:EventManager.java

示例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;
}
 
開發者ID:scify,項目名稱:jedai-ui,代碼行數:20,代碼來源:WizardController.java

示例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;
}
 
開發者ID:justice-code,項目名稱:QiuQiu,代碼行數:27,代碼來源:MapperAspect.java

示例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);
    }
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:21,代碼來源:Answer.java

示例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();
			}
		}
	}
}
 
開發者ID:biancso,項目名稱:Mevius-IO,代碼行數:24,代碼來源:MeviusHandler.java

示例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));
        }
    }
}
 
開發者ID:krix38,項目名稱:flowly,代碼行數:8,代碼來源:FlowRegister.java

示例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);
	}
}
  	
  }
 
開發者ID:smxc,項目名稱:garlicts,代碼行數:13,代碼來源:ControllerAbility.java

示例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;
}
 
開發者ID:GigaGamma,項目名稱:McLink,代碼行數:12,代碼來源:VItem.java

示例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 + " ??????????");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:JavacParserTest.java

示例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;
}
 
開發者ID:jweixin,項目名稱:jwx,代碼行數:15,代碼來源:WeixinMethod.java

示例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
}
 
開發者ID:Col-E,項目名稱:Recaf,代碼行數:17,代碼來源:Bus.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:32,代碼來源:AuthorizerFactory.java

示例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);
    }
}
 
開發者ID:meraki-analytics,項目名稱:datapipelines-java,代碼行數:28,代碼來源:AbstractDataTransformer.java


注:本文中的java.lang.reflect.Method.isAnnotationPresent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。