Class ArraySourceType
- java.lang.Object
-
- com.tonic.analysis.source.ast.type.ArraySourceType
-
- All Implemented Interfaces:
ASTNode,SourceType
public final class ArraySourceType extends Object implements SourceType
Represents an array type in the source AST.
-
-
Constructor Summary
Constructors Constructor Description ArraySourceType(SourceType componentType)Creates a one-dimensional array type.ArraySourceType(SourceType componentType, int dimensions)Creates an array type with an explicit dimension count.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.ArraySourceTypeaddDimension()Creates an array type over the same component with one additional dimension.booleanequals(Object obj)SourceTypegetComponentType()intgetDimensions()SourceTypegetElementType()Descends through nested array component types to the non-array base.intgetTotalDimensions()Sums this type's dimension count with those of any nested array component types.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
-
ArraySourceType
public ArraySourceType(SourceType componentType)
Creates a one-dimensional array type.- Parameters:
componentType- the component type- Throws:
NullPointerException- if the component type is null
-
ArraySourceType
public ArraySourceType(SourceType componentType, int dimensions)
Creates an array type with an explicit dimension count.- Parameters:
componentType- the component typedimensions- the number of dimensions, at least 1- Throws:
NullPointerException- if the component type is nullIllegalArgumentException- if the dimension count is below 1
-
-
Method Detail
-
getComponentType
public SourceType getComponentType()
- Returns:
- the component type
-
getDimensions
public int getDimensions()
- Returns:
- the dimensions
-
getElementType
public SourceType getElementType()
Descends through nested array component types to the non-array base.- Returns:
- the element type, so int for int[][]
-
addDimension
public ArraySourceType addDimension()
Creates an array type over the same component with one additional dimension.- Returns:
- the widened array type
-
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[]")
-
getTotalDimensions
public int getTotalDimensions()
Sums this type's dimension count with those of any nested array component types.- Returns:
- the total dimension count
-
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.
-
-