Skip to content

Commit

Permalink
Remove references to deprecated type resolvers in the runtime.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 704765516
  • Loading branch information
l46kok authored and copybara-github committed Dec 10, 2024
1 parent a30184b commit ab239c4
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 380 deletions.
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ java_library(
"//common:proto_json_adapter",
"//common:runtime_exception",
"//common/annotations",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
Expand Down
10 changes: 0 additions & 10 deletions runtime/src/main/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ BASE_SOURCES = [
"Registrar.java",
"ResolvedOverload.java",
"StandardFunctions.java",
"StandardTypeResolver.java",
"TypeResolver.java",
]

# keep sorted
Expand Down Expand Up @@ -70,8 +68,6 @@ java_library(
"//common/internal:default_message_factory",
"//common/internal:dynamic_proto",
"//common/internal:safe_string_formatter",
"//common/types",
"//common/types:type_providers",
"//runtime:runtime_helper",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_code_findbugs_annotations",
Expand Down Expand Up @@ -111,7 +107,6 @@ java_library(
"//common/types",
"//common/types:cel_types",
"//common/types:type_providers",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
Expand Down Expand Up @@ -253,17 +248,13 @@ java_library(
"//common/annotations",
"//common/internal:cel_descriptor_pools",
"//common/internal:dynamic_proto",
"//common/types",
"//common/types:type_providers",
"//common/values",
"//common/values:cel_value",
"//common/values:cel_value_provider",
"//common/values:proto_message_value",
"//runtime:interpreter",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:org_jspecify_jspecify",
],
)

Expand All @@ -276,7 +267,6 @@ java_library(
":base",
":unknown_attributes",
"//common/annotations",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:org_jspecify_jspecify",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package dev.cel.runtime;

import dev.cel.expr.Type;
import dev.cel.expr.Value;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.Immutable;
import com.google.protobuf.Descriptors.Descriptor;
Expand All @@ -31,7 +29,6 @@
import dev.cel.common.internal.DynamicProto;
import dev.cel.common.internal.ProtoAdapter;
import dev.cel.common.internal.ProtoMessageFactory;
import dev.cel.common.types.CelType;
import dev.cel.common.types.CelTypes;
import java.util.Map;
import java.util.Optional;
Expand All @@ -50,7 +47,6 @@
@Internal
public final class DescriptorMessageProvider implements RuntimeTypeProvider {
private final ProtoMessageFactory protoMessageFactory;
private final TypeResolver typeResolver;

@SuppressWarnings("Immutable")
private final ProtoAdapter protoAdapter;
Expand Down Expand Up @@ -82,33 +78,12 @@ public DescriptorMessageProvider(
* when adapting from proto to CEL and vice versa.
*/
public DescriptorMessageProvider(ProtoMessageFactory protoMessageFactory, CelOptions celOptions) {
this.typeResolver = StandardTypeResolver.getInstance(celOptions);
this.protoMessageFactory = protoMessageFactory;
this.protoAdapter =
new ProtoAdapter(
DynamicProto.create(protoMessageFactory), celOptions.enableUnsignedLongs());
}

@Override
@Nullable
public Value resolveObjectType(Object obj, @Nullable Value checkedTypeValue) {
return typeResolver.resolveObjectType(obj, checkedTypeValue);
}

/** {@inheritDoc} */
@Override
public Value adaptType(CelType type) {
return typeResolver.adaptType(type);
}

@Nullable
@Override
@Deprecated
/** {@inheritDoc} */
public Value adaptType(@Nullable Type type) {
return typeResolver.adaptType(type);
}

@Nullable
@Override
public Object createMessage(String messageName, Map<String, Object> values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
*/
@Immutable
@Internal
public interface RuntimeTypeProvider extends MessageProvider, TypeResolver {}
public interface RuntimeTypeProvider extends MessageProvider {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,21 @@

package dev.cel.runtime;

import dev.cel.expr.Type;
import dev.cel.expr.Value;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.Immutable;
import dev.cel.common.CelErrorCode;
import dev.cel.common.CelOptions;
import dev.cel.common.CelRuntimeException;
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.CelDescriptorPool;
import dev.cel.common.internal.DynamicProto;
import dev.cel.common.types.CelType;
import dev.cel.common.types.TypeType;
import dev.cel.common.values.CelValue;
import dev.cel.common.values.CelValueProvider;
import dev.cel.common.values.ProtoCelValueConverter;
import dev.cel.common.values.SelectableValue;
import dev.cel.common.values.StringValue;
import java.util.Map;
import java.util.NoSuchElementException;
import org.jspecify.annotations.Nullable;

/** Bridge between the old RuntimeTypeProvider and CelValueProvider APIs. */
@Internal
Expand All @@ -43,7 +37,6 @@ public final class RuntimeTypeProviderLegacyImpl implements RuntimeTypeProvider

private final CelValueProvider valueProvider;
private final ProtoCelValueConverter protoCelValueConverter;
private final TypeResolver standardTypeResolver;

@VisibleForTesting
public RuntimeTypeProviderLegacyImpl(
Expand All @@ -54,7 +47,6 @@ public RuntimeTypeProviderLegacyImpl(
this.valueProvider = valueProvider;
this.protoCelValueConverter =
ProtoCelValueConverter.newInstance(celOptions, celDescriptorPool, dynamicProto);
this.standardTypeResolver = StandardTypeResolver.getInstance(celOptions);
}

@Override
Expand Down Expand Up @@ -115,28 +107,6 @@ public Object adapt(Object message) {
return unwrapCelValue(protoCelValueConverter.fromJavaObjectToCelValue(message));
}

@Override
public Value resolveObjectType(Object obj, Value checkedTypeValue) {
// Presently, Java only supports evaluation of checked-only expressions.
Preconditions.checkNotNull(checkedTypeValue);
return standardTypeResolver.resolveObjectType(obj, checkedTypeValue);
}

@Override
public Value adaptType(CelType type) {
Preconditions.checkNotNull(type);
if (type instanceof TypeType) {
return createTypeValue(((TypeType) type).containingTypeName());
}

return createTypeValue(type.name());
}

@Override
public @Nullable Value adaptType(@Nullable Type type) {
throw new UnsupportedOperationException("This should only be called with native CelType.");
}

/**
* DefaultInterpreter cannot handle CelValue and instead expects plain Java objects.
*
Expand All @@ -145,8 +115,4 @@ public Value adaptType(CelType type) {
private Object unwrapCelValue(CelValue object) {
return protoCelValueConverter.fromCelValueToJavaObject(object);
}

private static Value createTypeValue(String name) {
return Value.newBuilder().setTypeValue(name).build();
}
}
Loading

0 comments on commit ab239c4

Please sign in to comment.