Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 175 CompareTo Generation fails if fields include underscores #177

Merged
merged 1 commit into from
Jan 19, 2024
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
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 = " ";

Check notice on line 39 in pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/PbjCompilerTask.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/PbjCompilerTask.java#L39

'VARIABLE_DEF' should be separated from previous line.

/**
* Set the java main directory that we write generated code into
Expand Down Expand Up @@ -120,6 +122,13 @@
}
} 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