-
Notifications
You must be signed in to change notification settings - Fork 422
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
Code cleanup #1070
Code cleanup #1070
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1070 +/- ##
============================================
+ Coverage 94.41% 94.43% +0.02%
Complexity 448 448
============================================
Files 2 2
Lines 6591 6564 -27
Branches 1763 1765 +2
============================================
- Hits 6223 6199 -24
Misses 94 94
+ Partials 274 271 -3
Continue to review full report at Codecov.
|
Also there are a lot of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall some nice improvements, thank you!
I put some comments, can you take a look?
@@ -7732,7 +7724,6 @@ void initFromMixin(UsageMessageSpec mixin, CommandSpec commandSpec) { | |||
if (initializable(sortOptions, mixin.sortOptions(), DEFAULT_SORT_OPTIONS)) {sortOptions = mixin.sortOptions();} | |||
if (initializable(synopsisHeading, mixin.synopsisHeading(), DEFAULT_SYNOPSIS_HEADING)) {synopsisHeading = mixin.synopsisHeading();} | |||
if (initializable(synopsisSubcommandLabel, mixin.synopsisSubcommandLabel(), DEFAULT_SYNOPSIS_SUBCOMMANDS)) {synopsisHeading = mixin.synopsisHeading();} | |||
if (initializable(width, mixin.width(), DEFAULT_USAGE_WIDTH)) {width = mixin.width();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never reached. initializable
checks whether the varaible is null and is not the default value, but an int is never null.
private static boolean initializable(Object current, Object candidate, Object defaultValue) {
return current == null && isNonDefault(candidate, defaultValue);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to keep this, we may introduce initializable
s with each primitive type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug: #1072
Fixing this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this one; the warning that this condition is always false
should go away with the latest master.
@@ -5138,9 +5133,8 @@ public Help create(CommandSpec commandSpec, Help.ColorScheme colorScheme) { | |||
return cls.cast(new LinkedHashMap<Object, Object>()); | |||
} | |||
try { | |||
@SuppressWarnings("deprecation") // Class.newInstance is deprecated in Java 9 | |||
T result = cls.newInstance(); | |||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This @SuppressWarnings("deprecation")
annotation suppresses the warning one gets when building the project with Java 9. I think it is better to keep it.
@@ -235,7 +235,7 @@ public void run() { | |||
} | |||
} | |||
|
|||
private static interface Function<T, V> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I am okay with removing static
for inner interfaces.
@@ -1470,7 +1470,7 @@ public void clearExecutionResults() { | |||
* @see RunAll | |||
* @deprecated Use {@link IExecutionStrategy} instead. | |||
* @since 2.0 */ | |||
@Deprecated public static interface IParseResultHandler { | |||
@Deprecated public interface IParseResultHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, no problem removing static
for inner interfaces.
@@ -1758,7 +1758,7 @@ protected R throwOrExit(ExecutionException ex) { | |||
* @since 2.0 */ | |||
@Deprecated public static class DefaultExceptionHandler<R> extends AbstractHandler<R, DefaultExceptionHandler<R>> implements IExceptionHandler, IExceptionHandler2<R> { | |||
public List<Object> handleException(ParameterException ex, PrintStream out, Help.Ansi ansi, String... args) { | |||
internalHandleParseException(ex, new PrintWriter(out, true), Help.defaultColorScheme(ansi)); return Collections.<Object>emptyList(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I introduced this to get rid of a "raw collections" warning when building with Java 8 or higher... Probably better to keep the generified form with <Object>
.
@@ -10038,7 +10025,6 @@ public MethodParam(Method method, int paramIndex) { | |||
} | |||
@Override public Annotation[] getDeclaredAnnotations() { return method.getParameterAnnotations()[paramIndex]; } | |||
@Override public void setAccessible(boolean flag) throws SecurityException { method.setAccessible(flag); } | |||
@SuppressWarnings("deprecation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method.isAccessible
will give deprecation warnings when building on Java 9+.
I believe we want to suppress this.
Try this:
%JAVA_11_HOME%\bin\javac -Xlint:all -d c:\Temp picocli\CommandLine.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried compiling on java 11 with -Xlint:all, I saw deprecation warnings for method.isAccessible
.
You did not get this?
@@ -14943,7 +14921,7 @@ public IParamLabelRenderer createDefaultParamLabelRenderer() { | |||
* OptionSpec#description()} array, and these rows look like {@code {"", "", "", option.description()[i]}}.</p> | |||
*/ | |||
static class DefaultOptionRenderer implements IOptionRenderer { | |||
private String requiredMarker = " "; | |||
private String requiredMarker; | |||
private boolean showDefaultValues; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make requiredMarker
and showDefaultValues
final
fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be final too?
I have checked the other removed |
The added final modifiers seem to break the codegen graalvm-aot tests, since the generated fields have an entra Edit: The field should not be made final, reverted. |
On a side note, I think we should also remove the broken kloudtek logo (HTTPS cert expired) and machine-translated article (从Commons CLI迁移到Picocli) from README. |
Thank you!
Interesting! I’ll take a look tomorrow.
Is the translation that bad? :-) |
This is due to a private field being made final, but it is accessed by reflection from annotations. I have removed the final modifier that caused the issue.
The translation is simply google translate I think. It is not unreadable tho, but some code snippets are being 'translated', and it is also not the original post (it is a repost). The original post is here (the content is the same, but with better formatting): https://blog.csdn.net/Tybyqi/article/details/85787550 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the initFromMixin
bit; other than that, looks good.
@@ -14943,7 +14921,7 @@ public IParamLabelRenderer createDefaultParamLabelRenderer() { | |||
* OptionSpec#description()} array, and these rows look like {@code {"", "", "", option.description()[i]}}.</p> | |||
*/ | |||
static class DefaultOptionRenderer implements IOptionRenderer { | |||
private String requiredMarker = " "; | |||
private String requiredMarker; | |||
private boolean showDefaultValues; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be final too?
@@ -10038,7 +10025,6 @@ public MethodParam(Method method, int paramIndex) { | |||
} | |||
@Override public Annotation[] getDeclaredAnnotations() { return method.getParameterAnnotations()[paramIndex]; } | |||
@Override public void setAccessible(boolean flag) throws SecurityException { method.setAccessible(flag); } | |||
@SuppressWarnings("deprecation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried compiling on java 11 with -Xlint:all, I saw deprecation warnings for method.isAccessible
.
You did not get this?
@@ -7732,7 +7724,6 @@ void initFromMixin(UsageMessageSpec mixin, CommandSpec commandSpec) { | |||
if (initializable(sortOptions, mixin.sortOptions(), DEFAULT_SORT_OPTIONS)) {sortOptions = mixin.sortOptions();} | |||
if (initializable(synopsisHeading, mixin.synopsisHeading(), DEFAULT_SYNOPSIS_HEADING)) {synopsisHeading = mixin.synopsisHeading();} | |||
if (initializable(synopsisSubcommandLabel, mixin.synopsisSubcommandLabel(), DEFAULT_SYNOPSIS_SUBCOMMANDS)) {synopsisHeading = mixin.synopsisHeading();} | |||
if (initializable(width, mixin.width(), DEFAULT_USAGE_WIDTH)) {width = mixin.width();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug: #1072
Fixing this now.
@@ -7732,7 +7724,6 @@ void initFromMixin(UsageMessageSpec mixin, CommandSpec commandSpec) { | |||
if (initializable(sortOptions, mixin.sortOptions(), DEFAULT_SORT_OPTIONS)) {sortOptions = mixin.sortOptions();} | |||
if (initializable(synopsisHeading, mixin.synopsisHeading(), DEFAULT_SYNOPSIS_HEADING)) {synopsisHeading = mixin.synopsisHeading();} | |||
if (initializable(synopsisSubcommandLabel, mixin.synopsisSubcommandLabel(), DEFAULT_SYNOPSIS_SUBCOMMANDS)) {synopsisHeading = mixin.synopsisHeading();} | |||
if (initializable(width, mixin.width(), DEFAULT_USAGE_WIDTH)) {width = mixin.width();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this one; the warning that this condition is always false
should go away with the latest master.
Made the fields final.
No.. I think it should, but for some reason it is not giving me warning. I have added the @SupressWarnings annotation back.
Done. |
Merged into master. |
This PR removes redundant modifiers and initializations, unused variables, incorrect javadoc references, etc.
The
static
modifiers in inner interfaces are removed since they are static by default, and removing them should not break binary compatibility (the md5sums are the same). Let me know if those are preferred to be kept.