Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,44 @@
import lombok.core.configuration.ConfigurationSource.Result;

public class BubblingConfigurationResolver implements ConfigurationResolver {

private final ConfigurationFile start;
private final ConfigurationFileToSource fileMapper;

public BubblingConfigurationResolver(ConfigurationFile start, ConfigurationFileToSource fileMapper) {
this.start = start;
this.fileMapper = fileMapper;
}

@SuppressWarnings("unchecked")
@Override
public <T> T resolve(ConfigurationKey<T> key) {
boolean isList = key.getType().isList();
List<List<ListModification>> listModificationsList = null;

boolean stopBubbling = false;
ConfigurationFile currentLevel = start;
Collection<ConfigurationFile> visited = new HashSet<ConfigurationFile>();
outer:
while (currentLevel != null) {
Deque<ConfigurationFile> round = new ArrayDeque<ConfigurationFile>();
round.push(currentLevel);

while (!round.isEmpty()) {
ConfigurationFile currentFile = round.pop();
if (currentFile == null || !visited.add(currentFile)) continue;

ConfigurationSource source = fileMapper.parsed(currentFile);
if (source == null) continue;

for (ConfigurationFile importFile : source.imports()) round.push(importFile);

Result stop = source.resolve(ConfigurationKeys.STOP_BUBBLING);
stopBubbling = stopBubbling || (stop != null && Boolean.TRUE.equals(stop.getValue()));

Result result = source.resolve(key);
if (result == null) continue;

if (isList) {
if (listModificationsList == null) listModificationsList = new ArrayList<List<ListModification>>();
listModificationsList.add((List<ListModification>) result.getValue());
Expand All @@ -84,10 +84,10 @@ public <T> T resolve(ConfigurationKey<T> key) {
if (stopBubbling) break;
currentLevel = currentLevel.parent();
}

if (!isList) return null;
if (listModificationsList == null) return (T) Collections.emptyList();

List<Object> listValues = new ArrayList<Object>();
Collections.reverse(listModificationsList);
for (List<ListModification> listModifications : listModificationsList) {
Expand All @@ -98,4 +98,4 @@ public <T> T resolve(ConfigurationKey<T> key) {
}
return (T) listValues;
}
}
}