All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.cel.runtime.DefaultMetadata Maven / Gradle / Ivy

// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.runtime;

import dev.cel.expr.CheckedExpr;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.Immutable;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.annotations.Internal;

/**
 * Metadata implementation based on {@link CheckedExpr}.
 *
 * 

CEL Library Internals. Do Not Use. */ @Immutable @Internal public final class DefaultMetadata implements Metadata { private final CelAbstractSyntaxTree ast; public DefaultMetadata(CelAbstractSyntaxTree ast) { this.ast = Preconditions.checkNotNull(ast); } @Deprecated public DefaultMetadata(CheckedExpr checkedExpr) { this(CelProtoAbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst()); } @Override public String getLocation() { return ast.getSource().getDescription(); } @Override public int getPosition(long exprId) { ImmutableMap positions = ast.getSource().getPositionsMap(); return positions.containsKey(exprId) ? positions.get(exprId) : 0; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy