44 * 45 * @param object the object value to box 46 * @return a constant containing {@code object} 47 */ 48 JavaConstant forObject(Object object); 49 50 /** 51 * Gets the object reference a given constant represents if it is of a given type. The constant 52 * must have kind {@link JavaKind#Object}. 53 * 54 * @param type the expected type of the object represented by {@code constant}. If the object is 55 * required to be of this type, then wrap the call to this method in 56 * {@link Objects#requireNonNull(Object)}. 57 * @param constant an object constant 58 * @return the object value represented by {@code constant} cast to {@code type} if it is an 59 * {@link Class#isInstance(Object) instance of} {@code type} otherwise {@code null} 60 */ 61 <T> T asObject(Class<T> type, JavaConstant constant); 62 63 /** 64 * Gets the object reference a given constant represents if it is of a given type. The constant 65 * must have kind {@link JavaKind#Object}. 66 * 67 * @param type the expected type of the object represented by {@code constant}. If the object is 68 * required to be of this type, then wrap the call to this method in 69 * {@link Objects#requireNonNull(Object)}. 70 * @param constant an object constant 71 * @return the object value represented by {@code constant} if it is an 72 * {@link ResolvedJavaType#isInstance(JavaConstant) instance of} {@code type} otherwise 73 * {@code null} 74 */ 75 Object asObject(ResolvedJavaType type, JavaConstant constant); 76 77 /** 78 * Creates a boxed constant for the given kind from an Object. The object needs to be of the 79 * Java boxed type corresponding to the kind. 80 * 81 * @param kind the kind of the constant to create 82 * @param value the Java boxed value: a {@link Byte} instance for {@link JavaKind#Byte}, etc. 83 * @return the boxed copy of {@code value} 84 */ 85 JavaConstant forBoxed(JavaKind kind, Object value); 86 87 /** 88 * Gets the value to bind to an injected parameter in a node intrinsic. 89 * 90 * @param type the type of a parameter in a node intrinsic constructor 91 * @return the value that should be bound to the parameter when invoking the constructor or null 92 * if this provider cannot provide a value of the requested type 93 */ 94 <T> T getInjectedNodeIntrinsicParameter(Class<T> type); 95 96 /** 97 * Get the original Java class corresponding to a {@link ResolvedJavaType}. 98 * 99 * @param type the type for which the original Java class is requested 100 * @return the original Java class corresponding to the {@code type} parameter 101 */ 102 Class<?> originalClass(ResolvedJavaType type); 103 } | 44 * 45 * @param object the object value to box 46 * @return a constant containing {@code object} 47 */ 48 JavaConstant forObject(Object object); 49 50 /** 51 * Gets the object reference a given constant represents if it is of a given type. The constant 52 * must have kind {@link JavaKind#Object}. 53 * 54 * @param type the expected type of the object represented by {@code constant}. If the object is 55 * required to be of this type, then wrap the call to this method in 56 * {@link Objects#requireNonNull(Object)}. 57 * @param constant an object constant 58 * @return the object value represented by {@code constant} cast to {@code type} if it is an 59 * {@link Class#isInstance(Object) instance of} {@code type} otherwise {@code null} 60 */ 61 <T> T asObject(Class<T> type, JavaConstant constant); 62 63 /** 64 * Creates a boxed constant for the given kind from an Object. The object needs to be of the 65 * Java boxed type corresponding to the kind. 66 * 67 * @param kind the kind of the constant to create 68 * @param value the Java boxed value: a {@link Byte} instance for {@link JavaKind#Byte}, etc. 69 * @return the boxed copy of {@code value} 70 */ 71 default JavaConstant forBoxed(JavaKind kind, Object value) { 72 if (kind == JavaKind.Object) { 73 return forObject(value); 74 } else { 75 return JavaConstant.forBoxedPrimitive(value); 76 } 77 } 78 79 /** 80 * Gets the value to bind to an injected parameter in a node intrinsic. 81 * 82 * @param type the type of a parameter in a node intrinsic constructor 83 * @return the value that should be bound to the parameter when invoking the constructor or null 84 * if this provider cannot provide a value of the requested type 85 */ 86 <T> T getInjectedNodeIntrinsicParameter(Class<T> type); 87 88 /** 89 * Get the original Java class corresponding to a {@link ResolvedJavaType}. 90 * 91 * @param type the type for which the original Java class is requested 92 * @return the original Java class corresponding to {@code type} or {@code null} if this object 93 * cannot map {@link ResolvedJavaType} instances to {@link Class} instances 94 */ 95 Class<?> originalClass(ResolvedJavaType type); 96 } |