|
41 | 41 | @AutoValue |
42 | 42 | @Immutable |
43 | 43 | public abstract class CelOverloadDecl { |
44 | | - /** Required. Globally unique overload name. */ |
| 44 | + /** |
| 45 | + * Globally unique overload name. If empty when building {@link CelFunctionDecl}, an overload ID |
| 46 | + * is automatically generated from the function name and parameter types. |
| 47 | + */ |
45 | 48 | public abstract String overloadId(); |
46 | 49 |
|
47 | 50 | /** |
@@ -79,7 +82,7 @@ public abstract class CelOverloadDecl { |
79 | 82 |
|
80 | 83 | /** Create a new builder to construct a {@link CelOverloadDecl} instance */ |
81 | 84 | public static Builder newBuilder() { |
82 | | - return new AutoValue_CelOverloadDecl.Builder().setDoc(""); |
| 85 | + return new AutoValue_CelOverloadDecl.Builder().setOverloadId("").setDoc(""); |
83 | 86 | } |
84 | 87 |
|
85 | 88 | /** Builder for configuring the {@link CelOverloadDecl}. */ |
@@ -153,6 +156,44 @@ public CelOverloadDecl build() { |
153 | 156 | } |
154 | 157 | } |
155 | 158 |
|
| 159 | + /** |
| 160 | + * Helper method for declaring a member function overload (e.g. {@code x.f(y, ...)}) with an |
| 161 | + * automatically generated overload ID. |
| 162 | + * |
| 163 | + * <p>The returned declaration has an empty {@link #overloadId()}, which is automatically |
| 164 | + * populated with the canonical signature (e.g. {@code "target.func(arg1,arg2)"}) when built into |
| 165 | + * a {@link CelFunctionDecl} via {@link CelFunctionDecl.Builder#build()} or {@link |
| 166 | + * CelFunctionDecl#newFunctionDeclaration}. |
| 167 | + * |
| 168 | + * @param resultType the return type of the overload |
| 169 | + * @param paramTypes the parameter types of the overload, where the first element ({@code |
| 170 | + * paramTypes[0]}) is the receiver (target) type {@code x} and any subsequent elements are the |
| 171 | + * method argument types {@code y, ...} |
| 172 | + */ |
| 173 | + @CheckReturnValue |
| 174 | + public static CelOverloadDecl newMemberOverload(CelType resultType, CelType... paramTypes) { |
| 175 | + return newMemberOverload("", resultType, Arrays.asList(paramTypes)); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Helper method for declaring a member function overload (e.g. {@code x.f(y, ...)}) with an |
| 180 | + * automatically generated overload ID. |
| 181 | + * |
| 182 | + * <p>The returned declaration has an empty {@link #overloadId()}, which is automatically |
| 183 | + * populated with the canonical signature (e.g. {@code "target.func(arg1,arg2)"}) when built into |
| 184 | + * a {@link CelFunctionDecl} via {@link CelFunctionDecl.Builder#build()} or {@link |
| 185 | + * CelFunctionDecl#newFunctionDeclaration}. |
| 186 | + * |
| 187 | + * @param resultType the return type of the overload |
| 188 | + * @param paramTypes the parameter types of the overload, where the first element ({@code |
| 189 | + * paramTypes.get(0)}) is the receiver (target) type {@code x} and any subsequent elements are |
| 190 | + * the method argument types {@code y, ...} |
| 191 | + */ |
| 192 | + @CheckReturnValue |
| 193 | + public static CelOverloadDecl newMemberOverload(CelType resultType, List<CelType> paramTypes) { |
| 194 | + return newMemberOverload("", /* doc= */ "", resultType, paramTypes); |
| 195 | + } |
| 196 | + |
156 | 197 | /** Helper method for declaring a member function overload */ |
157 | 198 | @CheckReturnValue |
158 | 199 | public static CelOverloadDecl newMemberOverload( |
@@ -181,6 +222,40 @@ public static CelOverloadDecl newMemberOverload( |
181 | 222 | return newOverload(overloadId, doc, resultType, paramTypes, /* isInstanceFunction= */ true); |
182 | 223 | } |
183 | 224 |
|
| 225 | + /** |
| 226 | + * Helper method for declaring a global function overload (e.g. {@code f(x, ...)}) with an |
| 227 | + * automatically generated overload ID. |
| 228 | + * |
| 229 | + * <p>The returned declaration has an empty {@link #overloadId()}, which is automatically |
| 230 | + * populated with the canonical signature (e.g. {@code "func(arg1,arg2)"}) when built into a |
| 231 | + * {@link CelFunctionDecl} via {@link CelFunctionDecl.Builder#build()} or {@link |
| 232 | + * CelFunctionDecl#newFunctionDeclaration}. |
| 233 | + * |
| 234 | + * @param resultType the return type of the overload |
| 235 | + * @param paramTypes the argument types of the overload |
| 236 | + */ |
| 237 | + @CheckReturnValue |
| 238 | + public static CelOverloadDecl newGlobalOverload(CelType resultType, CelType... paramTypes) { |
| 239 | + return newGlobalOverload("", resultType, Arrays.asList(paramTypes)); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * Helper method for declaring a global function overload (e.g. {@code f(x, ...)}) with an |
| 244 | + * automatically generated overload ID. |
| 245 | + * |
| 246 | + * <p>The returned declaration has an empty {@link #overloadId()}, which is automatically |
| 247 | + * populated with the canonical signature (e.g. {@code "func(arg1,arg2)"}) when built into a |
| 248 | + * {@link CelFunctionDecl} via {@link CelFunctionDecl.Builder#build()} or {@link |
| 249 | + * CelFunctionDecl#newFunctionDeclaration}. |
| 250 | + * |
| 251 | + * @param resultType the return type of the overload |
| 252 | + * @param paramTypes the argument types of the overload |
| 253 | + */ |
| 254 | + @CheckReturnValue |
| 255 | + public static CelOverloadDecl newGlobalOverload(CelType resultType, List<CelType> paramTypes) { |
| 256 | + return newGlobalOverload("", /* doc= */ "", resultType, paramTypes); |
| 257 | + } |
| 258 | + |
184 | 259 | /** Helper method for declaring a global function overload */ |
185 | 260 | @CheckReturnValue |
186 | 261 | public static CelOverloadDecl newGlobalOverload( |
|
0 commit comments