Codota Logo
Method.getAnnotation
Code IndexAdd Codota to your IDE (free)

How to use
getAnnotation
method
in
java.lang.reflect.Method

Best Java code snippets using java.lang.reflect.Method.getAnnotation (Showing top 20 results out of 25,632)

  • Common ways to obtain Method
private void myMethod () {
Method m =
  • Codota IconClass clazz;clazz.getMethod("<changeme>")
  • Codota IconClass clazz;String name;Class[] parameterTypes;clazz.getMethod(name, parameterTypes)
  • Codota IconPropertyDescriptor pd;pd.getReadMethod()
  • Smart code suggestions by Codota
}
origin: google/guava

/**
 * Checks whether {@code method} is thread-safe, as indicated by the presence of the {@link
 * AllowConcurrentEvents} annotation.
 */
private static boolean isDeclaredThreadSafe(Method method) {
 return method.getAnnotation(AllowConcurrentEvents.class) != null;
}
origin: spring-projects/spring-framework

protected <A extends Annotation> CacheMethodDetails<A> create(Class<A> annotationType,
    Class<?> targetType, String methodName,
    Class<?>... parameterTypes) {
  Method method = ReflectionUtils.findMethod(targetType, methodName, parameterTypes);
  Assert.notNull(method, "requested method '" + methodName + "'does not exist");
  A cacheAnnotation = method.getAnnotation(annotationType);
  return new DefaultCacheMethodDetails<>(method, cacheAnnotation, getCacheName(cacheAnnotation));
}
origin: spring-projects/spring-framework

@Test
public void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception {
  Class<ResponseEntityExceptionHandler> clazz = ResponseEntityExceptionHandler.class;
  Method handleExceptionMethod = clazz.getMethod("handleException", Exception.class, WebRequest.class);
  ExceptionHandler annotation = handleExceptionMethod.getAnnotation(ExceptionHandler.class);
  List<Class<?>> exceptionTypes = Arrays.asList(annotation.value());
  for (Method method : DefaultHandlerExceptionResolver.class.getDeclaredMethods()) {
    Class<?>[] paramTypes = method.getParameterTypes();
    if (method.getName().startsWith("handle") && (paramTypes.length == 4)) {
      String name = paramTypes[0].getSimpleName();
      assertTrue("@ExceptionHandler is missing " + name, exceptionTypes.contains(paramTypes[0]));
    }
  }
}
origin: spring-projects/spring-framework

@Test
public void localConfigWithDefaults() throws Exception {
  Method method = getClass().getMethod("localConfigMethodWithDefaults");
  SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
  MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
  assertDefaults(cfg);
}
origin: spring-projects/spring-framework

@Test
public void getAnnotationAttributesWithAttributeAliasesWithDifferentValues() throws Exception {
  exception.expect(AnnotationConfigurationException.class);
  exception.expectMessage(containsString("attribute 'value' and its alias 'path'"));
  exception.expectMessage(containsString("values of [{/enigma}] and [{/test}]"));
  Method method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes");
  WebMapping webMapping = method.getAnnotation(WebMapping.class);
  getAnnotationAttributes(webMapping);
}
origin: spring-projects/spring-framework

@Test
public void localConfigWithContinueOnError() throws Exception {
  Method method = getClass().getMethod("localConfigMethodWithContinueOnError");
  SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
  MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
  assertNotNull(cfg);
  assertEquals("errorMode", CONTINUE_ON_ERROR, cfg.getErrorMode());
}
origin: spring-projects/spring-framework

@Test
public void globalConfigWithDefaults() throws Exception {
  Method method = GlobalConfigWithDefaultsClass.class.getMethod("globalConfigMethod");
  SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
  MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, GlobalConfigWithDefaultsClass.class);
  assertDefaults(cfg);
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationWithMetaAnnotationOnLeaf() throws Exception {
  Method m = Leaf.class.getMethod("metaAnnotatedOnLeaf");
  assertNull(m.getAnnotation(Order.class));
  assertNotNull(getAnnotation(m, Order.class));
  assertNotNull(findAnnotation(m, Order.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationWithMetaMetaAnnotationOnLeaf() throws Exception {
  Method m = Leaf.class.getMethod("metaMetaAnnotatedOnLeaf");
  assertNull(m.getAnnotation(Component.class));
  assertNull(getAnnotation(m, Component.class));
  assertNotNull(findAnnotation(m, Component.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationWithMetaAnnotationOnRoot() throws Exception {
  Method m = Leaf.class.getMethod("metaAnnotatedOnRoot");
  assertNull(m.getAnnotation(Order.class));
  assertNotNull(getAnnotation(m, Order.class));
  assertNotNull(findAnnotation(m, Order.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationOnBridgedMethod() throws Exception {
  Method bridgedMethod = SimpleFoo.class.getMethod("something", String.class);
  assertFalse(bridgedMethod.isBridge());
  assertNull(bridgedMethod.getAnnotation(Order.class));
  assertNull(getAnnotation(bridgedMethod, Order.class));
  assertNotNull(findAnnotation(bridgedMethod, Order.class));
  assertNotNull(bridgedMethod.getAnnotation(Transactional.class));
  assertNotNull(getAnnotation(bridgedMethod, Transactional.class));
  assertNotNull(findAnnotation(bridgedMethod, Transactional.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationOnLeaf() throws Exception {
  Method m = Leaf.class.getMethod("annotatedOnLeaf");
  assertNotNull(m.getAnnotation(Order.class));
  assertNotNull(getAnnotation(m, Order.class));
  assertNotNull(findAnnotation(m, Order.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationWithAnnotationOnMethodInInterface() throws Exception {
  Method m = Leaf.class.getMethod("fromInterfaceImplementedByRoot");
  // @Order is not @Inherited
  assertNull(m.getAnnotation(Order.class));
  // getAnnotation() does not search on interfaces
  assertNull(getAnnotation(m, Order.class));
  // findAnnotation() does search on interfaces
  assertNotNull(findAnnotation(m, Order.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationOnRoot() throws Exception {
  Method m = Leaf.class.getMethod("annotatedOnRoot");
  assertNotNull(m.getAnnotation(Order.class));
  assertNotNull(getAnnotation(m, Order.class));
  assertNotNull(findAnnotation(m, Order.class));
}
origin: spring-projects/spring-framework

@Test
public void findMethodAnnotationOnRootButOverridden() throws Exception {
  Method m = Leaf.class.getMethod("overrideWithoutNewAnnotation");
  assertNull(m.getAnnotation(Order.class));
  assertNull(getAnnotation(m, Order.class));
  assertNotNull(findAnnotation(m, Order.class));
}
origin: spring-projects/spring-framework

@Test
public void localConfigWithIgnoreFailedDrops() throws Exception {
  Method method = getClass().getMethod("localConfigMethodWithIgnoreFailedDrops");
  SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
  MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
  assertNotNull(cfg);
  assertEquals("errorMode", IGNORE_FAILED_DROPS, cfg.getErrorMode());
}
origin: spring-projects/spring-framework

@Test
public void toStringForSynthesizedAnnotations() throws Exception {
  Method methodWithPath = WebController.class.getMethod("handleMappedWithPathAttribute");
  WebMapping webMappingWithAliases = methodWithPath.getAnnotation(WebMapping.class);
  assertNotNull(webMappingWithAliases);
  Method methodWithPathAndValue = WebController.class.getMethod("handleMappedWithSamePathAndValueAttributes");
  WebMapping webMappingWithPathAndValue = methodWithPathAndValue.getAnnotation(WebMapping.class);
  assertNotNull(webMappingWithPathAndValue);
  WebMapping synthesizedWebMapping1 = synthesizeAnnotation(webMappingWithAliases);
  assertNotNull(synthesizedWebMapping1);
  WebMapping synthesizedWebMapping2 = synthesizeAnnotation(webMappingWithAliases);
  assertNotNull(synthesizedWebMapping2);
  assertThat(webMappingWithAliases.toString(), is(not(synthesizedWebMapping1.toString())));
  assertToStringForWebMappingWithPathAndValue(synthesizedWebMapping1);
  assertToStringForWebMappingWithPathAndValue(synthesizedWebMapping2);
}
origin: spring-projects/spring-framework

protected DefaultCacheInvocationContext<?> createDummyContext() throws Exception {
  Method method = Sample.class.getMethod("get", String.class);
  CacheResult cacheAnnotation = method.getAnnotation(CacheResult.class);
  CacheMethodDetails<CacheResult> methodDetails =
      new DefaultCacheMethodDetails<>(method, cacheAnnotation, "test");
  CacheResultOperation operation = new CacheResultOperation(methodDetails,
      defaultCacheResolver, defaultKeyGenerator, defaultExceptionCacheResolver);
  return new DefaultCacheInvocationContext<>(operation, new Sample(), new Object[] {"id"});
}
origin: spring-projects/spring-framework

@Test
public void synthesizeAlreadySynthesizedAnnotation() throws Exception {
  Method method = WebController.class.getMethod("handleMappedWithValueAttribute");
  WebMapping webMapping = method.getAnnotation(WebMapping.class);
  assertNotNull(webMapping);
  WebMapping synthesizedWebMapping = synthesizeAnnotation(webMapping);
  assertNotSame(webMapping, synthesizedWebMapping);
  WebMapping synthesizedAgainWebMapping = synthesizeAnnotation(synthesizedWebMapping);
  assertThat(synthesizedAgainWebMapping, instanceOf(SynthesizedAnnotation.class));
  assertSame(synthesizedWebMapping, synthesizedAgainWebMapping);
  assertEquals("name attribute: ", "foo", synthesizedAgainWebMapping.name());
  assertArrayEquals("aliased path attribute: ", asArray("/test"), synthesizedAgainWebMapping.path());
  assertArrayEquals("actual value attribute: ", asArray("/test"), synthesizedAgainWebMapping.value());
}
origin: spring-projects/spring-framework

@Test
public void localConfigWithCustomValues() throws Exception {
  Method method = getClass().getMethod("localConfigMethodWithCustomValues");
  SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
  MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
  assertNotNull(cfg);
  assertEquals("dataSource", "ds", cfg.getDataSource());
  assertEquals("transactionManager", "txMgr", cfg.getTransactionManager());
  assertEquals("transactionMode", ISOLATED, cfg.getTransactionMode());
  assertEquals("encoding", "enigma", cfg.getEncoding());
  assertEquals("separator", "\n", cfg.getSeparator());
  assertEquals("commentPrefix", "`", cfg.getCommentPrefix());
  assertEquals("blockCommentStartDelimiter", "<<", cfg.getBlockCommentStartDelimiter());
  assertEquals("blockCommentEndDelimiter", ">>", cfg.getBlockCommentEndDelimiter());
  assertEquals("errorMode", IGNORE_FAILED_DROPS, cfg.getErrorMode());
}
java.lang.reflectMethodgetAnnotation

Popular methods of Method

  • invoke
    Returns the result of dynamically invoking this method. Equivalent to receiver.methodName(arg1, arg2
  • getName
  • getParameterTypes
  • getReturnType
  • setAccessible
  • getDeclaringClass
  • getModifiers
  • isAnnotationPresent
  • getGenericReturnType
    Returns the return type of this method as a Type instance.
  • getParameterAnnotations
  • getGenericParameterTypes
    Returns the parameter types as an array of Type instances, in declaration order. If this method has
  • isAccessible
  • getGenericParameterTypes,
  • isAccessible,
  • equals,
  • getAnnotations,
  • toString,
  • getExceptionTypes,
  • getParameterCount,
  • isBridge,
  • isSynthetic

Popular in Java

  • Finding current android device location
  • compareTo (BigDecimal)
  • findViewById (Activity)
  • putExtra (Intent)
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • ArrayList (java.util)
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
  • Timer (java.util)
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be s
  • TreeMap (java.util)
    A Red-Black tree based NavigableMap implementation. The map is sorted according to the Comparable of
  • JCheckBox (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now