1 // Copyright 2016 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; 15 16 import java.util.Objects; 17 import java.util.function.IntSupplier; 18 19 /** This class is for the testing of desugaring calls to Objects.requireNonNull(Object o...) */ 20 public class ClassCallingRequireNonNull { 21 22 public static int getStringLengthWithMethodReference(String s) { 23 return toInt(s::length); 24 } 25 26 public static int toInt(IntSupplier function) { 27 return function.getAsInt(); 28 } 29 30 public static int getStringLengthWithLambdaAndExplicitCallToRequireNonNull(final String s) { 31 return toInt(() -> Objects.requireNonNull(s).length()); 32 } 33 34 public static char getFirstCharVersionOne(String string) { 35 Objects.requireNonNull(string); 36 return string.charAt(0); 37 } 38 39 public static char getFirstCharVersionTwo(String string) { 40 string = Objects.requireNonNull(string); 41 return string.charAt(0); 42 } 43 44 public static char callRequireNonNullWithArgumentString(String string) { 45 string = Objects.requireNonNull(string, "the string should not be null"); 46 return string.charAt(0); 47 } 48 49 public static char callRequireNonNullWithArgumentSupplier(String string) { 50 string = Objects.requireNonNull(string, () -> "the string should not be null"); 51 return string.charAt(0); 52 } 53 } 54