Skip to content

Commit

Permalink
Avoid cyclic dependency between classes.
Browse files Browse the repository at this point in the history
Move defaults out of property evaluation and into context.
  • Loading branch information
ZachBray committed Dec 6, 2023
1 parent 26f79f2 commit 8796e9e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package uk.co.real_logic.sbe.generation;

import uk.co.real_logic.sbe.generation.common.PrecedenceChecks;
import uk.co.real_logic.sbe.generation.java.JavaOutputManager;
import uk.co.real_logic.sbe.generation.c.CGenerator;
import uk.co.real_logic.sbe.generation.c.COutputManager;
import uk.co.real_logic.sbe.generation.common.PrecedenceChecks;
import uk.co.real_logic.sbe.generation.cpp.CppGenerator;
import uk.co.real_logic.sbe.generation.cpp.NamespaceOutputManager;
import uk.co.real_logic.sbe.generation.golang.GolangGenerator;
import uk.co.real_logic.sbe.generation.golang.GolangOutputManager;
import uk.co.real_logic.sbe.generation.java.JavaGenerator;
import uk.co.real_logic.sbe.generation.java.JavaOutputManager;
import uk.co.real_logic.sbe.generation.rust.RustGenerator;
import uk.co.real_logic.sbe.generation.rust.RustOutputManager;
import uk.co.real_logic.sbe.ir.Ir;
Expand Down Expand Up @@ -122,25 +122,31 @@ public CodeGenerator newInstance(final Ir ir, final String outputDir)
};

/**
* Returns the configured precedence checks.
* Returns the precedence checks to run, configured from system properties.
*
* @return the configured precedence checks.
* @return the precedence checks to run, configured from system properties.
*/
public static PrecedenceChecks precedenceChecks()
{
final boolean shouldGeneratePrecedenceChecks =
Boolean.parseBoolean(System.getProperty(GENERATE_PRECEDENCE_CHECKS, "false"));
final PrecedenceChecks.Context context = new PrecedenceChecks.Context();

final String precedenceChecksFlagName =
System.getProperty(PRECEDENCE_CHECKS_FLAG_NAME, "SBE_ENABLE_PRECEDENCE_CHECKS");
final String shouldGeneratePrecedenceChecks = System.getProperty(GENERATE_PRECEDENCE_CHECKS);
if (shouldGeneratePrecedenceChecks != null)
{
context.shouldGeneratePrecedenceChecks(Boolean.parseBoolean(shouldGeneratePrecedenceChecks));
}

final String precedenceChecksPropName =
System.getProperty(JAVA_PRECEDENCE_CHECKS_PROPERTY_NAME, "sbe.enable.precedence.checks");
final String precedenceChecksFlagName = System.getProperty(PRECEDENCE_CHECKS_FLAG_NAME);
if (precedenceChecksFlagName != null)
{
context.precedenceChecksFlagName(precedenceChecksFlagName);
}

final PrecedenceChecks.Context context = new PrecedenceChecks.Context()
.shouldGeneratePrecedenceChecks(shouldGeneratePrecedenceChecks)
.precedenceChecksFlagName(precedenceChecksFlagName)
.precedenceChecksPropName(precedenceChecksPropName);
final String precedenceChecksPropName = System.getProperty(JAVA_PRECEDENCE_CHECKS_PROPERTY_NAME);
if (precedenceChecksPropName != null)
{
context.precedenceChecksPropName(precedenceChecksPropName);
}

return PrecedenceChecks.newInstance(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private FieldPrecedenceModel createModel(
public static final class Context
{
private boolean shouldGeneratePrecedenceChecks;
private String precedenceChecksFlagName;
private String precedenceChecksPropName;
private String precedenceChecksFlagName = "SBE_ENABLE_PRECEDENCE_CHECKS";
private String precedenceChecksPropName = "sbe.enable.precedence.checks";

/**
* Returns {@code true} if precedence checks should be generated; {@code false} otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import uk.co.real_logic.sbe.PrimitiveType;
import uk.co.real_logic.sbe.generation.CodeGenerator;
import uk.co.real_logic.sbe.generation.Generators;
import uk.co.real_logic.sbe.generation.TargetCodeGeneratorLoader;
import uk.co.real_logic.sbe.generation.common.FieldPrecedenceModel;
import uk.co.real_logic.sbe.generation.common.PrecedenceChecks;
import uk.co.real_logic.sbe.ir.Encoding;
Expand Down Expand Up @@ -72,7 +71,7 @@ public CppGenerator(final Ir ir, final boolean shouldDecodeUnknownEnumValues, fi
this(
ir,
shouldDecodeUnknownEnumValues,
TargetCodeGeneratorLoader.precedenceChecks(),
PrecedenceChecks.newInstance(new PrecedenceChecks.Context()),
outputManager
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import uk.co.real_logic.sbe.PrimitiveValue;
import uk.co.real_logic.sbe.generation.CodeGenerator;
import uk.co.real_logic.sbe.generation.Generators;
import uk.co.real_logic.sbe.generation.TargetCodeGeneratorLoader;
import uk.co.real_logic.sbe.generation.common.FieldPrecedenceModel;
import uk.co.real_logic.sbe.generation.common.PrecedenceChecks;
import uk.co.real_logic.sbe.ir.Encoding;
Expand Down Expand Up @@ -72,7 +71,7 @@ public CSharpGenerator(final Ir ir, final OutputManager outputManager)
{
this(
ir,
TargetCodeGeneratorLoader.precedenceChecks(),
PrecedenceChecks.newInstance(new PrecedenceChecks.Context()),
outputManager
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import uk.co.real_logic.sbe.PrimitiveType;
import uk.co.real_logic.sbe.generation.CodeGenerator;
import uk.co.real_logic.sbe.generation.Generators;
import uk.co.real_logic.sbe.generation.TargetCodeGeneratorLoader;
import uk.co.real_logic.sbe.generation.common.FieldPrecedenceModel;
import uk.co.real_logic.sbe.generation.common.PrecedenceChecks;
import uk.co.real_logic.sbe.ir.*;
Expand Down Expand Up @@ -131,7 +130,7 @@ public JavaGenerator(
shouldGenerateInterfaces,
shouldDecodeUnknownEnumValues,
shouldSupportTypesPackageNames,
TargetCodeGeneratorLoader.precedenceChecks(),
PrecedenceChecks.newInstance(new PrecedenceChecks.Context()),
outputManager
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@ void shouldGenerateBasicMessage() throws Exception
@Test
void shouldGenerateWithoutPrecedenceChecksByDefault() throws Exception
{
final PrecedenceChecks.Context context = new PrecedenceChecks.Context()
.shouldGeneratePrecedenceChecks(false)
.precedenceChecksPropName("sbe.enable.precedence.checks")
.precedenceChecksFlagName("SBE_ENABLE_PRECEDENCE_CHECKS");
final PrecedenceChecks.Context context = new PrecedenceChecks.Context();
final PrecedenceChecks precedenceChecks = PrecedenceChecks.newInstance(context);
generator(precedenceChecks).generate();

Expand All @@ -279,9 +276,7 @@ void shouldGenerateWithoutPrecedenceChecksByDefault() throws Exception
void shouldGeneratePrecedenceChecksWhenEnabled() throws Exception
{
final PrecedenceChecks.Context context = new PrecedenceChecks.Context()
.shouldGeneratePrecedenceChecks(true)
.precedenceChecksPropName("sbe.enable.precedence.checks")
.precedenceChecksFlagName("SBE_ENABLE_PRECEDENCE_CHECKS");
.shouldGeneratePrecedenceChecks(true);
final PrecedenceChecks precedenceChecks = PrecedenceChecks.newInstance(context);
generator(precedenceChecks).generate();

Expand Down

0 comments on commit 8796e9e

Please sign in to comment.