Package org.codehaus.groovy.ast.tools
Class WideningCategories
- java.lang.Object
-
- org.codehaus.groovy.ast.tools.WideningCategories
-
public class WideningCategories extends java.lang.ObjectThis 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 conditionsisIntCategory(ClassNode),isLongCategory(ClassNode),isBigIntCategory(ClassNode),isDoubleCategory(ClassNode)andisBigDecCategory(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.- Author:
- Jochen "blackdrag" Theodorou
-
-
Constructor Summary
Constructors Constructor Description WideningCategories()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ClassNodefirstCommonSuperType(java.util.List<ClassNode> nodes)Given a list of class nodes, returns the first common supertype.static ClassNodefirstCommonSuperType(ClassNode a, ClassNode b)Given two class nodes, returns the first common supertype, or the class itself if there are equal.static booleanisBigDecCategory(ClassNode type)It is of a BigDecimal category, if the provided type is a BigInteger category or a BigDecimal.static booleanisBigIntCategory(ClassNode type)It is of a BigInteger category, if the provided type is a long category or a BigInteger.static booleanisDoubleCategory(ClassNode type)It is of a double category, if the provided type is a BigDecimal, a float, double.static booleanisIntCategory(ClassNode type)It is of an int category, if the provided type is a byte, char, short, int.static booleanisLongCategory(ClassNode type)It is of a long category, if the provided type is a long, its wrapper or if it is a long category.static booleanisNumberCategory(ClassNode type)
-
-
-
Method Detail
-
isIntCategory
public static boolean isIntCategory(ClassNode type)
It is of an int category, if the provided type is a byte, char, short, int.
-
isLongCategory
public static boolean isLongCategory(ClassNode type)
It is of a long category, if the provided type is a long, its wrapper or if it is a long category.
-
isBigIntCategory
public static boolean isBigIntCategory(ClassNode type)
It is of a BigInteger category, if the provided type is a long category or a BigInteger.
-
isBigDecCategory
public static boolean isBigDecCategory(ClassNode type)
It is of a BigDecimal category, if the provided type is a BigInteger category or a BigDecimal.
-
isDoubleCategory
public static boolean isDoubleCategory(ClassNode type)
It is of a double category, if the provided type is a BigDecimal, a float, double. C(type)=double
-
isNumberCategory
public static boolean isNumberCategory(ClassNode type)
-
firstCommonSuperType
public static ClassNode firstCommonSuperType(ClassNode a, ClassNode b)
Given two class nodes, 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.- Parameters:
a- first class nodeb- second class node- Returns:
- first common supertype
-
firstCommonSuperType
public static ClassNode firstCommonSuperType(java.util.List<ClassNode> nodes)
Given a list of class nodes, returns the first common supertype. For example, Double and Float would return Number, while Set and String would return Object.- Parameters:
nodes- the list of nodes for which to find the first common super type.- Returns:
- first common supertype
-
-