1 package shark 2 3 import shark.HeapObject.HeapClass 4 import shark.HeapObject.HeapInstance 5 import shark.HeapObject.HeapObjectArray 6 import shark.HeapObject.HeapPrimitiveArray 7 8 /** 9 * Represents a static field or an instance field. 10 */ 11 class HeapField( 12 /** 13 * The class this field was declared in. 14 */ 15 val declaringClass: HeapClass, 16 /** 17 * Name of the field 18 */ 19 val name: String, 20 /** 21 * Value of the field. Also see shorthands [valueAsClass], [valueAsInstance], 22 * [valueAsObjectArray], [valueAsPrimitiveArray]. 23 */ 24 val value: HeapValue 25 ) { 26 27 /** 28 * Return a [HeapClass] is [value] references a class, and null otherwise. 29 */ 30 val valueAsClass: HeapClass? 31 get() = value.asObject?.asClass 32 33 /** 34 * Return a [HeapInstance] is [value] references an instance, and null otherwise. 35 */ 36 val valueAsInstance: HeapInstance? 37 get() = value.asObject?.asInstance 38 39 /** 40 * Return a [HeapObjectArray] is [value] references an object array, and null otherwise. 41 */ 42 val valueAsObjectArray: HeapObjectArray? 43 get() = value.asObject?.asObjectArray 44 45 /** 46 * Return a [HeapPrimitiveArray] is [value] references a primitive array, and null 47 * otherwise. 48 */ 49 val valueAsPrimitiveArray: HeapPrimitiveArray? 50 get() = value.asObject?.asPrimitiveArray 51 }