use of com.facebook.buck.rules.ParamInfo in project buck by facebook.
the class QueryTargetAccessor method filterAttributeContents.
/**
* Filters the objects in the given attribute that satisfy the given predicate.
*/
public static <T> ImmutableSet<Object> filterAttributeContents(TargetNode<T, ?> node, String attribute, final Predicate<Object> predicate) {
try {
final ImmutableSet.Builder<Object> builder = ImmutableSet.builder();
Class<?> constructorArgClass = node.getConstructorArg().getClass();
Field field = constructorArgClass.getField(attribute);
ParamInfo info = new ParamInfo(typeCoercerFactory, constructorArgClass, field);
info.traverse(value -> {
if (predicate.apply(value)) {
builder.add(value);
}
}, node.getConstructorArg());
return builder.build();
} catch (NoSuchFieldException e) {
// Ignore if the field does not exist in this rule.
return ImmutableSet.of();
}
}
use of com.facebook.buck.rules.ParamInfo in project buck by facebook.
the class QueryTargetAccessor method getTargetsInAttribute.
public static <T> ImmutableSet<QueryTarget> getTargetsInAttribute(TargetNode<T, ?> node, String attribute) {
try {
final ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
Class<?> constructorArgClass = node.getConstructorArg().getClass();
Field field = constructorArgClass.getField(attribute);
ParamInfo info = new ParamInfo(typeCoercerFactory, constructorArgClass, field);
info.traverse(value -> {
if (value instanceof Path) {
builder.add(QueryFileTarget.of((Path) value));
} else if (value instanceof SourcePath) {
builder.add(extractSourcePath((SourcePath) value));
} else if (value instanceof BuildTarget) {
builder.add(extractBuildTargetContainer((BuildTarget) value));
}
}, node.getConstructorArg());
return builder.build();
} catch (NoSuchFieldException e) {
// Ignore if the field does not exist in this rule.
return ImmutableSet.of();
}
}
Aggregations