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

Make enum CLI arguments match documented format #1787

Merged
merged 1 commit into from
Feb 27, 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
15 changes: 10 additions & 5 deletions jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static class CommentsLevelConverter implements IStringConverter<CommentsL
@Override
public CommentsLevel convert(String value) {
try {
return CommentsLevel.valueOf(value.toUpperCase());
return CommentsLevel.valueOf(stringAsEnumName(value));
} catch (Exception e) {
throw new IllegalArgumentException(
'\'' + value + "' is unknown comments level, possible values are: "
Expand All @@ -504,7 +504,7 @@ public static class UseKotlinMethodsForVarNamesConverter implements IStringConve
@Override
public UseKotlinMethodsForVarNames convert(String value) {
try {
return UseKotlinMethodsForVarNames.valueOf(value.replace('-', '_').toUpperCase());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this one already did the - -> _ replacement.

One thing I'm unclear on is if the toUpperCase() should include the Locale.ROOT constant that the enumValuesString passes.. though I don't follow what that's doing - the characters in the enums are all ASCII to begin with?

return UseKotlinMethodsForVarNames.valueOf(stringAsEnumName(value));
} catch (Exception e) {
throw new IllegalArgumentException(
'\'' + value + "' is unknown, possible values are: "
Expand All @@ -517,7 +517,7 @@ public static class DeobfuscationMapFileModeConverter implements IStringConverte
@Override
public DeobfuscationMapFileMode convert(String value) {
try {
return DeobfuscationMapFileMode.valueOf(value.toUpperCase());
return DeobfuscationMapFileMode.valueOf(stringAsEnumName(value));
} catch (Exception e) {
throw new IllegalArgumentException(
'\'' + value + "' is unknown, possible values are: "
Expand All @@ -530,7 +530,7 @@ public static class ResourceNameSourceConverter implements IStringConverter<Reso
@Override
public ResourceNameSource convert(String value) {
try {
return ResourceNameSource.valueOf(value.toUpperCase());
return ResourceNameSource.valueOf(stringAsEnumName(value));
} catch (Exception e) {
throw new IllegalArgumentException(
'\'' + value + "' is unknown, possible values are: "
Expand All @@ -543,7 +543,7 @@ public static class DecompilationModeConverter implements IStringConverter<Decom
@Override
public DecompilationMode convert(String value) {
try {
return DecompilationMode.valueOf(value.toUpperCase());
return DecompilationMode.valueOf(stringAsEnumName(value));
} catch (Exception e) {
throw new IllegalArgumentException(
'\'' + value + "' is unknown, possible values are: "
Expand All @@ -557,4 +557,9 @@ public static String enumValuesString(Enum<?>[] values) {
.map(v -> v.name().replace('_', '-').toLowerCase(Locale.ROOT))
.collect(Collectors.joining(", "));
}

private static String stringAsEnumName(String raw) {
// inverse of enumValuesString conversion
return value.replace('-', '_').toUpperCase();
}
}