Split ConfigIncludeContext from Parseable out into its own file

This commit is contained in:
Havoc Pennington 2012-04-08 10:03:44 -04:00
parent 8c6b204905
commit 5e7b929b65
2 changed files with 34 additions and 6 deletions

View File

@ -65,12 +65,7 @@ public abstract class Parseable implements ConfigParseable {
protected void postConstruct(ConfigParseOptions baseOptions) {
this.initialOptions = fixupOptions(baseOptions);
this.includeContext = new ConfigIncludeContext() {
@Override
public ConfigParseable relativeTo(String filename) {
return Parseable.this.relativeTo(filename);
}
};
this.includeContext = new SimpleIncludeContext(this);
if (initialOptions.getOriginDescription() != null)
initialOrigin = SimpleConfigOrigin.newSimple(initialOptions.getOriginDescription());
@ -80,6 +75,7 @@ public abstract class Parseable implements ConfigParseable {
// the general idea is that any work should be in here, not in the
// constructor,
// so that exceptions are thrown from the public parse() function and not
// from the creation of the Parseable. Essentially this is a lazy field.
// The parser should close the reader when it's done with it.

View File

@ -0,0 +1,32 @@
/**
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config.impl;
import com.typesafe.config.ConfigIncludeContext;
import com.typesafe.config.ConfigParseable;
class SimpleIncludeContext implements ConfigIncludeContext {
private final Parseable parseable;
SimpleIncludeContext(Parseable parseable) {
this.parseable = parseable;
}
SimpleIncludeContext() {
this(null);
}
SimpleIncludeContext withParseable(Parseable parseable) {
return new SimpleIncludeContext(parseable);
}
@Override
public ConfigParseable relativeTo(String filename) {
if (parseable != null)
return parseable.relativeTo(filename);
else
return null;
}
}