Skip to content

Commit

Permalink
fix: 175 CompareTo Generation fails if fields include underscores (#177)
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Sinclair <joseph.sinclair@swirldslabs.com>
  • Loading branch information
jsync-swirlds authored Jan 19, 2024
1 parent 377ec5c commit 31f701d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spotless {
toggleOffOn()
// don't need to set target, it is inferred from java
// apply a specific flavor of google-java-format
googleJavaFormat("1.15.0").aosp().reflowLongStrings()
googleJavaFormat("1.17.0").aosp().reflowLongStrings()
// make sure every file has the following copyright header.
// optionally, Spotless can set copyright years by digging
// through git history (see "license" section below).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

/** Gradle Task that generates java src code from protobuf proto schema files. */
public abstract class PbjCompilerTask extends SourceTask {
private static final int MAX_TRACE_FRAMES = 8;
private static final String STACK_ELEMENT_INDENT = " ";

/**
* Set the java main directory that we write generated code into
Expand Down Expand Up @@ -120,6 +122,13 @@ public static void compileFilesIn(Iterable<File> sourceFiles,
}
} catch (Exception e) {
System.err.println("Exception while processing file: " + protoFile);
// Print an abbreviated stack trace for help in debugging.
System.err.println(e);
var trace = e.getStackTrace();
int count = 0;
for (var element : trace) {
if (count++ < MAX_TRACE_FRAMES) System.err.println(STACK_ELEMENT_INDENT + element);
}
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private static String getFieldAnnotations(final Field field) {
private static List<Field> filterComparableFields(final MessageDefContext msgDef,
final ContextualLookupHelper lookupHelper,
final List<Field> fields) {
final Map<String, Field> fieldByName = fields.stream().collect(toMap(Field::nameCamelFirstLower, f -> f));
final Map<String, Field> fieldByName = fields.stream().collect(toMap(Field::name, f -> f));
final List<String> comparableFields = lookupHelper.getComparableFields(msgDef);
return comparableFields.stream().map(fieldByName::get).collect(Collectors.toList());
}
Expand Down
4 changes: 2 additions & 2 deletions pbj-integration-tests/src/main/proto/comparable.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ message ComparableSubObj {
int32 num = 1;
}

// <<<pbj.comparable = "int32Number, doubleNumber, booleanField, text, comparableEnum, subObject, bytes" >>>
// <<<pbj.comparable = "int32Number, doubleNumber, booleanField, text, comparableEnum, subObject, test_bytes" >>>
message ComparableTest {
int32 int32Number = 1;
double doubleNumber = 2;
bool booleanField = 3;
string text = 4;
ComparableEnum comparableEnum = 5;
ComparableSubObj subObject = 6;
bytes bytes = 7;
bytes test_bytes = 7;
}

// <<<pbj.comparable = "stringValue" >>>
Expand Down

0 comments on commit 31f701d

Please sign in to comment.