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

Avoid output to System.err when finding unique Enum name #1485

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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 @@ -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