Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/AnyEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* com.google.protobuf.Any}'s within an expression, breaking evaluation if the type is unknown at
* runtime.
*/
class AnyEvaluator implements Evaluator {
final class AnyEvaluator implements Evaluator {
private final RuleViolationHelper helper;
private final Descriptors.FieldDescriptor typeURLDescriptor;
private final Set<String> in;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/build/buf/protovalidate/AstExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import dev.cel.compiler.CelCompiler;

/** {@link AstExpression} is a compiled CEL {@link CelAbstractSyntaxTree}. */
class AstExpression {
final class AstExpression {
/** The compiled CEL AST. */
public final CelAbstractSyntaxTree ast;
final CelAbstractSyntaxTree ast;

/** Contains the original expression from the proto file. */
public final Expression source;
final Expression source;

/** Constructs a new {@link AstExpression}. */
private AstExpression(CelAbstractSyntaxTree ast, Expression source) {
Expand All @@ -43,7 +43,7 @@ private AstExpression(CelAbstractSyntaxTree ast, Expression source) {
* @return The compiled {@link AstExpression}.
* @throws CompilationException if the expression compilation fails.
*/
public static AstExpression newAstExpression(CelCompiler cel, Expression expr)
static AstExpression newAstExpression(CelCompiler cel, Expression expr)
throws CompilationException {
CelValidationResult compileResult = cel.compile(expr.expression);
if (!compileResult.getAllIssues().isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/CelPrograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.jspecify.annotations.Nullable;

/** Evaluator that executes a {@link CompiledProgram}. */
class CelPrograms implements Evaluator {
final class CelPrograms implements Evaluator {
private final RuleViolationHelper helper;

/** A list of {@link CompiledProgram} that will be executed against the input message. */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/build/buf/protovalidate/CompiledProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* {@link CompiledProgram} is a parsed and type-checked {@link Program} along with the source {@link
* Expression}.
*/
class CompiledProgram {
final class CompiledProgram {
/** A compiled CEL program that can be evaluated against a set of variable bindings. */
private final Program program;

Expand All @@ -52,7 +52,7 @@ class CompiledProgram {
* @param rulePath The field path from the FieldRules to the rule value.
* @param ruleValue The rule value.
*/
public CompiledProgram(
CompiledProgram(
Program program,
Expression source,
@Nullable FieldPath rulePath,
Expand All @@ -74,7 +74,7 @@ public CompiledProgram(
* violations.
* @throws ExecutionException If the evaluation of the CEL program fails with an error.
*/
public RuleViolation.@Nullable Builder eval(Value fieldValue, CelVariableResolver variables)
RuleViolation.@Nullable Builder eval(Value fieldValue, CelVariableResolver variables)
throws ExecutionException {
Object value;
try {
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/build/buf/protovalidate/CustomOverload.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ static List<CelFunctionBinding> create() {
}

/**
* This implementes that standard {@code bytes_to_string} function. We override it because the CEL
* This implements that standard {@code bytes_to_string} function. We override it because the CEL
* library doesn't validate that the bytes are valid utf-8.
*
* <p>Workround until https://github.com/google/cel-java/pull/717 lands.
* <p>Workaround until <a href="https://github.com/google/cel-java/pull/717">cel-java issue
* 717</a> lands.
*/
private static CelFunctionBinding celBytesToString() {
return CelFunctionBinding.from(
Expand Down Expand Up @@ -202,9 +203,7 @@ private static CelFunctionBinding celContainsBytes() {
"contains_bytes",
ByteString.class,
ByteString.class,
(receiver, param) -> {
return bytesContains(receiver.toByteArray(), param.toByteArray());
});
(receiver, param) -> bytesContains(receiver.toByteArray(), param.toByteArray()));
}

static boolean bytesContains(byte[] arr, byte[] subArr) {
Expand Down Expand Up @@ -285,9 +284,7 @@ private static CelFunctionBinding celIsIpPrefixInt() {
"is_ip_prefix_int",
String.class,
Long.class,
(prefix, version) -> {
return isIpPrefix(prefix, version, false);
});
(prefix, version) -> isIpPrefix(prefix, version, false));
}

/**
Expand All @@ -300,9 +297,7 @@ private static CelFunctionBinding celIsIpPrefixBool() {
"is_ip_prefix_bool",
String.class,
Boolean.class,
(prefix, strict) -> {
return isIpPrefix(prefix, 0L, strict);
});
(prefix, strict) -> isIpPrefix(prefix, 0L, strict));
}

/**
Expand Down Expand Up @@ -390,9 +385,9 @@ private static CelFunctionBinding celIsHostAndPort() {
* <p>The host can be one of:
*
* <ul>
* <li>An IPv4 address in dotted decimal format, for example "192.168.0.1".
* <li>An IPv6 address enclosed in square brackets, for example "[::1]".
* <li>A hostname, for example "example.com".
* <li>An IPv4 address in dotted decimal format, for example {@code 192.168.0.1}.
* <li>An IPv6 address enclosed in square brackets, for example {@code [::1]}.
* <li>A hostname, for example {@code example.com}.
* </ul>
*
* <p>The port is separated by a colon. It must be non-empty, with a decimal number in the range
Expand Down Expand Up @@ -570,7 +565,8 @@ static boolean isIp(String addr, long ver) {
}

/**
* Returns true if the string is a URI, for example "https://example.com/foo/bar?baz=quux#frag".
* Returns true if the string is a URI, for example {@code
* https://example.com/foo/bar?baz=quux#frag}.
*
* <p>URI is defined in the internet standard RFC 3986. Zone Identifiers in IPv6 address literals
* are supported (RFC 6874).
Expand All @@ -580,8 +576,9 @@ private static boolean isUri(String str) {
}

/**
* Returns true if the string is a URI Reference - a URI such as
* "https://example.com/foo/bar?baz=quux#frag", or a Relative Reference such as "./foo/bar?query".
* Returns true if the string is a URI Reference - a URI such as {@code
* https://example.com/foo/bar?baz=quux#frag}, or a Relative Reference such as {@code
* ./foo/bar?query}.
*
* <p>URI, URI Reference, and Relative Reference are defined in the internet standard RFC 3986.
* Zone Identifiers in IPv6 address literals are supported (RFC 6874).
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/build/buf/protovalidate/DescriptorMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private DescriptorMappings() {}
* @return The rules field descriptor for the specified wrapper fully qualified name.
*/
@Nullable
public static FieldDescriptor expectedWrapperRules(String fqn) {
static FieldDescriptor expectedWrapperRules(String fqn) {
switch (fqn) {
case "google.protobuf.BoolValue":
return EXPECTED_STANDARD_RULES.get(FieldDescriptor.Type.BOOL);
Expand Down Expand Up @@ -136,7 +136,7 @@ public static FieldDescriptor expectedWrapperRules(String fqn) {
* @param kind The protobuf field type.
* @return The corresponding CEL type for the protobuf field.
*/
public static CelType protoKindToCELType(FieldDescriptor.Type kind) {
static CelType protoKindToCELType(FieldDescriptor.Type kind) {
switch (kind) {
case FLOAT:
case DOUBLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Collections;
import java.util.List;

class EmbeddedMessageEvaluator implements Evaluator {
final class EmbeddedMessageEvaluator implements Evaluator {
private final RuleViolationHelper helper;
private final MessageEvaluator messageEvaluator;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/EnumEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* {@link EnumEvaluator} checks an enum value being a member of the defined values exclusively. This
* check is handled outside CEL as enums are completely type erased to integers.
*/
class EnumEvaluator implements Evaluator {
final class EnumEvaluator implements Evaluator {
private final RuleViolationHelper helper;

/** Captures all the defined values for this enum */
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/build/buf/protovalidate/EvaluatorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.jspecify.annotations.Nullable;

/** A build-through cache of message evaluators keyed off the provided descriptor. */
class EvaluatorBuilder {
final class EvaluatorBuilder {
private static final FieldPathElement CEL_FIELD_PATH_ELEMENT =
FieldPathUtils.fieldPathElement(
FieldRules.getDescriptor().findFieldByNumber(FieldRules.CEL_FIELD_NUMBER));
Expand Down Expand Up @@ -150,8 +150,7 @@ private DescriptorCacheBuilder(
* @return Unmodifiable map of descriptors to evaluators.
* @throws CompilationException If an error occurs compiling a rule on the cache.
*/
public Map<Descriptor, MessageEvaluator> build(Descriptor descriptor)
throws CompilationException {
Map<Descriptor, MessageEvaluator> build(Descriptor descriptor) throws CompilationException {
createMessageEvaluator(descriptor);
return Collections.unmodifiableMap(cache);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/build/buf/protovalidate/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import java.util.List;

/** Expression represents a single CEL expression. */
class Expression {
final class Expression {
/** The id of the rule. */
public final String id;
final String id;

/** The message of the rule. */
public final String message;
final String message;

/** The expression of the rule. */
public final String expression;
final String expression;

/**
* Constructs a new Expression.
Expand Down Expand Up @@ -57,7 +57,7 @@ private Expression(Rule rule) {
* @param rules The list of rules.
* @return The list of expressions.
*/
public static List<Expression> fromRules(List<build.buf.validate.Rule> rules) {
static List<Expression> fromRules(List<build.buf.validate.Rule> rules) {
List<Expression> expressions = new ArrayList<>();
for (build.buf.validate.Rule rule : rules) {
expressions.add(new Expression(rule));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/build/buf/protovalidate/FieldEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.jspecify.annotations.Nullable;

/** Performs validation on a single message field, defined by its descriptor. */
class FieldEvaluator implements Evaluator {
final class FieldEvaluator implements Evaluator {
private static final FieldDescriptor REQUIRED_DESCRIPTOR =
FieldRules.getDescriptor().findFieldByNumber(FieldRules.REQUIRED_FIELD_NUMBER);

Expand All @@ -38,7 +38,7 @@ class FieldEvaluator implements Evaluator {
private final RuleViolationHelper helper;

/** The {@link ValueEvaluator} to apply to the field's value */
public final ValueEvaluator valueEvaluator;
final ValueEvaluator valueEvaluator;

/** The {@link FieldDescriptor} targeted by this evaluator */
private final FieldDescriptor descriptor;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/build/buf/protovalidate/FieldPathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static String fieldPathString(FieldPath fieldPath) {
* @param fieldDescriptor The field descriptor to generate a field path element for.
* @return The field path element that corresponds to the provided field descriptor.
*/
public static FieldPathElement fieldPathElement(Descriptors.FieldDescriptor fieldDescriptor) {
static FieldPathElement fieldPathElement(Descriptors.FieldDescriptor fieldDescriptor) {
String name;
if (fieldDescriptor.isExtension()) {
name = "[" + fieldDescriptor.getFullName() + "]";
Expand All @@ -100,7 +100,7 @@ public static FieldPathElement fieldPathElement(Descriptors.FieldDescriptor fiel
* @param rulePathElements Rule path elements to prepend.
* @return For convenience, the list of violations passed into the violations parameter.
*/
public static List<RuleViolation.Builder> updatePaths(
static List<RuleViolation.Builder> updatePaths(
List<RuleViolation.Builder> violations,
@Nullable FieldPathElement fieldPathElement,
List<FieldPathElement> rulePathElements) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static String formatExponential(Object val, int precision) throws CelEva
return str.get();
}
String pattern = "%." + precision + "e";
return String.format(pattern, (Double) val);
return String.format(pattern, val);
} else {
throw new CelEvaluationException(
"error during formatting: scientific clause can only be used on doubles, was given "
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/build/buf/protovalidate/Ipv4.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* prefix.
*/
final class Ipv4 {
private String str;
private final String str;
private int index;
private List<Short> octets;
private final List<Short> octets;
private int prefixLen;

Ipv4(String str) {
this.str = str;
this.octets = new ArrayList<Short>();
this.octets = new ArrayList<>();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/build/buf/protovalidate/Ipv6.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
* prefix.
*/
final class Ipv6 {
private String str;
private final String str;
private int index;
// 16-bit pieces found
private List<Integer> pieces;
private final List<Integer> pieces;
// number of 16-bit pieces found when double colon was found
private int doubleColonAt;
private boolean doubleColonSeen;
Expand All @@ -40,7 +40,7 @@ final class Ipv6 {

Ipv6(String str) {
this.str = str;
this.pieces = new ArrayList<Integer>();
this.pieces = new ArrayList<>();
this.doubleColonAt = -1;
this.dottedRaw = "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/ListEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Objects;

/** Performs validation on the elements of a repeated field. */
class ListEvaluator implements Evaluator {
final class ListEvaluator implements Evaluator {
/** Rule path to repeated rules */
private static final FieldPath REPEATED_ITEMS_RULE_PATH =
FieldPath.newBuilder()
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/build/buf/protovalidate/MapEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.stream.Collectors;

/** Performs validation on a map field's key-value pairs. */
class MapEvaluator implements Evaluator {
final class MapEvaluator implements Evaluator {
/** Rule path to map key rules */
private static final FieldPath MAP_KEYS_RULE_PATH =
FieldPath.newBuilder()
Expand Down Expand Up @@ -87,7 +87,7 @@ class MapEvaluator implements Evaluator {
*
* @return The key evaluator.
*/
public ValueEvaluator getKeyEvaluator() {
ValueEvaluator getKeyEvaluator() {
return keyEvaluator;
}

Expand All @@ -96,7 +96,7 @@ public ValueEvaluator getKeyEvaluator() {
*
* @return The value evaluator.
*/
public ValueEvaluator getValueEvaluator() {
ValueEvaluator getValueEvaluator() {
return valueEvaluator;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/build/buf/protovalidate/MessageEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.List;

/** Performs validation on a {@link com.google.protobuf.Message}. */
class MessageEvaluator implements Evaluator {
final class MessageEvaluator implements Evaluator {
/** List of {@link Evaluator}s that are applied to a message. */
private final List<Evaluator> evaluators = new ArrayList<>();

Expand Down Expand Up @@ -55,7 +55,7 @@ public List<RuleViolation.Builder> evaluate(Value val, boolean failFast)
*
* @param eval The evaluator to append.
*/
public void append(Evaluator eval) {
void append(Evaluator eval) {
evaluators.add(eval);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
* A specialized {@link Evaluator} for applying {@code buf.validate.MessageOneofRule} to a {@link
* com.google.protobuf.Message}.
*/
class MessageOneofEvaluator implements Evaluator {
final class MessageOneofEvaluator implements Evaluator {
/** List of fields that are part of the oneof */
public final List<FieldDescriptor> fields;
final List<FieldDescriptor> fields;

/** If at least one must be set. */
public final boolean required;
final boolean required;

MessageOneofEvaluator(List<FieldDescriptor> fields, boolean required) {
this.fields = fields;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/MessageValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class MessageValue implements Value {
*
* @param value The message value.
*/
public MessageValue(Message value) {
MessageValue(Message value) {
this.value = value;
}

Expand Down
Loading