Fix how parameter delegates are handled

This commit is contained in:
Ben Gruver 2016-09-05 15:42:35 -07:00
parent c12b7e6e00
commit 9f794030da
6 changed files with 15 additions and 26 deletions

View File

@ -34,6 +34,7 @@ package org.jf.baksmali;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate;
import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument; import org.jf.baksmali.AnalysisArguments.CheckPackagePrivateArgument;
import org.jf.dexlib2.analysis.CustomInlineMethodResolver; import org.jf.dexlib2.analysis.CustomInlineMethodResolver;
import org.jf.dexlib2.analysis.InlineMethodResolver; import org.jf.dexlib2.analysis.InlineMethodResolver;
@ -52,6 +53,8 @@ import java.util.List;
commandName = "deodex", commandName = "deodex",
commandAliases = { "de", "x" }) commandAliases = { "de", "x" })
public class DeodexCommand extends DisassembleCommand { public class DeodexCommand extends DisassembleCommand {
@ParametersDelegate
protected CheckPackagePrivateArgument checkPackagePrivateArgument = new CheckPackagePrivateArgument(); protected CheckPackagePrivateArgument checkPackagePrivateArgument = new CheckPackagePrivateArgument();
@Parameter(names = {"--inline-table", "--inline", "--it"}, @Parameter(names = {"--inline-table", "--inline", "--it"},
@ -65,10 +68,6 @@ public class DeodexCommand extends DisassembleCommand {
super(commandAncestors); super(commandAncestors);
} }
@Override protected void setupCommand(JCommander jc) {
jc.addObject(checkPackagePrivateArgument);
}
@Override protected BaksmaliOptions getOptions(DexFile dexFile) { @Override protected BaksmaliOptions getOptions(DexFile dexFile) {
BaksmaliOptions options = super.getOptions(dexFile); BaksmaliOptions options = super.getOptions(dexFile);

View File

@ -34,6 +34,7 @@ package org.jf.baksmali;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate;
import com.beust.jcommander.validators.PositiveInteger; import com.beust.jcommander.validators.PositiveInteger;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -62,6 +63,7 @@ public class DisassembleCommand extends DexInputCommand {
description = "Show usage information for this command.") description = "Show usage information for this command.")
private boolean help; private boolean help;
@ParametersDelegate
protected AnalysisArguments analysisArguments = new AnalysisArguments(); protected AnalysisArguments analysisArguments = new AnalysisArguments();
@Parameter(names = {"--debug-info", "--di"}, arity = 1, @Parameter(names = {"--debug-info", "--di"}, arity = 1,
@ -137,10 +139,6 @@ public class DisassembleCommand extends DexInputCommand {
super(commandAncestors); super(commandAncestors);
} }
@Override protected void setupCommand(JCommander jc) {
jc.addObject(analysisArguments);
}
public void run() { public void run() {
if (help || inputList == null || inputList.isEmpty()) { if (help || inputList == null || inputList.isEmpty()) {
usage(); usage();

View File

@ -34,6 +34,7 @@ package org.jf.baksmali;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate;
import org.jf.dexlib2.analysis.ClassPath; import org.jf.dexlib2.analysis.ClassPath;
import org.jf.dexlib2.analysis.ClassProto; import org.jf.dexlib2.analysis.ClassProto;
import org.jf.dexlib2.dexbacked.DexBackedDexFile; import org.jf.dexlib2.dexbacked.DexBackedDexFile;
@ -57,16 +58,13 @@ public class ListFieldOffsetsCommand extends DexInputCommand {
description = "Show usage information") description = "Show usage information")
private boolean help; private boolean help;
@ParametersDelegate
private AnalysisArguments analysisArguments = new AnalysisArguments(); private AnalysisArguments analysisArguments = new AnalysisArguments();
public ListFieldOffsetsCommand(@Nonnull List<JCommander> commandAncestors) { public ListFieldOffsetsCommand(@Nonnull List<JCommander> commandAncestors) {
super(commandAncestors); super(commandAncestors);
} }
@Override protected void setupCommand(JCommander jc) {
jc.addObject(analysisArguments);
}
@Override public void run() { @Override public void run() {
if (help || inputList == null || inputList.isEmpty()) { if (help || inputList == null || inputList.isEmpty()) {
usage(); usage();

View File

@ -59,6 +59,7 @@ public class ListVtablesCommand extends DexInputCommand {
description = "Show usage information") description = "Show usage information")
private boolean help; private boolean help;
@ParametersDelegate
private AnalysisArguments analysisArguments = new AnalysisArguments(); private AnalysisArguments analysisArguments = new AnalysisArguments();
@ParametersDelegate @ParametersDelegate
@ -73,11 +74,6 @@ public class ListVtablesCommand extends DexInputCommand {
super(commandAncestors); super(commandAncestors);
} }
@Override protected void setupCommand(JCommander jc) {
jc.addObject(analysisArguments);
jc.addObject(checkPackagePrivateArgument);
}
@Override public void run() { @Override public void run() {
if (help || inputList == null || inputList.isEmpty()) { if (help || inputList == null || inputList.isEmpty()) {
usage(); usage();

View File

@ -32,6 +32,7 @@
package org.jf.util.jcommander; package org.jf.util.jcommander;
import com.beust.jcommander.JCommander; import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterDescription;
import com.beust.jcommander.Parameterized; import com.beust.jcommander.Parameterized;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
@ -98,10 +99,10 @@ public class ExtendedCommands {
} }
@Nonnull @Nonnull
public static String[] parameterArgumentNames(JCommander jc, Parameterized parameterized) { public static String[] parameterArgumentNames(ParameterDescription parameterDescription) {
// TODO: this won't work if we're using additional objects to collect parameters Parameterized parameterized = parameterDescription.getParameterized();
Class cls = jc.getObjects().get(0).getClass(); Class cls = parameterDescription.getObject().getClass();
Field field = null; Field field = null;
while (cls != Object.class) { while (cls != Object.class) {
try { try {

View File

@ -163,8 +163,7 @@ public class HelpFormatter {
} }
if (leafJc.getMainParameter() != null) { if (leafJc.getMainParameter() != null) {
String[] argumentNames = ExtendedCommands.parameterArgumentNames( String[] argumentNames = ExtendedCommands.parameterArgumentNames(leafJc.getMainParameter());
leafJc, leafJc.getMainParameter().getParameterized());
if (argumentNames.length == 0) { if (argumentNames.length == 0) {
writer.write(" <args>"); writer.write(" <args>");
} else { } else {
@ -200,8 +199,7 @@ public class HelpFormatter {
writer.write(Joiner.on(',').join(param.getParameter().names())); writer.write(Joiner.on(',').join(param.getParameter().names()));
} }
if (getParameterArity(param) > 0) { if (getParameterArity(param) > 0) {
String[] argumentNames = ExtendedCommands.parameterArgumentNames( String[] argumentNames = ExtendedCommands.parameterArgumentNames(param);
leafJc, param.getParameterized());
for (int i = 0; i < getParameterArity(param); i++) { for (int i = 0; i < getParameterArity(param); i++) {
writer.write(" "); writer.write(" ");
if (i < argumentNames.length) { if (i < argumentNames.length) {
@ -242,8 +240,7 @@ public class HelpFormatter {
} }
if (leafJc.getMainParameter() != null) { if (leafJc.getMainParameter() != null) {
String[] argumentNames = ExtendedCommands.parameterArgumentNames(leafJc, String[] argumentNames = ExtendedCommands.parameterArgumentNames(leafJc.getMainParameter());
leafJc.getMainParameter().getParameterized());
writer.write("\n"); writer.write("\n");
writer.indent(4); writer.indent(4);
if (argumentNames.length > 0) { if (argumentNames.length > 0) {