Class UnionSourceType
- java.lang.Object
-
- com.tonic.analysis.source.ast.type.UnionSourceType
-
- All Implemented Interfaces:
ASTNode,SourceType
public final class UnionSourceType extends Object implements SourceType
Represents a union type, e.g., catch (IOException | SQLException e).
-
-
Constructor Summary
Constructors Constructor Description UnionSourceType(SourceType... alternatives)Creates a union type from a varargs list.UnionSourceType(List<SourceType> alternatives)Creates a union type from a list, copied defensively.
-
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)SourceTypegetAlternative(int index)Reads one alternative by position.intgetAlternativeCount()List<SourceType>getAlternatives()SourceTypegetFirstAlternative()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
-
UnionSourceType
public UnionSourceType(List<SourceType> alternatives)
Creates a union type from a list, copied defensively.- Parameters:
alternatives- the alternative types, at least 2- Throws:
IllegalArgumentException- if the list is null or holds fewer than 2 alternatives
-
UnionSourceType
public UnionSourceType(SourceType... alternatives)
Creates a union type from a varargs list.- Parameters:
alternatives- the alternative types, at least 2- Throws:
IllegalArgumentException- if fewer than 2 alternatives are given
-
-
Method Detail
-
getAlternatives
public List<SourceType> getAlternatives()
- Returns:
- the alternatives
-
getAlternativeCount
public int getAlternativeCount()
- Returns:
- the number of alternatives, always at least 2
-
getAlternative
public SourceType getAlternative(int index)
Reads one alternative by position.- Parameters:
index- the zero-based position- Returns:
- the alternative type
- Throws:
IndexOutOfBoundsException- if the index is outside the alternative list
-
getFirstAlternative
public SourceType getFirstAlternative()
- Returns:
- the first alternative
-
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.
-
-