List of usage examples for java.lang.annotation RetentionPolicy RUNTIME
RetentionPolicy RUNTIME
To view the source code for java.lang.annotation RetentionPolicy RUNTIME.
Click Source Link
From source file:com.xemantic.tadedon.guice.matcher.Annotations.java
/** * Check if given {@code annotationType} has {@link Retention} set to {@link RetentionPolicy#RUNTIME}. * * @param annotationType the annotation type to check. *///from w ww . java 2 s . c om public static void checkForRuntimeRetention(Class<? extends Annotation> annotationType) { Retention retention = annotationType.getAnnotation(Retention.class); checkArgument(((retention != null) && (retention.value() == RetentionPolicy.RUNTIME)), "Annotation %s is missing RUNTIME retention", annotationType.getSimpleName()); }
From source file:org.raml.jaxrs.codegen.core.visitors.HttpMethodAnnotationVisitor.java
@SuppressWarnings("unchecked") @Override//from w w w .j av a 2s . co m public void visit(ResourceMethod resourceMethod) { JMethod annotatable = resourceMethod.getGeneratedObject(); String httpMethod = resourceMethod.getAction().getType().toString(); final Object annotationClass = httpMethodAnnotations.get(httpMethod.toUpperCase()); if (annotationClass == null) { try { final JPackage pkg = getCodeModel()._package(getConfiguration().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 + "."); annotatable.annotate(annotationClazz); httpMethodAnnotations.put(httpMethod.toUpperCase(), annotationClazz); } catch (JClassAlreadyExistsException e) { throw new RuntimeException(e.getMessage(), e); } } else if (annotationClass instanceof JClass) { annotatable.annotate((JClass) annotationClass); } else if (annotationClass instanceof Class) { annotatable.annotate((Class<? extends Annotation>) annotationClass); } else { throw new IllegalStateException( "Found annotation: " + annotationClass + " for HTTP method: " + httpMethod); } String resourceInterfacePath = strip(resourceMethod.getResourceInterface().getResource().getRelativeUri(), "/"); String path = StringUtils.substringAfter(resourceMethod.getAction().getResource().getUri(), resourceInterfacePath + "/"); annotatable.annotate(Path.class).param(DEFAULT_ANNOTATION_PARAMETER, path); MimeType requestMimeType = resourceMethod.getMimeType(); if (requestMimeType != null) { annotatable.annotate(Consumes.class).param(DEFAULT_ANNOTATION_PARAMETER, requestMimeType.getType()); } List<String> responseContentTypes = new ArrayList<String>(); for (MimeType mimeType : RamlHelper.getUniqueResponseMimeTypes(resourceMethod.getAction())) { responseContentTypes.add(mimeType.getType()); } if (!responseContentTypes.isEmpty()) { final JAnnotationArrayMember paramArray = annotatable.annotate(Produces.class) .paramArray(DEFAULT_ANNOTATION_PARAMETER); for (String responseMimeType : responseContentTypes) { paramArray.param(responseMimeType); } } }
From source file:org.apache.shindig.common.JsonSerializerTest.java
@Test public void serializePrimitives() throws Exception { assertEquals("null", JsonSerializer.serialize((Object) null)); assertEquals("\"hello\"", JsonSerializer.serialize("hello")); assertEquals("100", JsonSerializer.serialize(100)); assertEquals("125.0", JsonSerializer.serialize(125.0f)); assertEquals("126.0", JsonSerializer.serialize(126.0)); assertEquals("1", JsonSerializer.serialize(1L)); assertEquals("\"RUNTIME\"", JsonSerializer.serialize(RetentionPolicy.RUNTIME)); assertEquals("\"string buf\"", JsonSerializer.serialize(new StringBuilder().append("string").append(' ').append("buf"))); }
From source file:org.raml.jaxrs.codegen.core.Context.java
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; }