Class SimValueBuilder
- java.lang.Object
-
- com.tonic.analysis.simulation.heap.SimValueBuilder
-
public final class SimValueBuilder extends Object
Builder API for constructing simulated values with field initialization.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SimValueBuilderasArray(SimValue... elements)Replaces the array contents and sets the length to match.SimValuebuild(SimHeap heap)Materializes the value, allocating on the heap and recursively building nested field builders.SimValueBuilderdefinitelyNotNull()Marks the value as non-null.SimValueBuilderdefinitelyNull()Marks the value as null, dropping any allocation site.static SimValueBuilderforArray(IRType elementType)Starts a builder for a one-dimensional array.static SimValueBuilderforClass(String className)Starts a builder for an object type, accepting dotted or slashed names.static SimValueBuilderforType(IRType type)Starts a builder for an IR type.IRTypegetType()SimValueBuildernullable()Marks the value as possibly null, the default state.StringtoString()SimValueBuilderwithAllocationSite(AllocationSite site)Pins the value to an allocation site, which also makes it non-null.SimValueBuilderwithArrayElement(SimValue element)Appends one element at the next index.SimValueBuilderwithArrayLength(int length)Sets the array length independently of the elements supplied.SimValueBuilderwithBooleanValue(boolean value)Sets the constant this value carries, stored as the int 0 or 1.SimValueBuilderwithDoubleValue(double value)Sets the constant this value carries.SimValueBuilderwithField(String fieldName, boolean value)Sets a field to a boolean constant.SimValueBuilderwithField(String fieldName, int value)Sets a field to an int constant.SimValueBuilderwithField(String fieldName, long value)Sets a field to a long constant.SimValueBuilderwithField(String fieldName, SimValueBuilder nested)Sets a field to a nested builder, built against the same heap at build time.SimValueBuilderwithField(String fieldName, SimValue value)Sets a field to an already built value.SimValueBuilderwithField(String fieldName, String value)Sets a field to a java.lang.String constant.SimValueBuilderwithFloatValue(float value)Sets the constant this value carries.SimValueBuilderwithIntValue(int value)Sets the constant this value carries.SimValueBuilderwithLongValue(long value)Sets the constant this value carries.SimValueBuilderwithStringValue(String value)Sets the constant this value carries.
-
-
-
Method Detail
-
forType
public static SimValueBuilder forType(IRType type)
Starts a builder for an IR type.- Parameters:
type- the value type- Returns:
- the new builder
-
forClass
public static SimValueBuilder forClass(String className)
Starts a builder for an object type, accepting dotted or slashed names.- Parameters:
className- the class name- Returns:
- the new builder
-
forArray
public static SimValueBuilder forArray(IRType elementType)
Starts a builder for a one-dimensional array.- Parameters:
elementType- the element type- Returns:
- the new builder
-
withIntValue
public SimValueBuilder withIntValue(int value)
Sets the constant this value carries.- Parameters:
value- the int constant- Returns:
- this builder
-
withLongValue
public SimValueBuilder withLongValue(long value)
Sets the constant this value carries.- Parameters:
value- the long constant- Returns:
- this builder
-
withFloatValue
public SimValueBuilder withFloatValue(float value)
Sets the constant this value carries.- Parameters:
value- the float constant- Returns:
- this builder
-
withDoubleValue
public SimValueBuilder withDoubleValue(double value)
Sets the constant this value carries.- Parameters:
value- the double constant- Returns:
- this builder
-
withBooleanValue
public SimValueBuilder withBooleanValue(boolean value)
Sets the constant this value carries, stored as the int 0 or 1.- Parameters:
value- the boolean constant- Returns:
- this builder
-
withStringValue
public SimValueBuilder withStringValue(String value)
Sets the constant this value carries.- Parameters:
value- the string constant- Returns:
- this builder
-
withAllocationSite
public SimValueBuilder withAllocationSite(AllocationSite site)
Pins the value to an allocation site, which also makes it non-null.- Parameters:
site- the allocation site- Returns:
- this builder
-
withField
public SimValueBuilder withField(String fieldName, SimValue value)
Sets a field to an already built value.- Parameters:
fieldName- the field namevalue- the field value- Returns:
- this builder
-
withField
public SimValueBuilder withField(String fieldName, SimValueBuilder nested)
Sets a field to a nested builder, built against the same heap at build time.- Parameters:
fieldName- the field namenested- the builder for the field value- Returns:
- this builder
-
withField
public SimValueBuilder withField(String fieldName, int value)
Sets a field to an int constant.- Parameters:
fieldName- the field namevalue- the constant- Returns:
- this builder
-
withField
public SimValueBuilder withField(String fieldName, long value)
Sets a field to a long constant.- Parameters:
fieldName- the field namevalue- the constant- Returns:
- this builder
-
withField
public SimValueBuilder withField(String fieldName, boolean value)
Sets a field to a boolean constant.- Parameters:
fieldName- the field namevalue- the constant- Returns:
- this builder
-
withField
public SimValueBuilder withField(String fieldName, String value)
Sets a field to a java.lang.String constant.- Parameters:
fieldName- the field namevalue- the constant- Returns:
- this builder
-
asArray
public SimValueBuilder asArray(SimValue... elements)
Replaces the array contents and sets the length to match.- Parameters:
elements- the array elements in index order- Returns:
- this builder
-
withArrayLength
public SimValueBuilder withArrayLength(int length)
Sets the array length independently of the elements supplied.- Parameters:
length- the array length- Returns:
- this builder
-
withArrayElement
public SimValueBuilder withArrayElement(SimValue element)
Appends one element at the next index.- Parameters:
element- the element value- Returns:
- this builder
-
nullable
public SimValueBuilder nullable()
Marks the value as possibly null, the default state.- Returns:
- this builder
-
definitelyNull
public SimValueBuilder definitelyNull()
Marks the value as null, dropping any allocation site.- Returns:
- this builder
-
definitelyNotNull
public SimValueBuilder definitelyNotNull()
Marks the value as non-null.- Returns:
- this builder
-
getType
public IRType getType()
- Returns:
- the type
-
build
public SimValue build(SimHeap heap)
Materializes the value, allocating on the heap and recursively building nested field builders.- Parameters:
heap- the heap that receives allocations, field stores and array stores- Returns:
- the built value
-
-