mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
expandOnly() method to allow non-expandable roots
This commit is contained in:
@@ -99,6 +99,11 @@ public abstract class FilteredTraverser<T, Self extends FilteredTraverser<T, Sel
|
||||
return newInstance(myMeta.expand(filter));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Self expandOnly(@NotNull Condition<? super T> filter) {
|
||||
return newInstance(myMeta.expandOnly(filter));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Self filter(@NotNull Condition<? super T> filter) {
|
||||
return newInstance(myMeta.filter(filter));
|
||||
@@ -116,7 +121,7 @@ public abstract class FilteredTraverser<T, Self extends FilteredTraverser<T, Sel
|
||||
@NotNull
|
||||
@Override
|
||||
public JBIterable<T> children(@NotNull T node) {
|
||||
if (!myMeta.expandFilter.value(node) && !Conditions.oneOf(myMeta.roots).value(node)) {
|
||||
if (!myMeta.expandFilter.value(node) && (myMeta.expandOnly || !Conditions.oneOf(myMeta.roots).value(node))) {
|
||||
return JBIterable.empty();
|
||||
}
|
||||
return JBIterable.from(childrenImpl(node)).filter(Conditions.not(myMeta.excludeFilter));
|
||||
@@ -130,7 +135,7 @@ public abstract class FilteredTraverser<T, Self extends FilteredTraverser<T, Sel
|
||||
}
|
||||
|
||||
protected static <T> Meta<T> emptyMeta() {
|
||||
return new Meta<T>(EmptyIterable.<T>getInstance(), false,
|
||||
return new Meta<T>(EmptyIterable.<T>getInstance(), false, false,
|
||||
Conditions.alwaysTrue(),
|
||||
Conditions.alwaysTrue(),
|
||||
Conditions.alwaysFalse());
|
||||
@@ -139,41 +144,48 @@ public abstract class FilteredTraverser<T, Self extends FilteredTraverser<T, Sel
|
||||
protected static class Meta<T> {
|
||||
final Iterable<? extends T> roots;
|
||||
final boolean skipExpanded;
|
||||
final boolean expandOnly;
|
||||
final Condition<? super T> expandFilter;
|
||||
final Condition<? super T> resultFilter;
|
||||
final Condition<? super T> excludeFilter;
|
||||
|
||||
public Meta(@NotNull Iterable<? extends T> roots,
|
||||
boolean skipExpanded,
|
||||
boolean expandOnly,
|
||||
@NotNull Condition<? super T> expandFilter,
|
||||
@NotNull Condition<? super T> resultFilter,
|
||||
@NotNull Condition<? super T> excludeFilter) {
|
||||
this.roots = roots;
|
||||
this.skipExpanded = skipExpanded;
|
||||
this.expandOnly = expandOnly;
|
||||
this.expandFilter = expandFilter;
|
||||
this.resultFilter = resultFilter;
|
||||
this.excludeFilter = excludeFilter;
|
||||
}
|
||||
|
||||
public Meta<T> withRoots(@NotNull Iterable<? extends T> roots) {
|
||||
return new Meta<T>(roots, skipExpanded, expandFilter, resultFilter, excludeFilter);
|
||||
return new Meta<T>(roots, skipExpanded, expandOnly, expandFilter, resultFilter, excludeFilter);
|
||||
}
|
||||
|
||||
public Meta<T> skipExpanded(boolean skip) {
|
||||
return new Meta<T>(roots, skip, expandFilter, resultFilter, excludeFilter);
|
||||
return new Meta<T>(roots, skip, expandOnly, expandFilter, resultFilter, excludeFilter);
|
||||
}
|
||||
|
||||
public Meta<T> expand(@NotNull Condition<? super T> filter) {
|
||||
return new Meta<T>(roots, skipExpanded, Conditions.and2(expandFilter, filter), resultFilter, excludeFilter);
|
||||
return new Meta<T>(roots, skipExpanded, expandOnly, Conditions.and2(expandFilter, filter), resultFilter, excludeFilter);
|
||||
}
|
||||
|
||||
public Meta<T> expandOnly(@NotNull Condition<? super T> filter) {
|
||||
return new Meta<T>(roots, skipExpanded, true, Conditions.and2(expandFilter, filter), resultFilter, excludeFilter);
|
||||
}
|
||||
|
||||
public Meta<T> filter(@NotNull Condition<? super T> filter) {
|
||||
return new Meta<T>(roots, skipExpanded, expandFilter, Conditions.and2(resultFilter, filter), excludeFilter);
|
||||
return new Meta<T>(roots, skipExpanded, expandOnly, expandFilter, Conditions.and2(resultFilter, filter), excludeFilter);
|
||||
}
|
||||
|
||||
public Meta<T> exclude(Condition<? super T> filter) {
|
||||
// exclude filter is always accumulated
|
||||
return new Meta<T>(roots, skipExpanded, expandFilter, resultFilter, Conditions.or2(excludeFilter, filter));
|
||||
return new Meta<T>(roots, skipExpanded, expandOnly, expandFilter, resultFilter, Conditions.or2(excludeFilter, filter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user