org.jvnet.localizer.Generator Maven / Gradle / Ivy
/*
* The MIT License
*
* Copyright (c) 2007-, the localizer project contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jvnet.localizer;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JVar;
import org.apache.commons.lang3.text.WordUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.io.File;
import java.text.DateFormat;
import java.text.Format;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
/**
* @author Kohsuke Kawaguchi
*/
public class Generator extends CodeModelGenerator implements ClassGenerator {
public Generator(GeneratorConfig config) {
super(config);
}
@Deprecated
public Generator(File outputDirectory, Reporter reporter) {
this(outputDirectory, null, reporter);
}
@Deprecated
public Generator(File outputDirectory, String outputEncoding, Reporter reporter) {
this(outputDirectory, null, reporter, null);
}
@Deprecated
public Generator(File outputDirectory, String outputEncoding, Reporter reporter,
String keyPattern) {
this(GeneratorConfig.of(outputDirectory, outputEncoding, reporter, keyPattern));
}
protected void generateImpl(String className, Properties props) throws AssertionError {
try {
JDefinedClass c = cm._class(className);
c.annotate(SuppressWarnings.class).paramArray("value").param("").param("PMD").param("all");
if (accessModifierAnnotations) {
c.annotate(Restricted.class).param("value", NoExternalUse.class);
}
c.javadoc().add("Generated localization support class.");
// [RESULT]
// private static final ResourceBundleHolder holder = BundleHolder.get(Messages.class);
JFieldVar holder = c.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, ResourceBundleHolder.class, "holder",
cm.ref(ResourceBundleHolder.class).staticInvoke("get").arg(c.dotclass()) );
holder.javadoc().add("The resource bundle reference");
for (Entry
© 2015 - 2024 Weber Informatics LLC | Privacy Policy