Skip to content

Commit

Permalink
Violation: Rename getProto -> toProto
Browse files Browse the repository at this point in the history
  • Loading branch information
jchadwick-buf committed Dec 5, 2024
1 parent 456273e commit 9123d25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/main/java/build/buf/protovalidate/ValidationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ public String toString() {
builder.append("Validation error:");
for (Violation violation : violations) {
builder.append("\n - ");
if (!violation.getProto().getFieldPath().isEmpty()) {
builder.append(violation.getProto().getFieldPath());
if (!violation.toProto().getFieldPath().isEmpty()) {
builder.append(violation.toProto().getFieldPath());
builder.append(": ");
}
builder.append(
String.format(
"%s [%s]",
violation.getProto().getMessage(), violation.getProto().getConstraintId()));
"%s [%s]", violation.toProto().getMessage(), violation.toProto().getConstraintId()));
}
return builder.toString();
}
Expand All @@ -92,7 +91,7 @@ public String toString() {
public build.buf.validate.Violations toProto() {
List<build.buf.validate.Violation> protoViolations = new ArrayList<>();
for (Violation violation : violations) {
protoViolations.add(violation.getProto());
protoViolations.add(violation.toProto());
}
return Violations.newBuilder().addAllViolations(protoViolations).build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buf/protovalidate/Violation.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private Violation(
*
* @return The protobuf violation data.
*/
public build.buf.validate.Violation getProto() {
public build.buf.validate.Violation toProto() {
return proto;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ public static List<Violation> prependFieldPaths(
// special case that makes it significantly simpler to handle reverse-constructing paths with
// maps and repeated fields.
if (skipSubscript
&& violation.getProto().getField().getElementsCount() > 0
&& violation.getProto().getField().getElements(0).getSubscriptCase()
&& violation.toProto().getField().getElementsCount() > 0
&& violation.toProto().getField().getElements(0).getSubscriptCase()
!= FieldPathElement.SubscriptCase.SUBSCRIPT_NOT_SET) {
result.add(violation);
continue;
}
result.add(
violation.toBuilder()
.setProto(
violation.getProto().toBuilder()
violation.toProto().toBuilder()
.setField(
FieldPath.newBuilder()
.addElements(element)
.addAllElements(violation.getProto().getField().getElementsList())
.addAllElements(violation.toProto().getField().getElementsList())
.build())
.build())
.build());
Expand All @@ -76,11 +76,11 @@ public static List<Violation> prependRulePaths(
result.add(
violation.toBuilder()
.setProto(
violation.getProto().toBuilder()
violation.toProto().toBuilder()
.setRule(
FieldPath.newBuilder()
.addAllElements(elements)
.addAllElements(violation.getProto().getRule().getElementsList())
.addAllElements(violation.toProto().getRule().getElementsList())
.build())
.build())
.build());
Expand All @@ -97,12 +97,12 @@ public static List<Violation> prependRulePaths(
public static List<Violation> calculateFieldPathStrings(List<Violation> violations) {
List<Violation> result = new ArrayList<>();
for (Violation violation : violations) {
if (violation.getProto().getField().getElementsCount() > 0) {
if (violation.toProto().getField().getElementsCount() > 0) {
result.add(
violation.toBuilder()
.setProto(
violation.getProto().toBuilder()
.setFieldPath(fieldPathString(violation.getProto().getField()))
violation.toProto().toBuilder()
.setFieldPath(fieldPathString(violation.toProto().getField()))
.build())
.build());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private List<Violation> evalPairs(Value key, Value value, boolean failFast)
.map(
violation ->
violation.toBuilder()
.setProto(violation.getProto().toBuilder().setForKey(true).build())
.setProto(violation.toProto().toBuilder().setForKey(true).build())
.build())
.collect(Collectors.toList());
final List<Violation> valueViolations;
Expand Down

0 comments on commit 9123d25

Please sign in to comment.