Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 720362613
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 28, 2025
1 parent 5f9fc54 commit ae2ba1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 67 deletions.
67 changes: 15 additions & 52 deletions java/core/src/main/java/com/google/protobuf/TextFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ private TextFormat() {}

private static final Logger logger = Logger.getLogger(TextFormat.class.getName());

private static final String DEBUG_STRING_SILENT_MARKER = " \t ";

private static final String REDACTED_MARKER = "[REDACTED]";

/**
Expand Down Expand Up @@ -147,7 +145,7 @@ public static final class Printer {
* DEBUG_MULTILINE.compareTo(PRINTER_PRINT_TO_STRING) > 0. The inverse is not necessarily true.
*/
static enum FieldReporterLevel {
NO_REPORT(0),
REPORT_ALL(0),
PRINT(1),
PRINTER_PRINT_TO_STRING(2),
TEXTFORMAT_PRINT_TO_STRING(3),
Expand All @@ -158,7 +156,8 @@ static enum FieldReporterLevel {
DEBUG_MULTILINE(8),
DEBUG_SINGLE_LINE(9),
ABSTRACT_TO_STRING(10),
ABSTRACT_MUTABLE_TO_STRING(11);
ABSTRACT_MUTABLE_TO_STRING(11),
REPORT_NONE(12);
private final int index;

FieldReporterLevel(int index) {
Expand All @@ -183,13 +182,13 @@ static enum FieldReporterLevel {

private final boolean singleLine;

// Any API level higher than this level will be reported. This is set to
// ABSTRACT_MUTABLE_TO_STRING by default to prevent reporting for now.
// Any API level equal to orhigher than this level will be reported. This is set to
// REPORT_NONE by default to prevent reporting for now.
private static final ThreadLocal<FieldReporterLevel> sensitiveFieldReportingLevel =
new ThreadLocal<FieldReporterLevel>() {
@Override
protected FieldReporterLevel initialValue() {
return FieldReporterLevel.ABSTRACT_MUTABLE_TO_STRING;
return FieldReporterLevel.REPORT_NONE;
}
};

Expand Down Expand Up @@ -884,7 +883,7 @@ public static String unsignedToString(final long value) {
}

private static TextGenerator setSingleLineOutput(Appendable output, boolean singleLine) {
return new TextGenerator(output, singleLine, Printer.FieldReporterLevel.NO_REPORT);
return new TextGenerator(output, singleLine, Printer.FieldReporterLevel.REPORT_NONE);
}

private static TextGenerator setSingleLineOutput(
Expand Down Expand Up @@ -997,15 +996,6 @@ private static final class Tokenizer {
private int previousLine = 0;
private int previousColumn = 0;

/**
* {@link containsSilentMarkerAfterCurrentToken} indicates if there is a silent marker after the
* current token. This value is moved to {@link containsSilentMarkerAfterPrevToken} every time
* the next token is parsed.
*/
private boolean containsSilentMarkerAfterCurrentToken = false;

private boolean containsSilentMarkerAfterPrevToken = false;

/** Construct a tokenizer that parses tokens from the given text. */
private Tokenizer(final CharSequence text) {
this.text = text;
Expand All @@ -1029,14 +1019,6 @@ int getColumn() {
return column;
}

boolean getContainsSilentMarkerAfterCurrentToken() {
return containsSilentMarkerAfterCurrentToken;
}

boolean getContainsSilentMarkerAfterPrevToken() {
return containsSilentMarkerAfterPrevToken;
}

/** Are we at the end of the input? */
boolean atEnd() {
return currentToken.length() == 0;
Expand Down Expand Up @@ -1725,19 +1707,6 @@ public static <T extends Message> T parse(
* control the parser behavior.
*/
public static class Parser {

/**
* A valid silent marker appears between a field name and its value. If there is a ":" in
* between, the silent marker will only appear after the colon. This is called after a field
* name is parsed, and before the ":" if it exists. If the current token is ":", then
* containsSilentMarkerAfterCurrentToken indicates if there is a valid silent marker. Otherwise,
* the current token is part of the field value, so the silent marker is indicated by
* containsSilentMarkerAfterPrevToken.
*/
private void detectSilentMarker(
Tokenizer tokenizer, Descriptor immediateMessageType, String fieldName) {
}

/**
* Determines if repeated values for non-repeated fields and oneofs are permitted. For example,
* given required/optional field "foo" and a oneof containing "baz" and "moo":
Expand Down Expand Up @@ -2110,14 +2079,12 @@ private void mergeField(

// Skips unknown fields.
if (field == null) {
detectSilentMarker(tokenizer, type, name);
guessFieldTypeAndSkip(tokenizer, type, recursionLimit);
return;
}

// Handle potential ':'.
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
detectSilentMarker(tokenizer, type, field.getFullName());
tokenizer.tryConsume(":"); // optional
if (parseTreeBuilder != null) {
TextFormatParseInfoTree.Builder childParseTreeBuilder =
Expand All @@ -2143,7 +2110,6 @@ private void mergeField(
recursionLimit);
}
} else {
detectSilentMarker(tokenizer, type, field.getFullName());
tokenizer.consume(":"); // required
consumeFieldValues(
tokenizer,
Expand All @@ -2167,27 +2133,26 @@ private void mergeField(
}
}

private String consumeFullTypeName(Tokenizer tokenizer) throws ParseException {
private void consumeFullTypeName(Tokenizer tokenizer) throws ParseException {
// If there is not a leading `[`, this is just a type name.
if (!tokenizer.tryConsume("[")) {
return tokenizer.consumeIdentifier();
tokenizer.consumeIdentifier();
return;
}

// Otherwise, this is an extension or google.protobuf.Any type URL: we consume proto path
// elements until we've addressed the type.
String name = tokenizer.consumeIdentifier();
tokenizer.consumeIdentifier();
while (tokenizer.tryConsume(".")) {
name += "." + tokenizer.consumeIdentifier();
tokenizer.consumeIdentifier();
}
if (tokenizer.tryConsume("/")) {
name += "/" + tokenizer.consumeIdentifier();
tokenizer.consumeIdentifier();
while (tokenizer.tryConsume(".")) {
name += "." + tokenizer.consumeIdentifier();
tokenizer.consumeIdentifier();
}
}
tokenizer.consume("]");

return name;
}

/**
Expand Down Expand Up @@ -2433,7 +2398,6 @@ private void mergeAnyFieldValue(
throw tokenizer.parseExceptionPreviousToken("Expected a valid type URL.");
}
}
detectSilentMarker(tokenizer, anyDescriptor, typeUrlBuilder.toString());
tokenizer.tryConsume(":");
final String anyEndToken;
if (tokenizer.tryConsume("<")) {
Expand Down Expand Up @@ -2478,8 +2442,7 @@ private void mergeAnyFieldValue(
/** Skips the next field including the field's name and value. */
private void skipField(Tokenizer tokenizer, Descriptor type, int recursionLimit)
throws ParseException {
String name = consumeFullTypeName(tokenizer);
detectSilentMarker(tokenizer, type, name);
consumeFullTypeName(tokenizer);
guessFieldTypeAndSkip(tokenizer, type, recursionLimit);

// For historical reasons, fields may optionally be separated by commas or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private UnredactedDebugFormatForTest() {}
/** Like {@code TextFormat.printer().printToString(message)}, but for test assertion purposes. */
public static String unredactedMultilineString(MessageOrBuilder message) {
return TextFormat.printer()
.printToString(message, TextFormat.Printer.FieldReporterLevel.NO_REPORT);
.printToString(message, TextFormat.Printer.FieldReporterLevel.REPORT_NONE);
}

/** Like {@code TextFormat.printer().printToString(fields)}, but for test assertion purposes. */
Expand All @@ -26,7 +26,7 @@ public static String unredactedMultilineString(UnknownFieldSet fields) {
public static String unredactedSingleLineString(MessageOrBuilder message) {
return TextFormat.printer()
.emittingSingleLine(true)
.printToString(message, TextFormat.Printer.FieldReporterLevel.NO_REPORT);
.printToString(message, TextFormat.Printer.FieldReporterLevel.REPORT_NONE);
}

/**
Expand Down

This file was deleted.

0 comments on commit ae2ba1c

Please sign in to comment.