/** * Parses wildcard info from type definitions * * @param wildcard * @return */ protected static WildCardInfo ParseWildCard(WildcardType wildcard) { WildCardInfo wildcardInfo = null; if (wildcard != null) { wildcardInfo = new WildCardInfo(); Type[] extendTypes = wildcard.extendsBounds(); if (extendTypes != null && extendTypes.length > 0) { TypeInfo[] extendInfo = new TypeInfo[extendTypes.length]; for (int i = 0; i < extendTypes.length; i++) { extendInfo[i] = ParseType(extendTypes[i]); } wildcardInfo.extendsBounds = extendInfo; } Type[] superTypes = wildcard.superBounds(); if (superTypes != null && superTypes.length > 0) { TypeInfo[] superInfo = new TypeInfo[superTypes.length]; for (int i = 0; i < superTypes.length; i++) { superInfo[i] = ParseType(superTypes[i]); } wildcardInfo.superBounds = superInfo; } } return wildcardInfo; }
private Type getElementType(ParameterizedType type, int index) { Type elementType = type.getActualTypeArguments()[index]; if (elementType instanceof WildcardType) { WildcardType wildcardType = (WildcardType) elementType; return wildcardType.getUpperBounds()[0]; } return elementType; }
@SuppressWarnings({"unchecked", "cast"}) public WildcardType fullCopy() { WildcardType res = (WildcardType) copy(); for (int i = 0; i < getNumChildNoTransform(); i++) { ASTNode node = getChildNoTransform(i); if (node != null) node = node.fullCopy(); res.setChild(node, i); } return res; }
@SuppressWarnings({"unchecked", "cast"}) public WildcardType copy() { try { WildcardType node = (WildcardType) clone(); if (children != null) node.children = (ASTNode[]) children.clone(); return node; } catch (CloneNotSupportedException e) { } System.err.println("Error: Could not clone node of type " + getClass().getName() + "!"); return null; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; return wildcard.equals(((TypeVarBoundedType) o).typeVariable); }
@SuppressWarnings({"unchecked", "cast"}) public WildcardType clone() throws CloneNotSupportedException { WildcardType node = (WildcardType) super.clone(); node.subtype_TypeDecl_values = null; node.containedIn_TypeDecl_values = null; node.instanceOf_TypeDecl_values = null; node.in$Circle(false); node.is$Final(false); return node; }
@Override public int hashCode() { return wildcard.hashCode(); }
/** @return The first bound, either a type or a reference to a TypeVariable */ public Type firstBound() { Type[] lowerBounds = wildcard.getLowerBounds(); Type[] upperBounds = wildcard.getUpperBounds(); return lowerBounds.length != 0 ? lowerBounds[0] : upperBounds[0]; }
@Override public JsonType visitWildcard(WildcardType wildcardType, Void o) { throw new UnsupportedOperationException(wildcardType.toString()); }