Package org.codehaus.groovy.ast.tools
Class WideningCategories
java.lang.Object
org.codehaus.groovy.ast.tools.WideningCategories
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 SummaryNested ClassesModifier and TypeClassDescriptionstatic classThisClassNodespecialization is used when the lowest upper bound of two types cannot be represented by an existing type.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanimplementsInterfaceOrSubclassOf(ClassNode source, ClassNode targetType) Determines if the source class implements an interface or subclasses the target type.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 booleanUsed to check if a type is a double or Double.static booleanisDoubleCategory(ClassNode type) It is of a double category, if the provided type is a BigDecimal, a float, double.static booleanUsed to check if a type is a float or Float.static booleanisFloatingCategory(ClassNode type) It is of a floating category, if the provided type is a float, double.static booleanUsed to check if a type is an int or Integer.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) static ClassNodelowestUpperBound(List<ClassNode> nodes) Given a list of class nodes, returns the first common supertype.static ClassNodeGiven two class nodes, returns the first common supertype, or the class itself if there are equal.
- 
Constructor Details- 
WideningCategoriespublic WideningCategories()
 
- 
- 
Method Details- 
isIntUsed to check if a type is an int or Integer.- Parameters:
- type- the type to check
 
- 
isDoubleUsed to check if a type is a double or Double.- Parameters:
- type- the type to check
 
- 
isFloatUsed to check if a type is a float or Float.- Parameters:
- type- the type to check
 
- 
isIntCategoryIt is of an int category, if the provided type is a byte, char, short, int.
- 
isLongCategoryIt is of a long category, if the provided type is a long, its wrapper or if it is a long category.
- 
isBigIntCategoryIt is of a BigInteger category, if the provided type is a long category or a BigInteger.
- 
isBigDecCategoryIt is of a BigDecimal category, if the provided type is a BigInteger category or a BigDecimal.
- 
isDoubleCategoryIt is of a double category, if the provided type is a BigDecimal, a float, double. C(type)=double
- 
isFloatingCategoryIt is of a floating category, if the provided type is a float, double. C(type)=float
- 
isNumberCategory
- 
lowestUpperBoundGiven 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
 
- 
lowestUpperBoundGiven 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. 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.- Parameters:
- a- first class node
- b- second class node
- Returns:
- first common supertype
 
- 
implementsInterfaceOrSubclassOfDetermines if the source class implements an interface or subclasses the target type. This method takes thelowest upper bound class nodetype into account, allowing to remove unnecessary casts.- Parameters:
- source- the type of interest
- targetType- the target type of interest
 
 
-