All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.querydsl.codegen.GeneratedAnnotationResolver Maven / Gradle / Ivy

The newest version!
package com.querydsl.codegen;

import java.lang.annotation.Annotation;
import org.jetbrains.annotations.Nullable;

/**
 * {@code GeneratedAnnotationClassResolver} provides class name resolving functionality for
 * resolving the annotation type to be used on {@link Serializer}s generated sources.
 */
public final class GeneratedAnnotationResolver {

  private static final Class DEFAULT_GENERATED_ANNOTATION_CLASS =
      resolveJavaDefault();

  /**
   * Use the {@code generatedAnnotationClass} or use the JDK one.
   *
   * 

A {@code null generatedAnnotationClass} will resolve to the java {@code @Generated} * annotation (can be of type {@code javax.annotation.Generated} or {@code * javax.annotation.processing.Generated} depending on the java version. * * @param generatedAnnotationClass the fully qualified class name of the Single-Element * Annotation (with {@code String} element) to use or {@code null}. * @return the provided {@code generatedAnnotationClass} if not {@code null} or the one from java. * Never {@code null}. * @see Single-Element * Annotation */ public static Class resolve(@Nullable String generatedAnnotationClass) { if (generatedAnnotationClass != null) { try { return (Class) Class.forName(generatedAnnotationClass); } catch (Exception e) { // Try next one } } return resolveDefault(); } /** * Resolve the java {@code @Generated} annotation (can be of type {@code * javax.annotation.Generated} or {@code javax.annotation.processing.Generated} depending on the * java version. * * @return the Generated annotation class from java. Never {@code null}. */ public static Class resolveDefault() { return DEFAULT_GENERATED_ANNOTATION_CLASS; } @SuppressWarnings("unchecked") private static Class resolveJavaDefault() { try { return (Class) Class.forName("javax.annotation.processing.Generated"); } catch (Exception e) { // Try next one } try { return (Class) Class.forName("javax.annotation.Generated"); } catch (Exception e) { // Try next one } try { return (Class) Class.forName("jakarta.annotation.Generated"); } catch (Exception e) { // Try next one } throw new IllegalStateException("Can't find Generated annotation"); } private GeneratedAnnotationResolver() {} }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy