1919import com .google .common .collect .ImmutableSet ;
2020import com .google .common .primitives .UnsignedLong ;
2121import com .google .errorprone .annotations .Immutable ;
22+ import com .google .errorprone .annotations .InlineMe ;
2223import com .google .protobuf .ByteString ;
2324import com .google .protobuf .Duration ;
24- import com .google .protobuf .NullValue ;
2525import com .google .protobuf .Timestamp ;
2626import dev .cel .common .annotations .Internal ;
27+ import dev .cel .common .values .CelByteString ;
28+ import dev .cel .common .values .NullValue ;
2729
2830/**
2931 * Represents a primitive literal.
@@ -42,7 +44,7 @@ public abstract class CelConstant {
4244 UnsignedLong .class ,
4345 Double .class ,
4446 String .class ,
45- ByteString .class );
47+ CelByteString .class );
4648
4749 /** Represents the type of the Constant */
4850 public enum Kind {
@@ -92,7 +94,7 @@ public abstract static class CelConstantNotSet {}
9294
9395 public abstract String stringValue ();
9496
95- public abstract ByteString bytesValue ();
97+ public abstract CelByteString bytesValue ();
9698
9799 /**
98100 * @deprecated Do not use. Timestamp is no longer built-in CEL type.
@@ -134,10 +136,46 @@ public static CelConstant ofValue(String value) {
134136 return AutoOneOf_CelConstant .stringValue (value );
135137 }
136138
137- public static CelConstant ofValue (ByteString value ) {
139+ public static CelConstant ofValue (CelByteString value ) {
138140 return AutoOneOf_CelConstant .bytesValue (value );
139141 }
140142
143+ /**
144+ * @deprecated Use native type equivalent {@link #ofValue(NullValue)} instead.
145+ */
146+ @ InlineMe (
147+ replacement = "CelConstant.ofValue(NullValue.NULL_VALUE)" ,
148+ imports = {"dev.cel.common.ast.CelConstant" , "dev.cel.common.values.NullValue" })
149+ @ Deprecated
150+ public static CelConstant ofValue (com .google .protobuf .NullValue unused ) {
151+ return ofValue (NullValue .NULL_VALUE );
152+ }
153+
154+ /**
155+ * @deprecated Use native type equivalent {@link #ofValue(CelByteString)} instead.
156+ */
157+ @ Deprecated
158+ public static CelConstant ofValue (ByteString value ) {
159+ CelByteString celByteString = CelByteString .of (value .toByteArray ());
160+ return ofValue (celByteString );
161+ }
162+
163+ /**
164+ * @deprecated Do not use. Duration is no longer built-in CEL type.
165+ */
166+ @ Deprecated
167+ public static CelConstant ofValue (Duration value ) {
168+ return AutoOneOf_CelConstant .durationValue (value );
169+ }
170+
171+ /**
172+ * @deprecated Do not use. Timestamp is no longer built-in CEL type.
173+ */
174+ @ Deprecated
175+ public static CelConstant ofValue (Timestamp value ) {
176+ return AutoOneOf_CelConstant .timestampValue (value );
177+ }
178+
141179 /** Checks whether the provided Java object is a valid CelConstant value. */
142180 public static boolean isConstantValue (Object value ) {
143181 return CONSTANT_CLASSES .contains (value .getClass ());
@@ -163,26 +201,10 @@ public static CelConstant ofObjectValue(Object value) {
163201 return ofValue ((double ) value );
164202 } else if (value instanceof String ) {
165203 return ofValue ((String ) value );
166- } else if (value instanceof ByteString ) {
167- return ofValue ((ByteString ) value );
204+ } else if (value instanceof CelByteString ) {
205+ return ofValue ((CelByteString ) value );
168206 }
169207
170208 throw new IllegalArgumentException ("Value is not a CelConstant: " + value );
171209 }
172-
173- /**
174- * @deprecated Do not use. Duration is no longer built-in CEL type.
175- */
176- @ Deprecated
177- public static CelConstant ofValue (Duration value ) {
178- return AutoOneOf_CelConstant .durationValue (value );
179- }
180-
181- /**
182- * @deprecated Do not use. Timestamp is no longer built-in CEL type.
183- */
184- @ Deprecated
185- public static CelConstant ofValue (Timestamp value ) {
186- return AutoOneOf_CelConstant .timestampValue (value );
187- }
188210}
0 commit comments