langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Assert.java
changeset 29294 376a915b4ff0
parent 25874 83c19f00452c
equal deleted inserted replaced
29293:1583c6dd6df7 29294:376a915b4ff0
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.javac.util;
    26 package com.sun.tools.javac.util;
       
    27 
       
    28 import java.util.function.Supplier;
    27 
    29 
    28 /**
    30 /**
    29  * Simple facility for unconditional assertions.
    31  * Simple facility for unconditional assertions.
    30  * The methods in this class are described in terms of equivalent assert
    32  * The methods in this class are described in terms of equivalent assert
    31  * statements, assuming that assertions have been enabled.
    33  * statements, assuming that assertions have been enabled.
    92         if (!cond)
    94         if (!cond)
    93             error(msg);
    95             error(msg);
    94     }
    96     }
    95 
    97 
    96     /** Equivalent to
    98     /** Equivalent to
       
    99      *   assert cond : msg.get();
       
   100      *  Note: message string is computed lazily.
       
   101      */
       
   102     public static void check(boolean cond, Supplier<String> msg) {
       
   103         if (!cond)
       
   104             error(msg.get());
       
   105     }
       
   106 
       
   107     /** Equivalent to
    97      *   assert (o == null) : value;
   108      *   assert (o == null) : value;
    98      */
   109      */
    99     public static void checkNull(Object o, Object value) {
   110     public static void checkNull(Object o, Object value) {
   100         if (o != null)
   111         if (o != null)
   101             error(String.valueOf(value));
   112             error(String.valueOf(value));
   108         if (o != null)
   119         if (o != null)
   109             error(msg);
   120             error(msg);
   110     }
   121     }
   111 
   122 
   112     /** Equivalent to
   123     /** Equivalent to
       
   124      *   assert (o == null) : msg.get();
       
   125      *  Note: message string is computed lazily.
       
   126      */
       
   127     public static void checkNull(Object o, Supplier<String> msg) {
       
   128         if (o != null)
       
   129             error(msg.get());
       
   130     }
       
   131 
       
   132     /** Equivalent to
   113      *   assert (o != null) : msg;
   133      *   assert (o != null) : msg;
   114      */
   134      */
   115     public static <T> T checkNonNull(T t, String msg) {
   135     public static <T> T checkNonNull(T t, String msg) {
   116         if (t == null)
   136         if (t == null)
   117             error(msg);
   137             error(msg);
       
   138         return t;
       
   139     }
       
   140 
       
   141     /** Equivalent to
       
   142      *   assert (o != null) : msg.get();
       
   143      *  Note: message string is computed lazily.
       
   144      */
       
   145     public static <T> T checkNonNull(T t, Supplier<String> msg) {
       
   146         if (t == null)
       
   147             error(msg.get());
   118         return t;
   148         return t;
   119     }
   149     }
   120 
   150 
   121     /** Equivalent to
   151     /** Equivalent to
   122      *   assert false;
   152      *   assert false;