Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
Signed-off-by: Ivan Malygin <[email protected]>
  • Loading branch information
imalygin and codacy-production[bot] committed Nov 13, 2023
1 parent 4edab7b commit a4a066d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ else if (f.nameCamelFirstLower() != null) {
""").replace("$fieldName", f.nameCamelFirstLower());
}
else {
throw new RuntimeException("Unexpected field type for getting HashCode - " + f.type().toString());
throw new IllegalArgumentException("Unexpected field type for getting HashCode - " + f.type().toString());

Check notice on line 439 in pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/impl/Common.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/impl/Common.java#L439

Line is longer than 120 characters (found 146).
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public static void generateEnumFile(Protobuf3Parser.EnumDefContext enumDef, File
try (FileWriter javaWriter = new FileWriter(getJavaFile(destinationSrcDir, modelPackage, enumName))) {
javaWriter.write(
"package "+modelPackage+";\n\n"+
createEnum(javaDocComment, deprecated, enumName, maxIndex, enumValues, false)
createEnum(javaDocComment, deprecated, enumName,
maxIndex, enumValues, false)
);
}
}
Expand Down Expand Up @@ -110,12 +111,14 @@ static String createEnum(String javaDocComment, String deprecated, String enumNa
final String deprecatedText = enumValue.deprecated ? "@Deprecated\n" : "";
enumValuesCode.add(
cleanedEnumComment
+ deprecatedText+ camelToUpperSnake(enumValue.name) +"("+i+", \""+enumValue.name+"\")");
+ deprecatedText+ camelToUpperSnake(enumValue.name) +
"("+i+", \""+enumValue.name+"\")");
}
}
return """
$javaDocComment
$deprecated$public enum $enumName implements com.hedera.pbj.runtime.EnumWithProtoMetadata {
$deprecated$public enum $enumName
implements com.hedera.pbj.runtime.EnumWithProtoMetadata {
$enumValues;
/** The field ordinal in protobuf for this type */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
package com.hedera.pbj.compiler.impl.generators;

import com.hedera.pbj.compiler.impl.*;
import static com.hedera.pbj.compiler.impl.Common.DEFAULT_INDENT;
import static com.hedera.pbj.compiler.impl.Common.camelToUpperSnake;
import static com.hedera.pbj.compiler.impl.Common.cleanDocStr;
import static com.hedera.pbj.compiler.impl.Common.getFieldsHashCode;
import static com.hedera.pbj.compiler.impl.Common.getJavaFile;
import static com.hedera.pbj.compiler.impl.Common.javaPrimitiveToObjectType;
import static com.hedera.pbj.compiler.impl.generators.EnumGenerator.EnumValue;
import static com.hedera.pbj.compiler.impl.generators.EnumGenerator.createEnum;

import com.hedera.pbj.compiler.impl.Common;
import com.hedera.pbj.compiler.impl.ContextualLookupHelper;
import com.hedera.pbj.compiler.impl.Field;
import com.hedera.pbj.compiler.impl.Field.FieldType;
import com.hedera.pbj.compiler.impl.FileType;
import com.hedera.pbj.compiler.impl.OneOfField;
import com.hedera.pbj.compiler.impl.SingleField;
import com.hedera.pbj.compiler.impl.grammar.Protobuf3Parser;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

import static com.hedera.pbj.compiler.impl.Common.*;
import static com.hedera.pbj.compiler.impl.generators.EnumGenerator.EnumValue;
import static com.hedera.pbj.compiler.impl.generators.EnumGenerator.createEnum;

/**
* Code generator that parses protobuf files and generates nice Java source for record files for each message type and
* enum.
Expand Down Expand Up @@ -349,7 +364,7 @@ public int hashCode() {
if (!hashCodeGenerated) {
// Generate a call to private method that iterates through fields
// and calculates the hashcode.
statements = Common.getFieldsHashCode(fields, statements);
statements = getFieldsHashCode(fields, statements);

bodyContent +=
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.hedera.pbj.intergration.jmh;

import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import com.hedera.pbj.intergration.test.TestHashFunctions;
import com.hedera.pbj.runtime.MalformedProtobufException;
import com.hedera.pbj.runtime.io.buffer.BufferedData;
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.hedera.pbj.runtime.io.stream.ReadableStreamingData;
import com.hedera.pbj.test.proto.pbj.Hasheval;

Check notice on line 3 in pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/EqualsHashCodeBench.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/EqualsHashCodeBench.java#L3

Unused import - com.hedera.pbj.test.proto.pbj.Hasheval.
import com.hedera.pbj.test.proto.pbj.Suit;

Check notice on line 4 in pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/EqualsHashCodeBench.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/EqualsHashCodeBench.java#L4

Unused import - com.hedera.pbj.test.proto.pbj.Suit.
import com.hedera.pbj.test.proto.pbj.TimestampTest;
import com.hedera.pbj.test.proto.pbj.tests.HashevalTest;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Scope;
// Add any other JMH annotation imports you use
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@SuppressWarnings("unused")
Expand All @@ -29,6 +28,8 @@
@BenchmarkMode(Mode.AverageTime)
public class EqualsHashCodeBench {
private TimestampTest testStamp;
private TimestampTest testStamp;

Check notice on line 31 in pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/EqualsHashCodeBench.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/EqualsHashCodeBench.java#L31

'VARIABLE_DEF' should be separated from previous line.

private TimestampTest testStamp1;

public EqualsHashCodeBench() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.hedera.pbj.intergration.jmh;

import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import com.hedera.pbj.intergration.test.TestHashFunctions;
import com.hedera.pbj.runtime.MalformedProtobufException;
import com.hedera.pbj.runtime.io.buffer.BufferedData;
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.hedera.pbj.runtime.io.stream.ReadableStreamingData;
import com.hedera.pbj.test.proto.pbj.Hasheval;
import com.hedera.pbj.test.proto.pbj.Suit;
import com.hedera.pbj.test.proto.pbj.TimestampTest;
import com.hedera.pbj.test.proto.pbj.tests.HashevalTest;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package com.hedera.pbj.intergration.test;

import com.google.protobuf.CodedOutputStream;
import com.hedera.hapi.node.base.Timestamp;
import com.hedera.pbj.runtime.io.buffer.BufferedData;

Check notice on line 3 in pbj-integration-tests/src/test/java/com/hedera/pbj/intergration/test/TestHashFunctions.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-integration-tests/src/test/java/com/hedera/pbj/intergration/test/TestHashFunctions.java#L3

Unused import - com.hedera.pbj.runtime.io.buffer.BufferedData.
import com.hedera.pbj.runtime.test.NoToStringWrapper;
import com.hedera.pbj.test.proto.pbj.Hasheval;
import com.hedera.pbj.test.proto.pbj.TimestampTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Check notice on line 7 in pbj-integration-tests/src/test/java/com/hedera/pbj/intergration/test/TestHashFunctions.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-integration-tests/src/test/java/com/hedera/pbj/intergration/test/TestHashFunctions.java#L7

Unused import - org.junit.jupiter.params.provider.MethodSource.
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static com.hedera.pbj.runtime.ProtoTestTools.INTEGER_TESTS_LIST;
import static com.hedera.pbj.runtime.ProtoTestTools.LONG_TESTS_LIST;
import static com.hedera.pbj.runtime.ProtoTestTools.getThreadLocalByteBuffer;
import static com.hedera.pbj.runtime.ProtoTestTools.getThreadLocalDataBuffer;
import static com.hedera.pbj.runtime.ProtoTestTools.getThreadLocalDataBuffer2;
import static org.junit.jupiter.api.Assertions.assertEquals;

Check notice on line 11 in pbj-integration-tests/src/test/java/com/hedera/pbj/intergration/test/TestHashFunctions.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pbj-integration-tests/src/test/java/com/hedera/pbj/intergration/test/TestHashFunctions.java#L11

Unused import - org.junit.jupiter.api.Assertions.assertEquals.

/**
Expand Down

0 comments on commit a4a066d

Please sign in to comment.