• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Bazel Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 package com.google.devtools.build.android.desugar.testdata.java8;
15 
16 import java.util.List;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 
20 /**
21  * Desugar test input interface that declares lambdas and method references in default and static
22  * interface methods.
23  */
24 public interface InterfaceMethod {
defaultMethodReference(List<String> names)25   public default List<String> defaultMethodReference(List<String> names) {
26     return names.stream().filter(this::startsWithS).collect(Collectors.toList());
27   }
28 
defaultInvokingBootclasspathMethods(String expectedValue)29   public default String defaultInvokingBootclasspathMethods(String expectedValue) {
30     return Stream.of(expectedValue).findFirst().orElse("unexpected");
31   }
32 
staticMethodReference(List<String> names)33   public default List<String> staticMethodReference(List<String> names) {
34     return names.stream().filter(InterfaceMethod::startsWithA).collect(Collectors.toList());
35   }
36 
lambdaCallsDefaultMethod(List<String> names)37   public default List<String> lambdaCallsDefaultMethod(List<String> names) {
38     return names.stream().filter(s -> startsWithS(s)).collect(Collectors.toList());
39   }
40 
startsWithA(String input)41   public static boolean startsWithA(String input) {
42     return input.startsWith("A");
43   }
44 
startsWithS(String input)45   public default boolean startsWithS(String input) {
46     return input.startsWith("S");
47   }
48 
49   /**
50    * Empty class implementing {@link InterfaceMethod} so the test can instantiate and call default
51    * methods.
52    */
53   public static class Concrete implements InterfaceMethod {}
54 }
55