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

org.nuiton.jaxx.compiler.finalizers.ApplyI18nKeysFileFinalizer Maven / Gradle / Ivy

The newest version!
package org.nuiton.jaxx.compiler.finalizers;

/*-
 * #%L
 * JAXX :: Compiler
 * %%
 * Copyright (C) 2008 - 2024 Code Lutin, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import com.google.auto.service.AutoService;
import org.codehaus.plexus.component.annotations.Component;
import org.nuiton.jaxx.compiler.CompiledObject;
import org.nuiton.jaxx.compiler.CompilerException;
import org.nuiton.jaxx.compiler.JAXXCompiler;
import org.nuiton.jaxx.compiler.java.JavaFile;

/**
 * Created on 08/10/2020.
 *
 * @author Tony Chemit - [email protected]
 * @since 3.0
 */
@AutoService(JAXXCompilerFinalizer.class)
@Component(hint = "i18n-apply-keys-file", role = JAXXCompilerFinalizer.class)
public class ApplyI18nKeysFileFinalizer extends AbstractFinalizer {

    @Override
    public boolean accept(JAXXCompiler compiler) {
        return compiler.getConfiguration().isApplyI18nHelper() && compiler.getConfiguration().isI18nable() && compiler.getParentI18nKeysFileModel(true) != null;
    }

    @Override
    public void finalizeCompiler(CompiledObject root, JAXXCompiler compiler, JavaFile javaFile, String packageName, String className) {
        if (!compiler.isI18nInit()) {
            throw new CompilerException("Jaxx file has not set i18n: " + compiler.getOutputClassName());
        }
        I18nKeysFileModel keysFileModel = compiler.getParentI18nKeysFileModel(false);
        keysFileModel.getKeys().forEach(i18nKey -> compiler.getEngine().registerI18nKey(compiler.computeI18nProperty(i18nKey)));
    }

    @Override
    public void prepareJavaFile(CompiledObject root, JAXXCompiler compiler, JavaFile javaFile, String packageName, String className) {
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy