Automated conversion to Java 8
With a few manual fixes for readability.
RELNOTES: None.
PiperOrigin-RevId: 160582556
diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
index 7fa0051..601ae5c 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
@@ -13,11 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.query2;
-import com.google.common.base.Function;
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
+
import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
@@ -68,13 +67,6 @@
* The environment of a Blaze query. Not thread-safe.
*/
public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment<Target> {
- private static final Function<Target, Label> TO_LABEL = new Function<Target, Label>() {
- @Override
- public Label apply(Target input) {
- return input.getLabel();
- }
- };
-
private static final int MAX_DEPTH_FULL_SCAN_LIMIT = 20;
private final Map<String, Set<Target>> resolvedTargetPatterns = new HashMap<>();
private final TargetPatternEvaluator targetPatternEvaluator;
@@ -323,7 +315,7 @@
if (maxDepth >= MAX_DEPTH_FULL_SCAN_LIMIT && transitivePackageLoader != null) {
// Only do the full visitation if "maxDepth" is large enough. Otherwise, the benefits of
// preloading will be outweighed by the cost of doing more work than necessary.
- Set<Label> labels = ImmutableSet.copyOf(Collections2.transform(targets, TO_LABEL));
+ Set<Label> labels = targets.stream().map(Target::getLabel).collect(toImmutableSet());
transitivePackageLoader.sync(eventHandler, labels, keepGoing, loadingPhaseThreads);
}
}
@@ -421,15 +413,6 @@
}
return dependentFiles;
}
-
- private static final Function<ResolvedTargets<Target>, Set<Target>> RESOLVED_TARGETS_TO_TARGETS =
- new Function<ResolvedTargets<Target>, Set<Target>>() {
- @Override
- public Set<Target> apply(ResolvedTargets<Target> resolvedTargets) {
- return resolvedTargets.getTargets();
- }
- };
-
@Override
protected void preloadOrThrow(QueryExpression caller, Collection<String> patterns)
throws TargetParsingException, InterruptedException {
@@ -439,7 +422,7 @@
resolvedTargetPatterns.putAll(
Maps.transformValues(
targetPatternEvaluator.preloadTargetPatterns(eventHandler, patterns, keepGoing),
- RESOLVED_TARGETS_TO_TARGETS));
+ ResolvedTargets::getTargets));
}
}