private static String maybeSetBinding(TreeLogger logger, ModuleDef module, String propName,
String newValue) {
logger = logger.branch(TreeLogger.Type.INFO, "binding: " + propName + "=" + newValue);
BindingProperty binding = module.getProperties().findBindingProp(propName);
if (binding == null) {
logger.log(TreeLogger.Type.WARN, "undefined property: '" + propName + "'");
return null;
}
if (!binding.isAllowedValue(newValue)) {
String[] allowedValues = binding.getAllowedValues(binding.getRootCondition());
logger.log(TreeLogger.Type.WARN, "property '" + propName +
"' cannot be set to '" + newValue + "'");
logger.log(TreeLogger.Type.INFO, "allowed values: " +
Joiner.on(", ").join(allowedValues));
// See if we can fall back on a reasonable default.
if (allowedValues.length == 1) {
// There is only one possibility, so use it.
newValue = allowedValues[0];
} else if (binding.getName().equals("locale")) {
// TODO: come up with a more general solution. Perhaps fail
// the compile and give the user a way to override the property?
newValue = chooseDefault(binding, "default", "en", "en_US");
} else {
// There is more than one. Continue and possibly compile multiple permutations.
logger.log(TreeLogger.Type.INFO, "continuing without " + propName +
". Sourcemaps may not work.");
return null;
}
logger.log(TreeLogger.Type.INFO, "recovered with " + propName + "=" + newValue);
}
binding.setRootGeneratedValues(newValue);
return newValue;
}