Skip to content

Commit

Permalink
Merge pull request #1485 from joelittlejohn/avoid-system-err
Browse files Browse the repository at this point in the history
Avoid output to System.err when finding unique Enum name
  • Loading branch information
joelittlejohn committed Feb 16, 2023
2 parents 65e1fdb + dfbd0c0 commit ef5893b
Showing 1 changed file with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,21 @@ protected EnumDefinition buildEnumDefinition(String nodeName, JsonNode node, JTy

RuleLogger logger = ruleFactory.getLogger();

if (!javaEnums.isMissingNode() && !javaEnumNames.isMissingNode())
{
logger.error("Both javaEnums and javaEnumNames provided; the property javaEnumNames will be ignored when both javaEnums and javaEnumNames are provided.");
if (!javaEnums.isMissingNode() && !javaEnumNames.isMissingNode()) {
logger.warn("Both javaEnums and javaEnumNames provided; the property javaEnumNames will be ignored when both javaEnums and javaEnumNames are provided.");
}

if (!javaEnumNames.isMissingNode())
{
if (!javaEnumNames.isMissingNode()) {
logger.warn("javaEnumNames is deprecated; please migrate to javaEnums.");
}

EnumDefinition enumDefinition;

if (!javaEnums.isMissingNode())
{
if (!javaEnums.isMissingNode()) {
enumDefinition = buildEnumDefinitionWithJavaEnumsExtension(nodeName, node, enums, javaEnums, backingType);
} else if (!javaEnumNames.isMissingNode())
{
} else if (!javaEnumNames.isMissingNode()) {
enumDefinition = buildEnumDefinitionWithJavaEnumNamesExtension(nodeName, node, enums, javaEnumNames, backingType);
} else
{
} else {
enumDefinition = buildEnumDefinitionWithNoExtensions(nodeName, node, enums, backingType);
}

Expand Down Expand Up @@ -471,19 +466,11 @@ protected String getEnumName(String nodeName, JsonNode node, JClassContainer con
}

protected String makeUnique(final String name, Collection<String> existingNames) {
boolean found = false;

for (String existingName : existingNames) {
if (name.equals(existingName)) {
found = true;
break;
}
}

if (found) {
String newName = makeUnique(name + "_", existingNames);
System.err.println("Enum name " + name + " already used; trying to replace it with " + newName);
return newName;
if (existingNames.contains(name)) {
String newName = name + "_";
ruleFactory.getLogger().warn("Enum name " + name + " already used; trying to replace it with " + newName);
return makeUnique(newName, existingNames);
}

return name;
Expand Down

0 comments on commit ef5893b

Please sign in to comment.