remove ignoresFallbacks param from AbstractConfigValue.newCopy

Only one subclass ever used this, SimpleConfigObject

So now we have withFallbacksIgnored that asserts they are
already ignored, for the other classes, and has a special
SimpleConfigObject implementation.
This commit is contained in:
Havoc Pennington 2012-04-05 15:24:24 -04:00
parent a8d444e19f
commit 80eac565c6
15 changed files with 44 additions and 28 deletions

View File

@ -147,12 +147,11 @@ abstract class AbstractConfigObject extends AbstractConfigValue implements Confi
return ConfigValueType.OBJECT;
}
protected abstract AbstractConfigObject newCopy(ResolveStatus status, boolean ignoresFallbacks,
ConfigOrigin origin);
protected abstract AbstractConfigObject newCopy(ResolveStatus status, ConfigOrigin origin);
@Override
protected AbstractConfigObject newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
return newCopy(resolveStatus(), ignoresFallbacks, origin);
protected AbstractConfigObject newCopy(ConfigOrigin origin) {
return newCopy(resolveStatus(), origin);
}
@Override

View File

@ -122,7 +122,7 @@ abstract class AbstractConfigValue implements ConfigValue, MergeableValue, Seria
return this;
}
protected abstract AbstractConfigValue newCopy(boolean ignoresFallbacks, ConfigOrigin origin);
protected abstract AbstractConfigValue newCopy(ConfigOrigin origin);
// this is virtualized rather than a field because only some subclasses
// really need to store the boolean, and they may be able to pack it
@ -133,6 +133,14 @@ abstract class AbstractConfigValue implements ConfigValue, MergeableValue, Seria
return resolveStatus() == ResolveStatus.RESOLVED;
}
protected AbstractConfigValue withFallbacksIgnored() {
if (ignoresFallbacks())
return this;
else
throw new ConfigException.BugOrBroken(
"value class doesn't implement forced fallback-ignoring " + this);
}
// the withFallback() implementation is supposed to avoid calling
// mergedWith* if we're ignoring fallbacks.
protected final void requireNotIgnoringFallbacks() {
@ -189,7 +197,7 @@ abstract class AbstractConfigValue implements ConfigValue, MergeableValue, Seria
// falling back to a non-object doesn't merge anything, and also
// prohibits merging any objects that we fall back to later.
// so we have to switch to ignoresFallbacks mode.
return newCopy(true /* ignoresFallbacks */, origin);
return withFallbacksIgnored();
} else {
// if unresolved, we may have to look back to fallbacks as part of
// the resolution process, so always delay
@ -219,7 +227,7 @@ abstract class AbstractConfigValue implements ConfigValue, MergeableValue, Seria
if (this.origin == origin)
return this;
else
return newCopy(ignoresFallbacks(), origin);
return newCopy(origin);
}
// this is only overridden to change the return type

View File

@ -33,7 +33,7 @@ final class ConfigBoolean extends AbstractConfigValue {
}
@Override
protected ConfigBoolean newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
protected ConfigBoolean newCopy(ConfigOrigin origin) {
return new ConfigBoolean(origin, value);
}
}

View File

@ -48,7 +48,7 @@ final class ConfigConcatenation extends AbstractConfigValue implements Unmergeab
}
@Override
protected ConfigConcatenation newCopy(boolean ignoresFallbacks, ConfigOrigin newOrigin) {
protected ConfigConcatenation newCopy(ConfigOrigin newOrigin) {
return new ConfigConcatenation(newOrigin, pieces);
}

View File

@ -176,7 +176,7 @@ final class ConfigDelayedMerge extends AbstractConfigValue implements Unmergeabl
}
@Override
protected AbstractConfigValue newCopy(boolean newIgnoresFallbacks, ConfigOrigin newOrigin) {
protected AbstractConfigValue newCopy(ConfigOrigin newOrigin) {
return new ConfigDelayedMerge(newOrigin, stack);
}

View File

@ -50,8 +50,7 @@ final class ConfigDelayedMergeObject extends AbstractConfigObject implements Unm
}
@Override
protected ConfigDelayedMergeObject newCopy(ResolveStatus status, boolean ignoresFallbacks,
ConfigOrigin origin) {
protected ConfigDelayedMergeObject newCopy(ResolveStatus status, ConfigOrigin origin) {
if (status != resolveStatus())
throw new ConfigException.BugOrBroken(
"attempt to create resolved ConfigDelayedMergeObject");

View File

@ -47,7 +47,7 @@ final class ConfigDouble extends ConfigNumber {
}
@Override
protected ConfigDouble newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
protected ConfigDouble newCopy(ConfigOrigin origin) {
return new ConfigDouble(origin, value, originalText);
}
}

View File

@ -47,7 +47,7 @@ final class ConfigInt extends ConfigNumber {
}
@Override
protected ConfigInt newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
protected ConfigInt newCopy(ConfigOrigin origin) {
return new ConfigInt(origin, value, originalText);
}
}

View File

@ -47,7 +47,7 @@ final class ConfigLong extends ConfigNumber {
}
@Override
protected ConfigLong newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
protected ConfigLong newCopy(ConfigOrigin origin) {
return new ConfigLong(origin, value, originalText);
}
}

View File

@ -43,7 +43,7 @@ final class ConfigNull extends AbstractConfigValue {
}
@Override
protected ConfigNull newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
protected ConfigNull newCopy(ConfigOrigin origin) {
return new ConfigNull(origin);
}
}

View File

@ -46,9 +46,7 @@ final class ConfigReference extends AbstractConfigValue implements Unmergeable {
}
@Override
protected ConfigReference newCopy(boolean ignoresFallbacks, ConfigOrigin newOrigin) {
if (ignoresFallbacks)
throw new ConfigException.BugOrBroken("Cannot ignore fallbacks for " + this);
protected ConfigReference newCopy(ConfigOrigin newOrigin) {
return new ConfigReference(newOrigin, expr, prefixLength);
}

View File

@ -38,7 +38,7 @@ final class ConfigString extends AbstractConfigValue {
}
@Override
protected ConfigString newCopy(boolean ignoresFallbacks, ConfigOrigin origin) {
protected ConfigString newCopy(ConfigOrigin origin) {
return new ConfigString(origin, value);
}
}

View File

@ -82,8 +82,8 @@ final class ConfigSubstitution extends AbstractConfigValue implements
}
@Override
protected AbstractConfigValue newCopy(boolean ignoresFallbacks, ConfigOrigin newOrigin) {
return delegate().newCopy(ignoresFallbacks, newOrigin);
protected AbstractConfigValue newCopy(ConfigOrigin newOrigin) {
return delegate().newCopy(newOrigin);
}
@Override

View File

@ -396,7 +396,7 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList {
}
@Override
protected SimpleConfigList newCopy(boolean ignoresFallbacks, ConfigOrigin newOrigin) {
protected SimpleConfigList newCopy(ConfigOrigin newOrigin) {
return new SimpleConfigList(newOrigin, value);
}

View File

@ -132,12 +132,24 @@ final class SimpleConfigObject extends AbstractConfigObject {
return value.get(key);
}
@Override
protected SimpleConfigObject newCopy(ResolveStatus newStatus, boolean newIgnoresFallbacks,
ConfigOrigin newOrigin) {
private SimpleConfigObject newCopy(ResolveStatus newStatus, ConfigOrigin newOrigin,
boolean newIgnoresFallbacks) {
return new SimpleConfigObject(newOrigin, value, newStatus, newIgnoresFallbacks);
}
@Override
protected SimpleConfigObject newCopy(ResolveStatus newStatus, ConfigOrigin newOrigin) {
return newCopy(newStatus, newOrigin, ignoresFallbacks);
}
@Override
protected SimpleConfigObject withFallbacksIgnored() {
if (ignoresFallbacks)
return this;
else
return newCopy(resolveStatus(), origin(), true /* ignoresFallbacks */);
}
@Override
ResolveStatus resolveStatus() {
return ResolveStatus.fromBoolean(resolved);
@ -201,7 +213,7 @@ final class SimpleConfigObject extends AbstractConfigObject {
return new SimpleConfigObject(mergeOrigins(this, fallback), merged, newResolveStatus,
newIgnoresFallbacks);
else if (newResolveStatus != resolveStatus() || newIgnoresFallbacks != ignoresFallbacks())
return newCopy(newResolveStatus, newIgnoresFallbacks, origin());
return newCopy(newResolveStatus, origin(), newIgnoresFallbacks);
else
return this;
}
@ -230,7 +242,7 @@ final class SimpleConfigObject extends AbstractConfigObject {
}
}
if (changes == null) {
return newCopy(resolveStatus(), ignoresFallbacks(), origin());
return this;
} else {
Map<String, AbstractConfigValue> modified = new HashMap<String, AbstractConfigValue>();
boolean sawUnresolved = false;