Class SystemUtil

java.lang.Object
org.checkerframework.javacutil.SystemUtil

public class SystemUtil extends Object
This file contains basic utility functions.
  • Field Details

    • jreVersion

      public static final int jreVersion
      The major version number of the Java runtime (JRE), such as 8, 11, or 17.
  • Method Details

    • getJreVersion

      @Deprecated public static int getJreVersion()
      Deprecated.
      use field jreVersion instead
      Returns the major version number from the "java.version" system property, such as 8, 11, or 17.

      This is different from the version passed to the compiler via --release; use getReleaseValue(ProcessingEnvironment) to get that version.

      Extract the major version number from the "java.version" system property. Two possible formats are considered. Up to Java 8, from a version string like `1.8.whatever`, this method extracts 8. Since Java 9, from a version string like `11.0.1`, this method extracts 11.

      Starting in Java 9, there is the int Runtime.version().feature(), but that does not exist on JDK 8.

      Returns:
      the major version of the Java runtime
    • getReleaseValue

      public static @Nullable String getReleaseValue(ProcessingEnvironment env)
      Returns the release value passed to the compiler or null if release was not passed.
      Parameters:
      env - the ProcessingEnvironment
      Returns:
      the release value or null if none was passed
    • getToolsJar

      public static @Nullable String getToolsJar()
      Returns the pathname to the tools.jar file, or null if it does not exist. Returns null on Java 9 and later.
      Returns:
      the pathname to the tools.jar file, or null
    • union

      @Deprecated public static <T> List<T> union(List<T> list1, List<T> list2)
      Deprecated.
      use CollectionsPlume.listUnion
      Returns a list that contains all the distinct elements of the two lists: that is, the union of the two arguments.

      For very short lists, this is likely more efficient than creating a set and converting back to a list.

      Type Parameters:
      T - the type of the list elements
      Parameters:
      list1 - a list
      list2 - a list
      Returns:
      a list that contains all the distinct elements of the two lists
    • addWithoutDuplicates

      @Deprecated public static <T> void addWithoutDuplicates(List<T> dest, List<? extends T> source)
      Deprecated.
      use CollectionsPlume.adjoinAll
      Adds, to dest, all the elements of source that are not already in dest.

      For very short lists, this is likely more efficient than creating a set and converting back to a list.

      Type Parameters:
      T - the type of the list elements
      Parameters:
      dest - a list to add to
      source - a list of elements to add
    • intersection

      @Deprecated public static <T> List<T> intersection(List<? extends T> list1, List<? extends T> list2)
      Deprecated.
      use CollectionsPlume.listIntersection
      Returns a list that contains all the elements that are in both lists: that is, the set difference of the two arguments.

      For very short lists, this is likely more efficient than creating a set and converting back to a list.

      Type Parameters:
      T - the type of the list elements
      Parameters:
      list1 - a list
      list2 - a list
      Returns:
      a list that contains all the elements of list1 that are not in list2
    • withoutDuplicatesSorted

      public static <T extends Comparable<T>> List<T> withoutDuplicatesSorted(List<T> values)
      Returns a list with the same contents as its argument, but sorted and without duplicates. May return its argument if its argument is sorted and has no duplicates, but is not guaranteed to do so. The argument is not modified.

      This is like withoutDuplicates, but requires the list elements to implement Comparable, and thus can be more efficient.

      Type Parameters:
      T - the type of elements in values
      Parameters:
      values - a list of values
      Returns:
      the values, with duplicates removed
    • readFile

      @Deprecated public static List<String> readFile(File argFile) throws IOException
      Deprecated.
      use Files.readAllLines
      Return a list of Strings, one per line of the file.
      Parameters:
      argFile - argument file
      Returns:
      a list of Strings, one per line of the file
      Throws:
      IOException - when reading the argFile
    • sleep

      @Deprecated public static void sleep(long millis)
      Deprecated.
      use SystemPlume.sleep
      Like Thread.sleep, but does not throw any exceptions, so it is easier for clients to use. Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
      Parameters:
      millis - the length of time to sleep in milliseconds
    • concatenate

      @Deprecated public static <T> T[] concatenate(T firstElt, T[] array, T lastElt)
      Deprecated.
      use PlumeUtil.concat
      Concatenates an element, an array, and an element.
      Type Parameters:
      T - the type of the array elements
      Parameters:
      firstElt - the first element
      array - the array
      lastElt - the last elemeent
      Returns:
      a new array containing first element, the array, and the last element, in that order
    • getBooleanSystemProperty

      @Deprecated public static boolean getBooleanSystemProperty(String key)
      Deprecated.
      use UtilPlume.getBooleanSystemProperty
      Return true if the system property is set to "true". Return false if the system property is not set or is set to "false". Otherwise, errs.
      Parameters:
      key - system property to check
      Returns:
      true if the system property is set to "true". Return false if the system property is not set or is set to "false". Otherwise, errs.
    • getBooleanSystemProperty

      @Deprecated public static boolean getBooleanSystemProperty(String key, boolean defaultValue)
      Deprecated.
      use UtilPlume.getBooleanSystemProperty
      Return its boolean value if the system property is set. Return defaultValue if the system property is not set. Errs if the system property is set to a non-boolean value.
      Parameters:
      key - system property to check
      defaultValue - value to use if the property is not set
      Returns:
      the boolean value of key or defaultValue if key is not set
    • concatenate

      @Deprecated public static <T> T[] concatenate(T[] array1, T... array2)
      Deprecated.
      use StringsPlume.concatenate
      Concatenates two arrays. Can be invoked varargs-style.
      Type Parameters:
      T - the type of the array elements
      Parameters:
      array1 - the first array
      array2 - the second array
      Returns:
      a new array containing the contents of the given arrays, in order
    • mapCapacity

      @Deprecated public static int mapCapacity(int numElements)
      Deprecated.
      use CollectionsPlume.mapCapacity
      Given an expected number of elements, returns the capacity that should be passed to a HashMap or HashSet constructor, so that the set or map will not resize.
      Parameters:
      numElements - the maximum expected number of elements in the map or set
      Returns:
      the initial capacity to pass to a HashMap or HashSet constructor
    • mapCapacity

      @Deprecated public static int mapCapacity(Collection<?> c)
      Deprecated.
      use CollectionsPlume.mapCapacity
      Given an expected number of elements, returns the capacity that should be passed to a HashMap or HashSet constructor, so that the set or map will not resize.
      Parameters:
      c - a collection whose size is the maximum expected number of elements in the map or set
      Returns:
      the initial capacity to pass to a HashMap or HashSet constructor
    • mapCapacity

      @Deprecated public static int mapCapacity(Map<?,?> m)
      Deprecated.
      use CollectionsPlume.mapCapacity
      Given an expected number of elements, returns the capacity that should be passed to a HashMap or HashSet constructor, so that the set or map will not resize.
      Parameters:
      m - a map whose size is the maximum expected number of elements in the map or set
      Returns:
      the initial capacity to pass to a HashMap or HashSet constructor