Support alias "self" in queries

Writing an expression like "owner:self status:open" will now identify
changes that the caller owns and are still open. This self alias
is valid in contexts where a user is expected as an argument to a
query operator.

Change-Id: I87e58dda43d8da560b31400f1257857b0ea96175
This commit is contained in:
Shawn O. Pearce
2012-04-07 14:59:11 -07:00
parent 8010d4b9a6
commit 068a0d8dde
3 changed files with 111 additions and 52 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.query;
import com.google.common.collect.Iterables;
import com.google.gwtorm.server.OrmException;
import java.util.Collection;
@@ -44,23 +45,35 @@ import java.util.List;
public abstract class Predicate<T> {
/** Combine the passed predicates into a single AND node. */
public static <T> Predicate<T> and(final Predicate<T>... that) {
if (that.length == 1) {
return that[0];
}
return new AndPredicate<T>(that);
}
/** Combine the passed predicates into a single AND node. */
public static <T> Predicate<T> and(
final Collection<? extends Predicate<T>> that) {
if (that.size() == 1) {
return Iterables.getOnlyElement(that);
}
return new AndPredicate<T>(that);
}
/** Combine the passed predicates into a single OR node. */
public static <T> Predicate<T> or(final Predicate<T>... that) {
if (that.length == 1) {
return that[0];
}
return new OrPredicate<T>(that);
}
/** Combine the passed predicates into a single OR node. */
public static <T> Predicate<T> or(
final Collection<? extends Predicate<T>> that) {
if (that.size() == 1) {
return Iterables.getOnlyElement(that);
}
return new OrPredicate<T>(that);
}