Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package rewrite; |
| 5 | |
| 6 | import java.util.Objects; |
| 7 | |
| 8 | public class RequireNonNull { |
| 9 | |
| 10 | public static void main(String[] args) { |
| 11 | RequireNonNull o = new RequireNonNull(); |
| 12 | System.out.println(o.nonnullRemove().toString()); |
| 13 | System.out.println(o.nonnullRemove(o).toString()); |
| 14 | o.nonnullWithPhiInstruction(true, o); |
| 15 | o.nonnullWithPhiInstruction(false, o); |
| 16 | } |
| 17 | |
| 18 | private Object nonnullRemove() { |
| 19 | return Objects.requireNonNull(this); |
| 20 | } |
| 21 | |
| 22 | private Object nonnullRemove(Object o) { |
| 23 | Objects.requireNonNull(o); |
| 24 | return o; |
| 25 | } |
| 26 | |
| 27 | private void nonnullWithPhiInstruction(boolean b, Object input) { |
| 28 | Object o = null; |
| 29 | if (b) { |
| 30 | o = Objects.requireNonNull(input); |
| 31 | } |
| 32 | System.out.println(o); |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public String toString() { |
| 37 | return "toString"; |
| 38 | } |
| 39 | } |