Class TranslationClassGenerator


  • @SupportedOptions({"translationFilesPath","skipTranslations"})
    final class TranslationClassGenerator
    extends AbstractGenerator
    The translation class generator.

    The aim of this generator is to generate the classes corresponding to translation files of a MessageLogger or MessageBundle.

    • Field Detail

      • TRANSLATION_FILES_PATH_OPTION

        public static final java.lang.String TRANSLATION_FILES_PATH_OPTION
        See Also:
        Constant Field Values
      • SKIP_TRANSLATIONS

        public static final java.lang.String SKIP_TRANSLATIONS
        See Also:
        Constant Field Values
      • TRANSLATION_FILE_EXTENSION_PATTERN

        private static final java.lang.String TRANSLATION_FILE_EXTENSION_PATTERN
        The properties file pattern. The property file must match the given pattern org.pkgname.InterfaceName.i18n_locale.properties where locale is :
        • xx - where xx is the language like (e.g. en)
        • xx_YY - where xx is the language and YY is the country like (e.g. en_US)
        • xx_YY_ZZ - where xx is the language, YY is the country and ZZ is the variant like (e.g. en_US_POSIX)
        See Also:
        Constant Field Values
      • translationFilesPath

        private final java.lang.String translationFilesPath
      • skipTranslations

        private final boolean skipTranslations
    • Constructor Detail

      • TranslationClassGenerator

        public TranslationClassGenerator​(javax.annotation.processing.ProcessingEnvironment processingEnv)
        Construct an instance of the Translation Class Generator.
        Parameters:
        processingEnv - the processing environment
    • Method Detail

      • processTypeElement

        public void processTypeElement​(javax.lang.model.element.TypeElement annotation,
                                       javax.lang.model.element.TypeElement element,
                                       MessageInterface messageInterface)
        Description copied from class: AbstractGenerator
        Processes a type element.
        Specified by:
        processTypeElement in class AbstractGenerator
        Parameters:
        annotation - the annotation who trigger the processing
        element - the element that contains the methods.
        messageInterface - the message interface to implement.
      • allInterfaceTranslations

        private java.util.Map<java.io.File,​java.util.Map<MessageMethod,​java.lang.String>> allInterfaceTranslations​(MessageInterface messageInterface,
                                                                                                                               java.util.List<java.io.File> files)
                                                                                                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • findTranslationFiles

        private java.util.List<java.io.File> findTranslationFiles​(MessageInterface messageInterface)
                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • validateTranslationMessages

        private java.util.Map<MessageMethod,​java.lang.String> validateTranslationMessages​(MessageInterface messageInterface,
                                                                                                java.io.File file)
        Returns only the valid translations message corresponding to the declared MessageMethod methods in the MessageBundle or MessageLogger interface.
        Parameters:
        messageInterface - the message interface.
        file - the translation file
        Returns:
        the valid translations messages
      • generateSourceFileFor

        private void generateSourceFileFor​(MessageInterface messageInterface,
                                           java.io.File translationFile,
                                           java.util.Map<MessageMethod,​java.lang.String> translations)
        Generate a class for the given translation file.
        Parameters:
        messageInterface - the message interface
        translationFile - the translation file
        translations - the translations message