List of usage examples for com.google.gwt.i18n.rebind LocaleUtils getInstance
public static LocaleUtils getInstance(TreeLogger logger, PropertyOracle propertyOracle, GeneratorContext context)
From source file:com.em.validation.rebind.generator.gwt.GwtMessageGenerator.java
License:Apache License
/** * Get the locale that is currently being generated * <br/><br/>/*from w w w. j av a 2 s. co m*/ * taken from http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/i18n/rebind/LocalizableGenerator.java * * @param logger * @param context * @return */ public GwtLocale getCurrentGenerationLocale(TreeLogger logger, GeneratorContext context) { // Get the current locale PropertyOracle propertyOracle = context.getPropertyOracle(); LocaleUtils localeUtils = LocaleUtils.getInstance(logger, propertyOracle, context); GwtLocale locale = localeUtils.getCompileLocale(); return locale; }
From source file:fr.putnami.pwt.core.widget.rebind.UiBinderLocalizedGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle typeOracle = context.getTypeOracle(); assert typeOracle != null; JClassType viewType = typeOracle.findType(typeName); if (viewType == null) { logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null); throw new UnableToCompleteException(); }// w w w . j av a2 s. c o m PropertyOracle propertyOracle = context.getPropertyOracle(); LocaleUtils localeUtils = LocaleUtils.getInstance(logger, propertyOracle, context); GwtLocale locale = localeUtils.getCompileLocale(); UiBinderLocalizedCreator creator = new UiBinderLocalizedCreator(viewType, locale); return creator.create(logger, context); }
From source file:org.jboss.hal.config.rebind.EnvironmentGenerator.java
License:Apache License
private void generateProductInfo(final TreeLogger logger, final GeneratorContext generatorContext) { // get print writer that receives the source code PrintWriter printWriter = generatorContext.tryCreate(logger, PRODUCT_INFO_PACKAGE, PRODUCT_INFO_CLASS); // print writer if null, source code has ALREADY been generated, return if (printWriter == null) { return;/* w ww . j a va 2s.c o m*/ } String halVersion = failSafeGetProperty(generatorContext.getPropertyOracle(), "hal.version", "0.0.0"); String halBuild = failSafeGetProperty(generatorContext.getPropertyOracle(), "hal.build", null); LocaleUtils localeUtils = LocaleUtils.getInstance(logger, generatorContext.getPropertyOracle(), generatorContext); Set<GwtLocale> locales = localeUtils.getAllCompileLocales(); List<String> localeValues = locales.stream().map(GwtLocale::getAsString) .filter(locale -> !Strings.isNullOrEmpty(locale)).collect(Collectors.toList()); StringBuffer code = generator.generate(PRODUCT_INFO_TEMPLATE, () -> { Map<String, Object> context = new HashMap<>(); context.put("packageName", PRODUCT_INFO_PACKAGE); context.put("className", PRODUCT_INFO_CLASS); context.put("halVersion", halVersion); context.put("halBuild", halBuild); context.put("locales", localeValues); return context; }); printWriter.write(code.toString()); generatorContext.commit(logger, printWriter); }
From source file:org.jboss.hal.config.rebind.ProductInfoGenerator.java
License:Open Source License
@Override protected String generate(final TreeLogger logger, final GeneratorContext context) { String halVersion = failSafeGetProperty(context.getPropertyOracle(), "hal.version", "n/a"); String variantValue = failSafeGetProperty(context.getPropertyOracle(), "hal.variant", "COMMUNITY") .toUpperCase();// w w w . j a v a 2s .co m Variant variant; try { variant = Variant.valueOf(variantValue); } catch (IllegalArgumentException e) { variant = Variant.COMMUNITY; } LocaleUtils localeUtils = LocaleUtils.getInstance(logger, context.getPropertyOracle(), context); Set<GwtLocale> locales = localeUtils.getAllCompileLocales(); List<String> localeValues = new ArrayList<>(); for (GwtLocale locale : locales) { if (locale.getAsString() != null && locale.getAsString().length() != 0) { localeValues.add(locale.getAsString()); } } return ClassBuilder.define(PACKAGE_NAME + "." + CLASS_NAME, AbstractProductInfo.class).publicScope() .implementsInterface(ProductInfo.class).body().publicConstructor() .callSuper(Stmt.loadLiteral(variant), Stmt.loadLiteral(halVersion), Stmt.loadLiteral(localeValues)) .finish().toJavaString(); }