/** 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); }
/** 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); }
@Override public boolean matches(Method method) { for (Class<? extends Annotation> annotationClass : annotations) { if (method.isAnnotationPresent(annotationClass)) { return true; } } return false; } });
public static boolean hasTestMethods(Class<?> klass) { Method[] methods = klass.getMethods(); for(Method m:methods) { if (m.isAnnotationPresent(Test.class)) { return true; } } return false; } }
public boolean hasTestMethods(Class<?> klass) { Method[] methods = klass.getMethods(); for(Method m:methods) { if (m.isAnnotationPresent(Test.class)) { return true; } } return false; } }
private boolean matchesMethod(Method method) { return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(method, this.annotationType) : method.isAnnotationPresent(this.annotationType)); }
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()); } }
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()); } }
private String description( Method method ) { if ( method.isAnnotationPresent( Description.class ) ) { return method.getAnnotation( Description.class ).value(); } else { return null; } }
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()); }
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); }
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));
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));
@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); } } }
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}); } } }
/** * 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())); }
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); }
boolean isAnnotationPresent = m.isAnnotationPresent(CheckReturnValue.class);
if (!m.isAnnotationPresent(SchedulerSupport.class)) { b.append("Missing @SchedulerSupport: ").append(m).append("\r\n"); } else {
/** 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)); }