Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Malygin <[email protected]>
  • Loading branch information
imalygin committed Jan 12, 2024
1 parent 21afb50 commit 95b6379
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public static String getFieldsCompareToStatements(final List<Field> fields, Stri
} else if (f.type() == Field.FieldType.MESSAGE || f.type() == Field.FieldType.ONE_OF) {
verifyComparable(f, destinationSrcDir);
generatedCodeSoFar += generateCompareToForObject(f);
}else {
} else {
throw new IllegalArgumentException("Unexpected field type for getting CompareTo - " + f.type().toString());
}
}
Expand Down Expand Up @@ -677,31 +677,16 @@ private static String getPrimitiveWrapperCompareToGeneration(Field f) {
""";


final String compareStatement;
switch (f.messageType()) {
case "StringValue" ->
compareStatement =
"$fieldName.compareTo(thatObj.$fieldName)";
case "BoolValue" ->
compareStatement =
"java.lang.Boolean.compare($fieldName, thatObj.$fieldName)";
case "Int32Value", "UInt32Value" ->
compareStatement =
"java.lang.Integer.compare($fieldName, thatObj.$fieldName)";
case "Int64Value", "UInt64Value" ->
compareStatement =
"java.lang.Long.compare($fieldName, thatObj.$fieldName)";
case "FloatValue" ->
compareStatement =
"java.lang.Float.compare($fieldName, thatObj.$fieldName)";
case "DoubleValue" ->
compareStatement =
"java.lang.Double.compare($fieldName, thatObj.$fieldName)";
case "BytesValue" ->
compareStatement =
"(int)($fieldName.length() - thatObj.$fieldName.length())";
final String compareStatement = switch (f.messageType()) {
case "StringValue" -> "$fieldName.compareTo(thatObj.$fieldName)";
case "BoolValue" -> "java.lang.Boolean.compare($fieldName, thatObj.$fieldName)";
case "Int32Value", "UInt32Value" -> "java.lang.Integer.compare($fieldName, thatObj.$fieldName)";
case "Int64Value", "UInt64Value" -> "java.lang.Long.compare($fieldName, thatObj.$fieldName)";
case "FloatValue" -> "java.lang.Float.compare($fieldName, thatObj.$fieldName)";
case "DoubleValue" -> "java.lang.Double.compare($fieldName, thatObj.$fieldName)";
case "BytesValue" -> "(int)($fieldName.length() - thatObj.$fieldName.length())";
default -> throw new UnsupportedOperationException("Unhandled optional message type:" + f.messageType());
}
};

return template
.replace("$compareStatement", compareStatement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,32 @@

import com.hedera.pbj.compiler.impl.grammar.Protobuf3Lexer;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser.*;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser.EnumDefContext;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser.MessageDefContext;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser.MessageElementContext;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser.MessageTypeContext;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser.TopLevelDefContext;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import edu.umd.cs.findbugs.annotations.Nullable;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;

/**
* Class that manages packages and enum names that are used more than one place in code generation
*/
Expand Down

0 comments on commit 95b6379

Please sign in to comment.