1515package dev .cel .common .ast ;
1616
1717import static com .google .common .base .Preconditions .checkArgument ;
18+ import static com .google .common .base .Preconditions .checkNotNull ;
1819
1920import dev .cel .common .ast .CelExpr .CelNotSet ;
2021import dev .cel .common .ast .CelExpr .ExprKind ;
@@ -34,6 +35,7 @@ public final class CelMutableExpr {
3435 private ExprKind .Kind exprKind ;
3536 private CelNotSet notSet ;
3637 private CelConstant constant ;
38+ private CelMutableIdent ident ;
3739 private int hash = 0 ;
3840
3941 public long id () {
@@ -58,17 +60,58 @@ public CelConstant constant() {
5860 return constant ;
5961 }
6062
63+ public CelMutableIdent ident () {
64+ checkExprKind (Kind .IDENT );
65+ return ident ;
66+ }
67+
6168 public void setConstant (CelConstant constant ) {
6269 this .exprKind = ExprKind .Kind .CONSTANT ;
63- this .constant = constant ;
70+ this .constant = checkNotNull ( constant ) ;
6471 }
6572
66- public static CelMutableExpr ofConstant (CelConstant constant ) {
67- return ofConstant (0L , constant );
73+ public void setIdent (CelMutableIdent ident ) {
74+ this .exprKind = ExprKind .Kind .IDENT ;
75+ this .ident = checkNotNull (ident );
6876 }
6977
70- public static CelMutableExpr ofConstant (long id , CelConstant constant ) {
71- return new CelMutableExpr (id , constant );
78+ /** A mutable identifier expression. */
79+ public static final class CelMutableIdent {
80+ private String name = "" ;
81+
82+ public String name () {
83+ return name ;
84+ }
85+
86+ public void setName (String name ) {
87+ this .name = checkNotNull (name );
88+ }
89+
90+ public static CelMutableIdent create (String name ) {
91+ return new CelMutableIdent (name );
92+ }
93+
94+ @ Override
95+ public boolean equals (Object obj ) {
96+ if (obj == this ) {
97+ return true ;
98+ }
99+ if (obj instanceof CelMutableIdent ) {
100+ CelMutableIdent that = (CelMutableIdent ) obj ;
101+ return this .name .equals (that .name );
102+ }
103+
104+ return false ;
105+ }
106+
107+ @ Override
108+ public int hashCode () {
109+ return name .hashCode ();
110+ }
111+
112+ private CelMutableIdent (String name ) {
113+ this .name = checkNotNull (name );
114+ }
72115 }
73116
74117 public static CelMutableExpr ofNotSet () {
@@ -79,11 +122,32 @@ public static CelMutableExpr ofNotSet(long id) {
79122 return new CelMutableExpr (id );
80123 }
81124
125+ public static CelMutableExpr ofConstant (CelConstant constant ) {
126+ return ofConstant (0L , constant );
127+ }
128+
129+ public static CelMutableExpr ofConstant (long id , CelConstant constant ) {
130+ return new CelMutableExpr (id , constant );
131+ }
132+
133+ public static CelMutableExpr ofIdent (String name ) {
134+ return ofIdent (0 , name );
135+ }
136+
137+ public static CelMutableExpr ofIdent (long id , String name ) {
138+ return new CelMutableExpr (id , CelMutableIdent .create (name ));
139+ }
140+
82141 private CelMutableExpr (long id , CelConstant mutableConstant ) {
83142 this .id = id ;
84143 setConstant (mutableConstant );
85144 }
86145
146+ private CelMutableExpr (long id , CelMutableIdent mutableIdent ) {
147+ this .id = id ;
148+ setIdent (mutableIdent );
149+ }
150+
87151 private CelMutableExpr (long id ) {
88152 this ();
89153 this .id = id ;
@@ -101,6 +165,7 @@ private Object exprValue() {
101165 case CONSTANT :
102166 return constant ();
103167 case IDENT :
168+ return ident ();
104169 case SELECT :
105170 case CALL :
106171 case CREATE_LIST :
0 commit comments