java.lang.reflect.Method.isAnnotationPresent()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(377)

本文整理了Java中java.lang.reflect.Method.isAnnotationPresent()方法的一些代码示例,展示了Method.isAnnotationPresent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.isAnnotationPresent()方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:isAnnotationPresent

Method.isAnnotationPresent介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

/** Returns true if the method includes an annotation of the provided class type. */
public boolean isAnnotationPresent (Class<? extends java.lang.annotation.Annotation> annotationType) {
  return method.isAnnotationPresent(annotationType);
}

代码示例来源:origin: libgdx/libgdx

/** Returns true if the method includes an annotation of the provided class type. */
public boolean isAnnotationPresent (Class<? extends java.lang.annotation.Annotation> annotationType) {
  return method.isAnnotationPresent(annotationType);
}

代码示例来源:origin: mrniko/netty-socketio

@Override
  public boolean matches(Method method) {
    for (Class<? extends Annotation> annotationClass : annotations) {
      if (method.isAnnotationPresent(annotationClass)) {
        return true;
      }
    }
    return false;
  }
});

代码示例来源:origin: org.mockito/mockito-core

public static boolean hasTestMethods(Class<?> klass) {
    Method[] methods = klass.getMethods();
    for(Method m:methods) {
      if (m.isAnnotationPresent(Test.class)) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: google/j2objc

public boolean hasTestMethods(Class<?> klass) {
    Method[] methods = klass.getMethods();
    for(Method m:methods) {
      if (m.isAnnotationPresent(Test.class)) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: spring-projects/spring-framework

private boolean matchesMethod(Method method) {
  return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(method, this.annotationType) :
      method.isAnnotationPresent(this.annotationType));
}

代码示例来源:origin: lets-blade/blade

private static void cacheMethod(Map<Class<? extends Annotation>, Method> cache, Method[] methods, Class<? extends Annotation> filter) {
  List<Method> methodList = Stream.of(methods)
      .filter(method -> method.isAnnotationPresent(filter))
      .collect(Collectors.toList());
  if (methodList.size() == 1) {
    cache.put(filter, methodList.get(0));
  } else if (methodList.size() > 1) {
    throw new RuntimeException("Duplicate annotation @" + filter.getSimpleName() + " in class: " + methodList.get(0).getDeclaringClass().getName());
  }
}

代码示例来源:origin: lets-blade/blade

private static void cacheMethod(Map<Class<? extends Annotation>, Method> cache, Method[] methods, Class<? extends Annotation> filter) {
  List<Method> methodList = Stream.of(methods)
      .filter(method -> method.isAnnotationPresent(filter))
      .collect(Collectors.toList());
  if (methodList.size() == 1) {
    cache.put(filter, methodList.get(0));
  } else if (methodList.size() > 1) {
    throw new RuntimeException("Duplicate annotation @" + filter.getSimpleName() + " in class: " + methodList.get(0).getDeclaringClass().getName());
  }
}

代码示例来源:origin: neo4j/neo4j

private String description( Method method )
{
  if ( method.isAnnotationPresent( Description.class ) )
  {
    return method.getAnnotation( Description.class ).value();
  }
  else
  {
    return null;
  }
}

代码示例来源:origin: google/guava

private static ImmutableList<Method> getAnnotatedMethodsNotCached(Class<?> clazz) {
 Set<? extends Class<?>> supertypes = TypeToken.of(clazz).getTypes().rawTypes();
 Map<MethodIdentifier, Method> identifiers = Maps.newHashMap();
 for (Class<?> supertype : supertypes) {
  for (Method method : supertype.getDeclaredMethods()) {
   if (method.isAnnotationPresent(Subscribe.class) && !method.isSynthetic()) {
    // TODO(cgdecker): Should check for a generic parameter type and error out
    Class<?>[] parameterTypes = method.getParameterTypes();
    checkArgument(
      parameterTypes.length == 1,
      "Method %s has @Subscribe annotation but has %s parameters."
        + "Subscriber methods must have exactly 1 parameter.",
      method,
      parameterTypes.length);
    MethodIdentifier ident = new MethodIdentifier(method);
    if (!identifiers.containsKey(ident)) {
     identifiers.put(ident, method);
    }
   }
  }
 }
 return ImmutableList.copyOf(identifiers.values());
}

代码示例来源:origin: spring-projects/spring-framework

private LifecycleMetadata buildLifecycleMetadata(final Class<?> clazz) {
  List<LifecycleElement> initMethods = new ArrayList<>();
  List<LifecycleElement> destroyMethods = new ArrayList<>();
  Class<?> targetClass = clazz;
  do {
    final List<LifecycleElement> currInitMethods = new ArrayList<>();
    final List<LifecycleElement> currDestroyMethods = new ArrayList<>();
    ReflectionUtils.doWithLocalMethods(targetClass, method -> {
      if (this.initAnnotationType != null && method.isAnnotationPresent(this.initAnnotationType)) {
        LifecycleElement element = new LifecycleElement(method);
        currInitMethods.add(element);
        if (logger.isTraceEnabled()) {
          logger.trace("Found init method on class [" + clazz.getName() + "]: " + method);
        }
      }
      if (this.destroyAnnotationType != null && method.isAnnotationPresent(this.destroyAnnotationType)) {
        currDestroyMethods.add(new LifecycleElement(method));
        if (logger.isTraceEnabled()) {
          logger.trace("Found destroy method on class [" + clazz.getName() + "]: " + method);
        }
      }
    });
    initMethods.addAll(0, currInitMethods);
    destroyMethods.addAll(currDestroyMethods);
    targetClass = targetClass.getSuperclass();
  }
  while (targetClass != null && targetClass != Object.class);
  return new LifecycleMetadata(clazz, initMethods, destroyMethods);
}

代码示例来源:origin: apache/incubator-dubbo

Method method = clazz.getMethod(methodName, parameterTypes);
Class<?>[] methodClasses = null;
if (method.isAnnotationPresent(MethodValidated.class)){
  methodClasses = method.getAnnotation(MethodValidated.class).value();
  groups.addAll(Arrays.asList(methodClasses));

代码示例来源:origin: apache/incubator-dubbo

Method method = clazz.getMethod(methodName, parameterTypes);
Class<?>[] methodClasses = null;
if (method.isAnnotationPresent(MethodValidated.class)){
  methodClasses = method.getAnnotation(MethodValidated.class).value();
  groups.addAll(Arrays.asList(methodClasses));

代码示例来源:origin: Graylog2/graylog2-server

@Override
  public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    final Class<?> resourceClass = resourceInfo.getResourceClass();
    final Method resourceMethod = resourceInfo.getResourceMethod();

    if (serverStatus.hasCapability(ServerStatus.Capability.MASTER))
      return;

    if (resourceMethod.isAnnotationPresent(RestrictToMaster.class) || resourceClass.isAnnotationPresent(RestrictToMaster.class)) {
      context.register(restrictToMasterFilter);
    }
  }
}

代码示例来源:origin: google/guava

final void testAllDeclarations() throws Exception {
 checkState(method == null);
 Method[] methods = getClass().getMethods();
 Arrays.sort(
   methods,
   new Comparator<Method>() {
    @Override
    public int compare(Method a, Method b) {
     return a.getName().compareTo(b.getName());
    }
   });
 for (Method method : methods) {
  if (method.isAnnotationPresent(TestSubtype.class)) {
   method.setAccessible(true);
   SubtypeTester tester = (SubtypeTester) clone();
   tester.method = method;
   method.invoke(tester, new Object[] {null});
  }
 }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return {@code true} if {@link Ignore @Ignore} is present for the supplied
 * {@linkplain FrameworkMethod test method} or if the test method is disabled
 * via {@code @IfProfileValue}.
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class)
 */
protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) {
  Method method = frameworkMethod.getMethod();
  return (method.isAnnotationPresent(Ignore.class) ||
      !ProfileValueUtils.isTestEnabledInThisEnvironment(method, getTestClass().getJavaClass()));
}

代码示例来源:origin: square/dagger

public ReflectiveProvidesBinding(Method method, String key, String moduleClass,
  Object instance, boolean library) {
 super(key, method.isAnnotationPresent(Singleton.class), moduleClass, method.getName());
 this.method = method;
 this.instance = instance;
 method.setAccessible(true);
 setLibrary(library);
}

代码示例来源:origin: ReactiveX/RxJava

boolean isAnnotationPresent = m.isAnnotationPresent(CheckReturnValue.class);

代码示例来源:origin: ReactiveX/RxJava

if (!m.isAnnotationPresent(SchedulerSupport.class)) {
  b.append("Missing @SchedulerSupport: ").append(m).append("\r\n");
} else {

代码示例来源:origin: ben-manes/caffeine

/** Checks the statistics if {@link CheckNoStats} is found. */
private static void checkNoStats(ITestResult testResult, CacheContext context) {
 Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod();
 boolean checkNoStats = testMethod.isAnnotationPresent(CheckNoStats.class);
 if (!checkNoStats) {
  return;
 }
 assertThat("Test requires CacheContext param for validation", context, is(not(nullValue())));
 assertThat(context, hasHitCount(0));
 assertThat(context, hasMissCount(0));
 assertThat(context, hasLoadSuccessCount(0));
 assertThat(context, hasLoadFailureCount(0));
}

相关文章

微信公众号

最新文章

更多