Use fullCurrentPath() when relativizing includes, and make it throw if path is empty

This is just to consolidate our use of pathStack in one place.
This commit is contained in:
Havoc Pennington 2014-05-01 10:15:44 -04:00
parent 36c1392028
commit e5cc23235f

View File

@ -440,15 +440,11 @@ final class Parser {
}
private Path fullCurrentPath() {
Path full = null;
// pathStack has top of stack at front
for (Path p : pathStack) {
if (full == null)
full = p;
else
full = full.prepend(p);
}
return full;
if (pathStack.isEmpty())
throw new ConfigException.BugOrBroken("Bug in parser; tried to get current path when at root");
else
return new Path(pathStack.descendingIterator());
}
private String previousFieldName() {
@ -683,9 +679,7 @@ final class Parser {
}
if (!pathStack.isEmpty()) {
// The stack is in reverse order (most recent first on the
// iterator), so build the path from the reversed iterator.
Path prefix = new Path(pathStack.descendingIterator());
Path prefix = fullCurrentPath();
obj = obj.relativized(prefix);
}