Class IntersectionSourceType
- java.lang.Object
-
- com.tonic.analysis.source.ast.type.IntersectionSourceType
-
- All Implemented Interfaces:
ASTNode,SourceType
public final class IntersectionSourceType extends Object implements SourceType
An intersection type such as "A & B", as written in a type parameter bound; it lowers to its first bound.
-
-
Constructor Summary
Constructors Constructor Description IntersectionSourceType(SourceType... bounds)Creates an intersection from a bound array.IntersectionSourceType(List<SourceType> bounds)Creates an intersection over a copied, unmodifiable bound list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.booleanequals(Object o)SourceTypegetBound(int index)intgetBoundCount()List<SourceType>getBounds()SourceTypegetFirstBound()inthashCode()IRTypetoIRType()Converts this source type to the equivalent IR type.StringtoJavaSource()Converts this source type to Java source code representation.StringtoString()-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getChildren, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
Methods inherited from interface com.tonic.analysis.source.ast.type.SourceType
getLocation, getParent, isArray, isPrimitive, isReference, isVoid, setParent
-
-
-
-
Constructor Detail
-
IntersectionSourceType
public IntersectionSourceType(List<SourceType> bounds)
Creates an intersection over a copied, unmodifiable bound list.- Parameters:
bounds- the intersected types, at least two- Throws:
IllegalArgumentException- if fewer than two bounds are given
-
IntersectionSourceType
public IntersectionSourceType(SourceType... bounds)
Creates an intersection from a bound array.- Parameters:
bounds- the intersected types, at least two and none null- Throws:
IllegalArgumentException- if fewer than two bounds are givenNullPointerException- if the array or any bound is null
-
-
Method Detail
-
getBounds
public List<SourceType> getBounds()
- Returns:
- the bounds
-
getBoundCount
public int getBoundCount()
- Returns:
- the number of intersected types
-
getBound
public SourceType getBound(int index)
- Parameters:
index- the position in the bound list- Returns:
- the bound at a position
- Throws:
IndexOutOfBoundsException- if the position is out of range
-
getFirstBound
public SourceType getFirstBound()
- Returns:
- the leading bound, which the type erases to
-
toJavaSource
public String toJavaSource()
Description copied from interface:SourceTypeConverts this source type to Java source code representation.- Specified by:
toJavaSourcein interfaceSourceType- Returns:
- the Java source representation (e.g., "int", "String", "int[]")
-
toIRType
public IRType toIRType()
Description copied from interface:SourceTypeConverts this source type to the equivalent IR type.- Specified by:
toIRTypein interfaceSourceType- Returns:
- the corresponding IRType
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-