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


Java Method.getAnnotation方法代碼示例

本文整理匯總了Java中java.lang.reflect.Method.getAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java Method.getAnnotation方法的具體用法?Java Method.getAnnotation怎麽用?Java Method.getAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getAnnotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: LevelDListener

import java.lang.reflect.Method; //導入方法依賴的package包/類
public LevelDListener(Method method) {
	NullCheck.check(method, "method");
	this.method = method; 
	
	// check the annotation
	if (getAnnotation() == null) {
		throw new ListenerMethodParametersException(method, "There is no ObjectListener annotation on the method!", AnnotationListenerRegistrator.this);				
	}
	
	// check the method signature
	if (method.getParameterTypes().length != 1 ||
	    !method.getParameterTypes()[0].isAssignableFrom(IWorldObjectEvent.class)) { 
		throw new ListenerMethodParametersException(method, method.getAnnotation(ObjectListener.class), AnnotationListenerRegistrator.this);
	}
	
	objectId = getId(method, getAnnotation());
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:18,代碼來源:AnnotationListenerRegistrator.java

示例2: run

import java.lang.reflect.Method; //導入方法依賴的package包/類
@Override
public void run() {
    // 獲取日誌標題
    if (StringUtils.isBlank(log.getTitle())) {
        String permission = "";
        if (handler instanceof HandlerMethod) {
            Method m = ((HandlerMethod) handler).getMethod();
            RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class);
            permission = (rp != null ? StringUtils.join(rp.value(), ",") : "");
        }
    }
    // 如果有異常,設置異常信息
    log.setException(Exceptions.getStackTraceAsString(ex));
    // 如果無標題並無異常日誌,則不保存信息
    if (StringUtils.isBlank(log.getTitle()) && StringUtils.isBlank(log.getException())) {
        return;
    }
    logService.insert(log);
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:20,代碼來源:LogUtils.java

示例3: test

import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
 * Tests a specific file manager, by calling all methods annotated
 * with {@code @Test} passing this file manager as an argument.
 *
 * @param fm the file manager to be tested
 * @throws Exception if the test fails
 */
void test(StandardJavaFileManager fm) throws Exception {
    System.err.println("Testing " + fm);
    for (Method m: getClass().getDeclaredMethods()) {
        Annotation a = m.getAnnotation(Test.class);
        if (a != null) {
            try {
                System.err.println("Test " + m.getName());
                m.invoke(this, new Object[] { fm });
            } catch (InvocationTargetException e) {
                Throwable cause = e.getCause();
                throw (cause instanceof Exception) ? ((Exception) cause) : e;
            }
            System.err.println();
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:SJFM_TestBase.java

示例4: findShardMethodsAndRegist

import java.lang.reflect.Method; //導入方法依賴的package包/類
public static Set<Method> findShardMethodsAndRegist(String fullClassName,Class<? extends Annotation> anno,boolean check) throws ClassNotFoundException {
    Set<Method> methodSet = new HashSet<Method>();
    Class<?> clz = Class.forName(fullClassName);
    Method[] methods = clz.getDeclaredMethods();
    for (Method method : methods) {
        int modifiers = method.getModifiers();
        if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
            continue;
        }
        Annotation annotation = method.getAnnotation(anno);
        
        String statementId = fullClassName + DIAN + method.getName();
        
        if (annotation != null) {
            if (check) {
                Method checkExists = ShardMethodFactory.getStatementMethodById(statementId);
                if (checkExists!=null) {
                    throw new IllegalArgumentException(" duplicate key : "+statementId);
                }
            }
            ShardMethodFactory.regMethod(statementId, method);
            methodSet.add(method);
        }
    }
    return methodSet;
}
 
開發者ID:devpage,項目名稱:sharding-quickstart,代碼行數:27,代碼來源:PackageUtil.java

示例5: getTransit

import java.lang.reflect.Method; //導入方法依賴的package包/類
private Transit getTransit(final Method method) {
    final Annotation annotation = method.getAnnotation(Ipc.class);
    // 1. Check only one is enough because of Error-40043
    // 2. to and from must not be null at the same time because of Error-40045
    final String to = Instance.invoke(annotation, "to");
    final Transit transit;
    if (StringUtil.isNil(to)) {
        // Node transit
        transit = Instance.singleton(FinalTransit.class);
        LOGGER.info(Info.NODE_FINAL, method, method.getDeclaringClass());
    } else {
        // Final transit
        transit = Instance.singleton(NodeTransit.class);
        LOGGER.info(Info.NODE_MIDDLE, method, method.getDeclaringClass());
    }
    // Connect for transit
    transit.connect(method);
    return transit;
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:20,代碼來源:UnityTunnel.java

示例6: determineAndroidExecutionScope

import java.lang.reflect.Method; //導入方法依賴的package包/類
protected AndroidExecutionScope determineAndroidExecutionScope(Class<?> clazz, String methodName, Class<?> ... arguments) {
	ExecutionScope scope = null;
	
	if (methodName != null) {
		try {
			Method method = clazz.getMethod(methodName, arguments);
			scope = method.getAnnotation(ExecutionScope.class);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException(e);
		}
	}
	if (scope == null) {
		scope = clazz.getAnnotation(ExecutionScope.class);
	}
	
	return scope == null ? defaultAndroidExecutionScope : scope.value();
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:18,代碼來源:AndroidDeferredObject.java

示例7: unregisterCommands

import java.lang.reflect.Method; //導入方法依賴的package包/類
public void unregisterCommands(Object obj) {
    for (Method m : obj.getClass().getMethods()) {
        if (m.getAnnotation(Command.class) != null) {
            Command command = m.getAnnotation(Command.class);
            this.commandMap.remove(command.name().toLowerCase());
            this.commandMap.remove(this.plugin.getName() + ":" + command.name().toLowerCase());
            this.map.getCommand(command.name().toLowerCase()).unregister(this.map);
        }
    }
}
 
開發者ID:ijoeleoli,項目名稱:ServerCommons,代碼行數:11,代碼來源:CommandFramework.java

示例8: run

import java.lang.reflect.Method; //導入方法依賴的package包/類
/** Invoke all methods annotated with @Test. */
protected void run() throws Exception {
    for (Method m: getClass().getDeclaredMethods()) {
        Annotation a = m.getAnnotation(Test.class);
        if (a != null) {
            testCount++;
            testName = m.getName();
            System.err.println("test: " + testName);
            try {
                m.invoke(this, new Object[] { });
            } catch (InvocationTargetException e) {
                Throwable cause = e.getCause();
                throw (cause instanceof Exception) ? ((Exception) cause) : e;
            }
            System.err.println();
        }
    }

    if (testCount == 0)
        error("no tests found");

    StringBuilder summary = new StringBuilder();
    if (testCount != 1)
        summary.append(testCount).append(" tests");
    if (errorCount > 0) {
        if (summary.length() > 0) summary.append(", ");
        summary.append(errorCount).append(" errors");
    }
    System.err.println(summary);
    if (errorCount > 0)
        throw new Exception(errorCount + " errors found");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:APITest.java

示例9: getStrutsActions

import java.lang.reflect.Method; //導入方法依賴的package包/類
private Map<String, String> getStrutsActions(Object proxy, Class<? extends LocalizedLookupDispatchAction> apply) throws Throwable {
	Map<String, String> ret = new HashMap<String, String>();
	for (Method m: iMessages.getDeclaredMethods()) {
		if (m.getParameterTypes().length > 0) continue;
		org.unitime.localization.messages.Messages.StrutsAction action = m.getAnnotation(org.unitime.localization.messages.Messages.StrutsAction.class);
		if (action != null) {
			Messages.DefaultMessage dm = m.getAnnotation(Messages.DefaultMessage.class);
			if (action.apply() == null || action.apply().length == 0) {
				try {
					if (apply.getMethod(action.value(), new Class<?>[] {
						ActionMapping.class, ActionForm.class, HttpServletRequest.class, HttpServletResponse.class
						}) != null) {
						ret.put((String)invoke(proxy, m, new Object[] {}), action.value());
						if (dm != null)
							ret.put(dm.value(), action.value());
					}
				} catch (NoSuchMethodException e) {}
			} else {
				for (Class<? extends LocalizedLookupDispatchAction> a: action.apply())
					if (a.equals(apply)) {
						ret.put((String)invoke(proxy, m, new Object[] {}), action.value());
						if (dm != null)
							ret.put(dm.value(), action.value());
					}
			}
		}
	}
	return ret;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:30,代碼來源:Localization.java

示例10: infoMethods

import java.lang.reflect.Method; //導入方法依賴的package包/類
public static Map<String, Method> infoMethods(Class<?> c) {
    Map<String, Method> mets = new TreeMap<String, Method>();
    for (Method met : c.getMethods()) {
        InfoName name = met.getAnnotation(InfoName.class);
        if (name == null) {
            continue;
        }
        mets.put(name.value(), met);
    }
    return mets;
}
 
開發者ID:adnanmitf09,項目名稱:Rubus,代碼行數:12,代碼來源:HardwareReport.java

示例11: testInvalidMethodTestLoggingAnnotation

import java.lang.reflect.Method; //導入方法依賴的package包/類
public void testInvalidMethodTestLoggingAnnotation() throws Exception {
    final LoggingListener loggingListener = new LoggingListener();

    final Description suiteDescription = Description.createSuiteDescription(InvalidMethod.class);

    loggingListener.testRunStarted(suiteDescription);

    final Method method = InvalidMethod.class.getMethod("invalidMethod");
    final TestLogging annotation = method.getAnnotation(TestLogging.class);
    Description testDescription = Description.createTestDescription(InvalidMethod.class, "invalidMethod", annotation);
    final IllegalArgumentException e =
        expectThrows(IllegalArgumentException.class, () -> loggingListener.testStarted(testDescription));
    assertThat(e.getMessage(), equalTo("invalid test logging annotation [abc:INFO:WARN]"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:LoggingListenerTests.java

示例12: getMockObject

import java.lang.reflect.Method; //導入方法依賴的package包/類
public Mock getMockObject(String url){
    for (Map serviceMethodCache:mVector) {

        for (Object entry:serviceMethodCache.keySet()){
            Object o = serviceMethodCache.get(entry);
            try {

                if (mUrlAragsMap.containsKey(url)){
                    Object[] args = (Object[]) mUrlAragsMap.get(url);
                    String reqUrl =  buildRequestUrl(o,args);
                    if (reqUrl.equals(url)){
                        Method m = (Method) entry;
                        Mock mock =  m.getAnnotation(Mock.class);
                        if (mock!=null){
                            return  mock;
                        }
                        return null;
                    }
                }
            } catch (Exception e) {
                LogUtil.l(e);
            }
        }
    }

    return null;
}
 
開發者ID:yale8848,項目名稱:RetrofitCache,代碼行數:28,代碼來源:RetrofitCache.java

示例13: getOptions

import java.lang.reflect.Method; //導入方法依賴的package包/類
private Map<String,Method> getOptions() {
	Map<String,Method> result = new TreeMap<String,Method>();
	Class<?> klass = getClass();
	Class<CLIOption> optionClass = CLIOption.class;
	for (Method meth : klass.getMethods()) {
		if (!meth.isAnnotationPresent(optionClass))
			continue;
		CLIOption annotation = meth.getAnnotation(optionClass);
		String option = annotation.value();
		if (result.containsKey(option))
			throw new RuntimeException("duplicate option " + option);
		result.put(option, meth);
	}
	return result;
}
 
開發者ID:Bibliome,項目名稱:bibliome-java-utils,代碼行數:16,代碼來源:CLIOParser.java

示例14: getSupperMethodAnnotation

import java.lang.reflect.Method; //導入方法依賴的package包/類
public static JSONField getSupperMethodAnnotation(Class<?> clazz, Method method) {
    for (Class<?> interfaceClass : clazz.getInterfaces()) {
        for (Method interfaceMethod : interfaceClass.getMethods()) {
            if (!interfaceMethod.getName().equals(method.getName())) {
                continue;
            }

            if (interfaceMethod.getParameterTypes().length != method.getParameterTypes().length) {
                continue;
            }

            boolean match = true;
            for (int i = 0; i < interfaceMethod.getParameterTypes().length; ++i) {
                if (!interfaceMethod.getParameterTypes()[i].equals(method.getParameterTypes()[i])) {
                    match = false;
                    break;
                }
            }

            if (!match) {
                continue;
            }

            JSONField annotation = interfaceMethod.getAnnotation(JSONField.class);
            if (annotation != null) {
                return annotation;
            }
        }
    }

    return null;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:33,代碼來源:TypeUtils.java

示例15: getAllAvalibleMethods

import java.lang.reflect.Method; //導入方法依賴的package包/類
public ArrayList<String> getAllAvalibleMethods()
{
	ArrayList<String> stringList = new ArrayList<>();
	for(Method method : HarshenCastleCommands.class.getMethods())
		if(method.getAnnotation(HarshenCommand.class) != null)
			stringList.add(method.getName());
	return stringList;
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:9,代碼來源:CommandHarshenCastleLoader.java


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