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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | WideningCategories.LowestUpperBoundClassNode
This |
| Modifier and Type | Field and Description |
|---|---|
| private static final Comparator | INTERFACE_CLASSNODE_COMPARATOR
A comparator which is used in case we generate a virtual lower upper bound class node. |
| private static final Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| private static boolean | Returns: true if the class nodes are equal, false otherwiseCompares two class nodes, but including their generics types. |
| private static ClassNode | Returns: the class node representing the lowest upper boundinterfaces both class nodes share, which their lowest common super class do not implement. interfaces)Given two class nodes supposedly at the upper common level, returns a class node which is able to represent their lowest upper bound. |
| private static void | extractMostSpecificImplementedInterfaces(final ClassNode type, final ClassNode inode, final List<ClassNode> result)
|
| private static ClassNode | |
| public static boolean | implementsInterfaceOrSubclassOf(final ClassNode source, final ClassNode target)
Determines if the source class implements an interface or subclasses the target type. |
| public static boolean | isBigDecCategory(final ClassNode type)
Checks if type is a BigDecimal, BigInteger, long, int, byte, char or short. |
| public static boolean | isBigIntCategory(final ClassNode type)
Checks if type is a BigInteger, long, int, byte, char or short. |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| private static List | keepLowestCommonInterfaces(final Set<ClassNode> fromA, final Set<ClassNode> fromB)
Given the interfaces implemented by two types, returns a list of the most specific common implemented interfaces. |
| public static ClassNode | lowestUpperBound(final List<ClassNode> nodes)
Given a list of types, returns the first common supertype. |
| public static ClassNode | lowestUpperBound(final ClassNode a, final ClassNode b)
Given two types, returns the first common supertype, or the class itself if there are equal. |
| private static ClassNode | |
| private static ClassNode | Returns: the class node representing the parameterized lowest upper boundthe type to be parameterized lub, final ClassNode parameterized type a a, final ClassNode parameterized type b b, final ClassNode if we detect a recursive call, use this LUB as the parameterized type instead of computing a value fallback)Given a lowest upper bound computed without generic type information but which requires to be parameterized and the two implementing classnodes which are parameterized with potentially two different types, returns a parameterized lowest upper bound. |
| private static ClassNode |
| INTERFACE_CLASSNODE_COMPARATOR | back to summary |
|---|---|
| private static final Comparator<ClassNode> INTERFACE_CLASSNODE_COMPARATOR A comparator which is used in case we generate a virtual lower upper bound class node. In that case, since a concrete implementation should be used at compile time, we must ensure that interfaces are always sorted. It is not important what sort is used, as long as the result is constant. | |
| NUMBER_TYPES_PRECEDENCE | back to summary |
|---|---|
| private static final Map<ClassNode, Integer> NUMBER_TYPES_PRECEDENCE | |
| WideningCategories | back to summary |
|---|---|
| public WideningCategories() | |
| addMostSpecificInterface | back to summary |
|---|---|
| private static void addMostSpecificInterface(final ClassNode interfaceNode, final List<ClassNode> nodes) | |
| areEqualWithGenerics | back to summary |
|---|---|
| private static boolean areEqualWithGenerics(final ClassNode a, final ClassNode b) Compares two class nodes, but including their generics types.
| |
| buildTypeWithInterfaces | back to summary |
|---|---|
| private static ClassNode buildTypeWithInterfaces(final ClassNode baseType1, final ClassNode baseType2, final Collection<ClassNode> interfaces) Given two class nodes supposedly at the upper common level, returns a class node which is able to represent their lowest upper bound.
| |
| extractMostSpecificImplementedInterfaces | back to summary |
|---|---|
| private static void extractMostSpecificImplementedInterfaces(final ClassNode type, final ClassNode inode, final List<ClassNode> result) | |
| findGenericsTypeHolderForClass | back to summary |
|---|---|
| private static ClassNode findGenericsTypeHolderForClass(ClassNode source, final ClassNode target) | |
| implementsInterfaceOrSubclassOf | back to summary |
|---|---|
| public static boolean implementsInterfaceOrSubclassOf(final ClassNode source, final ClassNode target) Determines if the source class implements an interface or subclasses the
target type. This method takes the
| |
| isBigDecCategory | back to summary |
|---|---|
| public static boolean isBigDecCategory(final ClassNode type) Checks if type is a BigDecimal, BigInteger, long, int, byte, char or short.
| |
| isBigIntCategory | back to summary |
|---|---|
| public static boolean isBigIntCategory(final ClassNode type) Checks if type is a BigInteger, long, int, byte, char or short.
| |
| isDouble | back to summary |
|---|---|
| public static boolean isDouble(final ClassNode type) Checks if type is a double.
| |
| isDoubleCategory | back to summary |
|---|---|
| public static boolean isDoubleCategory(final ClassNode type) Checks if type is a float, double or BigDecimal (category).
| |
| isFloat | back to summary |
|---|---|
| public static boolean isFloat(final ClassNode type) Checks if type is a float.
| |
| isFloatingCategory | back to summary |
|---|---|
| public static boolean isFloatingCategory(final ClassNode type) Checks if type is a float or double.
| |
| isInt | back to summary |
|---|---|
| public static boolean isInt(final ClassNode type) Checks if type is an int.
| |
| isIntCategory | back to summary |
|---|---|
| public static boolean isIntCategory(final ClassNode type) Checks if type is an int, byte, char or short.
| |
| isLongCategory | back to summary |
|---|---|
| public static boolean isLongCategory(final ClassNode type) Checks if type is a long, int, byte, char or short.
| |
| isNumberCategory | back to summary |
|---|---|
| public static boolean isNumberCategory(final ClassNode type) Checks if type is a BigDecimal (category) or Number.
| |
| keepLowestCommonInterfaces | back to summary |
|---|---|
| private static List Given the interfaces implemented by two types, returns a list of the most specific common implemented interfaces. | |
| lowestUpperBound | back to summary |
|---|---|
| public static ClassNode lowestUpperBound(final 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.
| |
| lowestUpperBound | back to summary |
|---|---|
| public static ClassNode lowestUpperBound(final ClassNode a, final 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.
| |
| lowestUpperBound | back to summary |
|---|---|
| private static ClassNode lowestUpperBound(final ClassNode a, final ClassNode b, Set<ClassNode> interfacesImplementedByA, Set<ClassNode> interfacesImplementedByB) | |
| parameterizeLowestUpperBound | back to summary |
|---|---|
| private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final ClassNode a, final ClassNode b, final ClassNode fallback) Given a lowest upper bound computed without generic type information but which requires to be parameterized and the two implementing classnodes which are parameterized with potentially two different types, returns a parameterized lowest upper bound. For example, if LUB is Set<T> and a is Set<String> and b is Set<StringBuffer>, this will return a LUB which parameterized type matches Set<? extends CharSequence>
| |
| upperBound | back to summary |
|---|---|
| private static ClassNode upperBound(final GenericsType gt) | |
ClassNode specialization is used when the lowest upper bound of two types
cannot be represented by an existing type. For example, if B extends A, C extends A
and both C and B implement a common interface not implemented by A, then we use this class
to represent the bound.
At compile time, some classes like org.codehaus.groovy.classgen.AsmClassGenerator need
to know about a real class node, so we compute a "compile time" node which will be used
to return a name and a type class.
| Modifier and Type | Field and Description |
|---|---|
| private final ClassNode | |
| private final ClassNode[] | |
| private final String | |
| private final String | |
| private final ClassNode |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public GenericsType | |
| public String | |
| public String | |
| public ClassNode | |
| public String | |
| public Class | getTypeClass()
Returns the concrete class this classnode relates to.
|
| public int | hashCode()
Overrides org. |
| compileTimeClassNode | back to summary |
|---|---|
| private final ClassNode compileTimeClassNode | |
| interfaces | back to summary |
|---|---|
| private final ClassNode[] interfaces | |
| name | back to summary |
|---|---|
| private final String name | |
| text | back to summary |
|---|---|
| private final String text | |
| upper | back to summary |
|---|---|
| private final ClassNode upper | |
| LowestUpperBoundClassNode | back to summary |
|---|---|
| public LowestUpperBoundClassNode(final String name, final ClassNode upper, final ClassNode... interfaces) | |
| asGenericsType | back to summary |
|---|---|
| public GenericsType asGenericsType() Overrides org.
| |
| getLubName | back to summary |
|---|---|
| public String getLubName() | |
| getName | back to summary |
|---|---|
| public String getName() Overrides org.
| |
| getPlainNodeReference | back to summary |
|---|---|
| public ClassNode getPlainNodeReference() Overrides org.
| |
| getText | back to summary |
|---|---|
| public String getText() Overrides org.
| |
| getTypeClass | back to summary |
|---|---|
| public Class Overrides org. Doc from org. Returns the concrete class this classnode relates to. However, this method
is inherently unsafe as it may return null depending on the compile phase you are
using. AST transformations should never use this method directly, but rather obtain
a new class node using | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides org. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |