From 5e7b929b656452284bfc7b94dd81154795c7e4a4 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 8 Apr 2012 10:03:44 -0400 Subject: [PATCH] Split ConfigIncludeContext from Parseable out into its own file --- .../com/typesafe/config/impl/Parseable.java | 8 ++--- .../config/impl/SimpleIncludeContext.java | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 config/src/main/java/com/typesafe/config/impl/SimpleIncludeContext.java diff --git a/config/src/main/java/com/typesafe/config/impl/Parseable.java b/config/src/main/java/com/typesafe/config/impl/Parseable.java index 8289c1bb..6e9415df 100644 --- a/config/src/main/java/com/typesafe/config/impl/Parseable.java +++ b/config/src/main/java/com/typesafe/config/impl/Parseable.java @@ -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. diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleIncludeContext.java b/config/src/main/java/com/typesafe/config/impl/SimpleIncludeContext.java new file mode 100644 index 00000000..66dfade1 --- /dev/null +++ b/config/src/main/java/com/typesafe/config/impl/SimpleIncludeContext.java @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2011-2012 Typesafe Inc. + */ +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; + } +}