java类java.lang.annotation.Retention的实例源码

JavaClassTest.java 文件源码 项目:ArchUnit 阅读 39 收藏 0 点赞 0 评论 0
@Test
public void isAnnotatedWith_typeName() {
    assertThat(importClassWithContext(Parent.class).isAnnotatedWith(SomeAnnotation.class.getName()))
            .as("Parent is annotated with @" + SomeAnnotation.class.getSimpleName()).isTrue();
    assertThat(importClassWithContext(Parent.class).isAnnotatedWith(Retention.class.getName()))
            .as("Parent is annotated with @" + Retention.class.getSimpleName()).isFalse();
}
AnnotationProxyTest.java 文件源码 项目:ArchUnit 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void wrong_annotation_type_is_rejected() {
    JavaAnnotation mismatch = javaAnnotationFrom(TestAnnotation.class.getAnnotation(Retention.class));

    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage(Retention.class.getSimpleName());
    thrown.expectMessage(TestAnnotation.class.getSimpleName());
    thrown.expectMessage("incompatible");
    AnnotationProxy.of(TestAnnotation.class, mismatch);
}
JavaMemberTest.java 文件源码 项目:ArchUnit 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void isAnnotatedWith_type() {
    assertThat(importField(SomeClass.class, "someField").isAnnotatedWith(Deprecated.class))
            .as("field is annotated with @Deprecated").isTrue();
    assertThat(importField(SomeClass.class, "someField").isAnnotatedWith(Retention.class))
            .as("field is annotated with @Retention").isFalse();
}
JavaMemberTest.java 文件源码 项目:ArchUnit 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void isAnnotatedWith_typeName() {
    assertThat(importField(SomeClass.class, "someField").isAnnotatedWith(Deprecated.class.getName()))
            .as("field is annotated with @Deprecated").isTrue();
    assertThat(importField(SomeClass.class, "someField").isAnnotatedWith(Retention.class.getName()))
            .as("field is annotated with @Retention").isFalse();
}
QueriesConfigImplTest.java 文件源码 项目:queries 阅读 51 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    mappers = new HashMap<>();
    mappers.put(Retention.class, mapper1);
    mappers.put(Target.class, mapper2);

    converters = new HashMap<>();
    converters.put(Retention.class, converter1);
    converters.put(Target.class, converter2);

    config = new QueriesConfigImpl(dialect, binder, mappers, converters);
}
FeatureEnumTest.java 文件源码 项目:googles-monorepo-demo 阅读 25 收藏 0 点赞 0 评论 0
private static void assertGoodTesterAnnotation(
    Class<? extends Annotation> annotationClass) {
  assertNotNull(
      rootLocaleFormat("%s must be annotated with @TesterAnnotation.",
          annotationClass),
      annotationClass.getAnnotation(TesterAnnotation.class));
  final Retention retentionPolicy =
      annotationClass.getAnnotation(Retention.class);
  assertNotNull(
      rootLocaleFormat("%s must have a @Retention annotation.", annotationClass),
      retentionPolicy);
  assertEquals(
      rootLocaleFormat("%s must have RUNTIME RetentionPolicy.", annotationClass),
      RetentionPolicy.RUNTIME, retentionPolicy.value());
  assertNotNull(
      rootLocaleFormat("%s must be inherited.", annotationClass),
      annotationClass.getAnnotation(Inherited.class));

  for (String propertyName : new String[]{"value", "absent"}) {
    Method method = null;
    try {
      method = annotationClass.getMethod(propertyName);
    } catch (NoSuchMethodException e) {
      fail(rootLocaleFormat("%s must have a property named '%s'.",
          annotationClass, propertyName));
    }
    final Class<?> returnType = method.getReturnType();
    assertTrue(rootLocaleFormat("%s.%s() must return an array.",
        annotationClass, propertyName),
        returnType.isArray());
    assertSame(rootLocaleFormat("%s.%s() must return an array of %s.",
        annotationClass, propertyName, annotationClass.getDeclaringClass()),
        annotationClass.getDeclaringClass(), returnType.getComponentType());
  }
}
FactoryProcessor.java 文件源码 项目:toothpick 阅读 26 收藏 0 点赞 0 评论 0
private void checkScopeAnnotationValidity(TypeElement annotation) {
  if (annotation.getAnnotation(Scope.class) == null) {
    error(annotation, "Scope Annotation %s does not contain Scope annotation.", annotation.getQualifiedName());
    return;
  }

  Retention retention = annotation.getAnnotation(Retention.class);
  if (retention == null || retention.value() != RetentionPolicy.RUNTIME) {
    error(annotation, "Scope Annotation %s does not have RUNTIME retention policy.", annotation.getQualifiedName());
  }
}
Context.java 文件源码 项目:aml 阅读 29 收藏 0 点赞 0 评论 0
private JDefinedClass createCustomHttpMethodAnnotation(final String httpMethod)
    throws JClassAlreadyExistsException
{
    final JPackage pkg = codeModel._package(getSupportPackage());
    final JDefinedClass annotationClazz = pkg._annotationTypeDeclaration(httpMethod);
    annotationClazz.annotate(Target.class).param("value", ElementType.METHOD);
    annotationClazz.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
    annotationClazz.annotate(HttpMethod.class).param("value", httpMethod);
    annotationClazz.javadoc().add("Custom JAX-RS support for HTTP " + httpMethod + ".");
    httpMethodAnnotations.put(httpMethod.toUpperCase(), annotationClazz);
    return annotationClazz;
}
Context.java 文件源码 项目:aml 阅读 27 收藏 0 点赞 0 评论 0
private JDefinedClass createCustomHttpMethodAnnotation(final String httpMethod)
    throws JClassAlreadyExistsException
{
    final JPackage pkg = codeModel._package(getSupportPackage());
    final JDefinedClass annotationClazz = pkg._annotationTypeDeclaration(httpMethod);
    annotationClazz.annotate(Target.class).param("value", ElementType.METHOD);
    annotationClazz.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
    annotationClazz.annotate(HttpMethod.class).param("value", httpMethod);
    annotationClazz.javadoc().add("Custom JAX-RS support for HTTP " + httpMethod + ".");
    httpMethodAnnotations.put(httpMethod.toUpperCase(), annotationClazz);
    return annotationClazz;
}
ReflectionForUnavailableAnnotationInspection.java 文件源码 项目:intellij-ce-playground 阅读 24 收藏 0 点赞 0 评论 0
public void foo() throws NoSuchMethodException {
    getClass().getAnnotation(Retention.class);
    getClass().getAnnotation(UnretainedAnnotation.class);
    getClass().getAnnotation(SourceAnnotation.class);
    getClass().isAnnotationPresent(Retention.class);
    getClass().isAnnotationPresent(UnretainedAnnotation.class);
    getClass().isAnnotationPresent(SourceAnnotation.class);
    getClass().getMethod("foo").getAnnotation(SourceAnnotation.class);
}


问题


面经


文章

微信
公众号

扫码关注公众号