Skip to content

Commit

Permalink
fix: ApiVersion.toString uses the input format
Browse files Browse the repository at this point in the history
  • Loading branch information
burkedavison committed Sep 26, 2023
1 parent f8ff141 commit ac3dd3d
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.google.docfx.doclet;

import com.google.common.base.MoreObjects;
import java.util.Collection;
import java.util.Comparator;
import java.util.Objects;
Expand All @@ -10,7 +9,7 @@
import javax.annotation.Nullable;

public class ApiVersion implements Comparable<ApiVersion> {
public static ApiVersion NONE = new ApiVersion(0, 0, null, 0);
public static ApiVersion NONE = new ApiVersion("", 0, 0, null, 0);

private static final Pattern VALID_VERSION_REGEX =
Pattern.compile("^v(\\d+)p?(\\d+)?(alpha|beta)?(\\d+)?");
Expand Down Expand Up @@ -38,6 +37,7 @@ public static Optional<ApiVersion> parse(@Nullable String input) {
if (matcher.matches()) {
return Optional.of(
new ApiVersion(
input,
safeParseInt(matcher.group(1)),
safeParseInt(matcher.group(2)),
matcher.group(3),
Expand Down Expand Up @@ -69,12 +69,14 @@ public static ApiVersion getRecommended(Collection<ApiVersion> versions) {
.orElseThrow(() -> new IllegalArgumentException("Versions must not be empty.")));
}

private final String original;
private final int major;
private final int minor;
private final String stability;
private final int prerelease;

private ApiVersion(int major, int minor, String stability, int prerelease) {
private ApiVersion(String original, int major, int minor, String stability, int prerelease) {
this.original = original;
this.major = major;
this.minor = minor;
this.stability = stability;
Expand Down Expand Up @@ -127,11 +129,6 @@ public int hashCode() {

@Override
public String toString() {
return MoreObjects.toStringHelper(ApiVersion.class)
.add("major", major)
.add("minor", minor)
.add("stability", stability)
.add("prerelease", prerelease)
.toString();
return original;
}
}

0 comments on commit ac3dd3d

Please sign in to comment.