本文整理汇总了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());
}
示例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);
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
}
示例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");
}
示例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;
}
示例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;
}
示例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]"));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}