Search in sources :

Example 1 with ParamInfo

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();
    }
}
Also used : Field(java.lang.reflect.Field) ImmutableSet(com.google.common.collect.ImmutableSet) ParamInfo(com.facebook.buck.rules.ParamInfo)

Example 2 with ParamInfo

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();
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Field(java.lang.reflect.Field) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) ParamInfo(com.facebook.buck.rules.ParamInfo)

Aggregations

ParamInfo (com.facebook.buck.rules.ParamInfo)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Field (java.lang.reflect.Field)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 Path (java.nio.file.Path)1