WideningCategories (Groovy 5.0.0)
Description: declaration: package: org.codehaus.groovy.ast.tools, class: WideningCategories

Package org.codehaus.groovy.ast.tools

# Class WideningCategories

java.lang.Object
org.codehaus.groovy.ast.tools.WideningCategories

public class WideningCategories extends Object
This class provides helper methods to determine the type from a widening operation for example for a plus operation.

To determine the resulting type of for example a=exp1+exp2 we look at the conditions `isIntCategory(ClassNode)`, `isLongCategory(ClassNode)`, `isBigIntCategory(ClassNode)`, `isDoubleCategory(ClassNode)` and `isBigDecCategory(ClassNode)` in that order. The first case applying to exp1 and exp2 is defining the result type of the expression.

If for example you look at x = 1 + 2l we have the first category applying to the number 1 being int, since the 1 is an int. The 2l is a long, therefore the int category will not apply and the result type can't be int. The next category in the list is long, and since both apply to long, the result type is a long.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `WideningCategories.LowestUpperBoundClassNode`
  This `ClassNode` specialization is used when the lowest upper bound of two types cannot be represented by an existing type.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WideningCategories()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `implementsInterfaceOrSubclassOf(ClassNode source, ClassNode target)`
  Determines if the source class implements an interface or subclasses the target type.
  `static boolean`
  `isBigDecCategory(ClassNode type)`
  Checks if type is a BigDecimal, BigInteger, long, int, byte, char or short.
  `static boolean`
  `isBigIntCategory(ClassNode type)`
  Checks if type is a BigInteger, long, int, byte, char or short.
  `static boolean`
  `isDouble(ClassNode type)`
  Checks if type is a double.
  `static boolean`
  `isDoubleCategory(ClassNode type)`
  Checks if type is a float, double or BigDecimal (category).
  `static boolean`
  `isFloat(ClassNode type)`
  Checks if type is a float.
  `static boolean`
  `isFloatingCategory(ClassNode type)`
  Checks if type is a float or double.
  `static boolean`
  `isInt(ClassNode type)`
  Checks if type is an int.
  `static boolean`
  `isIntCategory(ClassNode type)`
  Checks if type is an int, byte, char or short.
  `static boolean`
  `isLongCategory(ClassNode type)`
  Checks if type is a long, int, byte, char or short.
  `static boolean`
  `isNumberCategory(ClassNode type)`
  Checks if type is a BigDecimal (category) or Number.
  `static ClassNode`
  `lowestUpperBound(List<ClassNode> nodes)`
  Given a list of types, returns the first common supertype.
  `static ClassNode`
  `lowestUpperBound(ClassNode a, ClassNode b)`
  Given two types, returns the first common supertype, or the class itself if there are equal.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### WideningCategories

    public WideningCategories()

- ## Method Details

  - ### isInt

    public static boolean isInt(ClassNode type)
    Checks if type is an int.
    Since:
      2.0.0

  - ### isFloat

    public static boolean isFloat(ClassNode type)
    Checks if type is a float.
    Since:
      2.0.0

  - ### isDouble

    public static boolean isDouble(ClassNode type)
    Checks if type is a double.
    Since:
      2.0.0

  - ### isIntCategory

    public static boolean isIntCategory(ClassNode type)
    Checks if type is an int, byte, char or short.
    Since:
      2.0.0

  - ### isLongCategory

    public static boolean isLongCategory(ClassNode type)
    Checks if type is a long, int, byte, char or short.
    Since:
      2.0.0

  - ### isBigIntCategory

    public static boolean isBigIntCategory(ClassNode type)
    Checks if type is a BigInteger, long, int, byte, char or short.
    Since:
      2.0.0

  - ### isBigDecCategory

    public static boolean isBigDecCategory(ClassNode type)
    Checks if type is a BigDecimal, BigInteger, long, int, byte, char or short.
    Since:
      2.0.0

  - ### isDoubleCategory

    public static boolean isDoubleCategory(ClassNode type)
    Checks if type is a float, double or BigDecimal (category).
    Since:
      2.0.0

  - ### isFloatingCategory

    public static boolean isFloatingCategory(ClassNode type)
    Checks if type is a float or double.
    Since:
      2.0.0

  - ### isNumberCategory

    public static boolean isNumberCategory(ClassNode type)
    Checks if type is a BigDecimal (category) or Number.
    Since:
      2.0.0

  - ### lowestUpperBound

    public static ClassNode lowestUpperBound(List<ClassNode> nodes)
    Given a list of types, returns the first common supertype. For example, Double and Float would return Number, while Set and String would return Object.
    Since:
      2.0.0

  - ### lowestUpperBound

    public static ClassNode lowestUpperBound(ClassNode a, ClassNode b)
    Given two types, returns the first common supertype, or the class itself if there are equal. For example, Double and Float would return Number, while Set and String would return Object.

    This method is not guaranteed to return a class node which corresponds to a real type. For example, if two types have more than one interface in common and are not in the same hierarchy branch, then the returned type will be a virtual type implementing all those interfaces.

    Calls to this method are supposed to be made with resolved generics. This means that you can have wildcards, but no placeholder.

    Since:
      2.0.0

  - ### implementsInterfaceOrSubclassOf

    public static boolean implementsInterfaceOrSubclassOf(ClassNode source, ClassNode target)
    Determines if the source class implements an interface or subclasses the target type. This method takes the `lowest upper bound class node` type into account, allowing removal of unnecessary casts.
    Since:
      2.3.0