Search in sources :

Example 1 with Result

use of lombok.core.configuration.ConfigurationSource.Result in project lombok by rzwitserloot.

the class FileSystemSourceCache method sourcesForDirectory.

private Iterable<ConfigurationSource> sourcesForDirectory(final File directory, final ConfigurationProblemReporter reporter) {
    return new Iterable<ConfigurationSource>() {

        @Override
        public Iterator<ConfigurationSource> iterator() {
            return new Iterator<ConfigurationSource>() {

                File currentDirectory = directory;

                ConfigurationSource next;

                boolean stopBubbling = false;

                @Override
                public boolean hasNext() {
                    if (next != null)
                        return true;
                    if (stopBubbling)
                        return false;
                    next = findNext();
                    return next != null;
                }

                @Override
                public ConfigurationSource next() {
                    if (!hasNext())
                        throw new NoSuchElementException();
                    ConfigurationSource result = next;
                    next = null;
                    return result;
                }

                private ConfigurationSource findNext() {
                    while (currentDirectory != null && next == null) {
                        next = getSourceForDirectory(currentDirectory, reporter);
                        currentDirectory = currentDirectory.getParentFile();
                    }
                    if (next != null) {
                        Result stop = next.resolve(ConfigurationKeys.STOP_BUBBLING);
                        stopBubbling = (stop != null && Boolean.TRUE.equals(stop.getValue()));
                    }
                    return next;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : Iterator(java.util.Iterator) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException) Result(lombok.core.configuration.ConfigurationSource.Result)

Example 2 with Result

use of lombok.core.configuration.ConfigurationSource.Result in project lombok by rzwitserloot.

the class BubblingConfigurationResolver method resolve.

@SuppressWarnings("unchecked")
@Override
public <T> T resolve(ConfigurationKey<T> key) {
    boolean isList = key.getType().isList();
    List<List<ListModification>> listModificationsList = null;
    for (ConfigurationSource source : sources) {
        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());
        }
        if (result.isAuthoritative()) {
            if (isList)
                break;
            return (T) result.getValue();
        }
    }
    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) {
        if (listModifications != null)
            for (ListModification modification : listModifications) {
                listValues.remove(modification.getValue());
                if (modification.isAdded())
                    listValues.add(modification.getValue());
            }
    }
    return (T) listValues;
}
Also used : ListModification(lombok.core.configuration.ConfigurationSource.ListModification) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Result(lombok.core.configuration.ConfigurationSource.Result)

Aggregations

Result (lombok.core.configuration.ConfigurationSource.Result)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 ListModification (lombok.core.configuration.ConfigurationSource.ListModification)1