Skip to content

Commit

Permalink
[#1504] workaround Java 5 compiler limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Dec 7, 2021
1 parent a8b658a commit beeef2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public static void bash(String scriptName, File out, File command, CommandLine c
"\n" +
"LIBS=path/to/libs\n" +
"CP=\"${LIBS}/myApp.jar\"\n" +
"java -cp \"${CP}\" '" + commandLine.getCommand().getClass().getName() + "' $@");
"java -cp \"${CP}\" '" + ((Object) commandLine.getCommand()).getClass().getName() + "' $@");
}
} finally {
if (completionWriter != null) { completionWriter.close(); }
Expand Down Expand Up @@ -635,7 +635,7 @@ private static String generateFunctionForCommand(String functionName, String com
}
}
// If the command is a HelpCommand, append parent subcommands to the autocompletion list.
if (commandLine.getParent() != null && commandLine.getCommand() instanceof HelpCommand) {
if (commandLine.getParent() != null && ((Object) commandLine.getCommand()) instanceof HelpCommand) {
subCommands = new LinkedHashSet<String>(subCommands);
for (CommandLine subCommandLine : commandLine.getParent().getSubcommands().values()) {
if (commandLine == subCommandLine) { continue; } // Skip the HelpCommand itself
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ public static <T> T populateCommand(T command, String... args) {
public static <T> T populateSpec(Class<T> spec, String... args) {
CommandLine cli = toCommandLine(spec, new DefaultFactory());
cli.parse(args);
return cli.getCommand();
return cli.<T>getCommand();
}

/** Expands any {@linkplain CommandLine#isExpandAtFiles() @-files} in the specified command line arguments, then
Expand Down Expand Up @@ -1922,9 +1922,9 @@ static Integer executeHelpRequest(List<CommandLine> parsedCommands) {
return parsed.getCommandSpec().exitCodeOnVersionHelp();
} else if (parsed.getCommandSpec().helpCommand()) {
PrintWriter err = parsed.getErr();
if (parsed.getCommand() instanceof IHelpCommandInitializable2) {
if (((Object) parsed.getCommand()) instanceof IHelpCommandInitializable2) {
((IHelpCommandInitializable2) parsed.getCommand()).init(parsed, colorScheme, out, err);
} else if (parsed.getCommand() instanceof IHelpCommandInitializable) {
} else if (((Object) parsed.getCommand()) instanceof IHelpCommandInitializable) {
((IHelpCommandInitializable) parsed.getCommand()).init(parsed, colorScheme.ansi, System.out, System.err);
}
executeUserObject(parsed, new ArrayList<Object>());
Expand Down Expand Up @@ -2769,7 +2769,7 @@ public void printVersionHelp(PrintWriter out, Help.Ansi ansi, Object... params)
@Deprecated public static <C extends Callable<T>, T> T call(C callable, String... args) {
CommandLine cmd = new CommandLine(callable);
List<Object> results = cmd.parseWithHandler(new RunLast(), args);
return firstElement(results);
return CommandLine.<T>firstElement(results);
}

/**
Expand Down Expand Up @@ -2838,7 +2838,7 @@ public void printVersionHelp(PrintWriter out, Help.Ansi ansi, Object... params)
@Deprecated public static <C extends Callable<T>, T> T call(C callable, PrintStream out, PrintStream err, Help.Ansi ansi, String... args) {
CommandLine cmd = new CommandLine(callable);
List<Object> results = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
return firstElement(results);
return CommandLine.<T>firstElement(results);
}
/**
* Equivalent to {@code new CommandLine(callableClass, factory).execute(args)}, except for the return value.
Expand All @@ -2857,7 +2857,7 @@ public void printVersionHelp(PrintWriter out, Help.Ansi ansi, Object... params)
@Deprecated public static <C extends Callable<T>, T> T call(Class<C> callableClass, IFactory factory, String... args) {
CommandLine cmd = new CommandLine(callableClass, factory);
List<Object> results = cmd.parseWithHandler(new RunLast(), args);
return firstElement(results);
return CommandLine.<T>firstElement(results);
}
/**
* Delegates to {@link #call(Class, IFactory, PrintStream, PrintStream, Help.Ansi, String...)} with
Expand Down Expand Up @@ -2933,7 +2933,7 @@ public void printVersionHelp(PrintWriter out, Help.Ansi ansi, Object... params)
@Deprecated public static <C extends Callable<T>, T> T call(Class<C> callableClass, IFactory factory, PrintStream out, PrintStream err, Help.Ansi ansi, String... args) {
CommandLine cmd = new CommandLine(callableClass, factory);
List<Object> results = cmd.parseWithHandlers(new RunLast().useOut(out).useAnsi(ansi), new DefaultExceptionHandler<List<Object>>().useErr(err).useAnsi(ansi), args);
return firstElement(results);
return CommandLine.<T>firstElement(results);
}

@SuppressWarnings("unchecked") private static <T> T firstElement(List<Object> results) {
Expand Down Expand Up @@ -8930,7 +8930,7 @@ private String defaultValueFromProvider() {
/** Returns the current value of this argument. Delegates to the current {@link #getter()}. */
public <T> T getValue() throws PicocliException {
try {
return getter.get();
return getter.<T>get();
} catch (PicocliException ex) { throw ex;
} catch (Exception ex) { throw new PicocliException("Could not get value for " + this + ": " + ex, ex);
}
Expand Down Expand Up @@ -11771,7 +11771,7 @@ class ProxyBinding implements IGetter, ISetter {
ProxyBinding(Method method) { this.method = Assert.notNull(method, "method"); }
@SuppressWarnings("unchecked") public <T> T get() { return (T) map.get(method.getName()); }
public <T> T set(T value) {
T result = get();
T result = this.<T>get();
map.put(method.getName(), value);
return result;
}
Expand Down

0 comments on commit beeef2d

Please sign in to comment.