From 7e21683515144cc6127eff007226c86021b7b2df Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 4 Dec 2013 07:14:05 +0100 Subject: Added format preferences: Suppress @SuppressWarnings, suppress needless application of 'final'. --- src/delombok/lombok/delombok/Delombok.java | 38 ++++++++++-------- .../lombok/delombok/FormatPreferences.java | 46 +++++++++++++++++++--- 2 files changed, 62 insertions(+), 22 deletions(-) (limited to 'src/delombok/lombok') diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 23400771..ef2d2f38 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -58,6 +58,7 @@ import com.sun.tools.javac.util.Context; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.Excludes; +import com.zwitserloot.cmdreader.FullName; import com.zwitserloot.cmdreader.InvalidCommandLineException; import com.zwitserloot.cmdreader.Mandatory; import com.zwitserloot.cmdreader.Sequential; @@ -91,9 +92,12 @@ public class Delombok { private boolean verbose; @Shorthand("f") - @Description("Sets formatting rules. Use 'help' or 'list' to list all available rules. Unset format rules are inferred by scanning the source for usages.") + @Description("Sets formatting rules. Use --format-help to list all available rules. Unset format rules are inferred by scanning the source for usages.") private List format = new ArrayList(); + @FullName("format-help") + private boolean formatHelp; + @Shorthand("q") @Description("No warnings or errors will be emitted to standard error") @Excludes("verbose") @@ -109,7 +113,7 @@ public class Delombok { @Shorthand("d") @Description("Directory to save delomboked files to") - @Mandatory(onlyIfNot={"print", "help"}) + @Mandatory(onlyIfNot={"print", "help", "format-help"}) private String target; @Shorthand("c") @@ -176,7 +180,7 @@ public class Delombok { return; } - if (args.help || args.input.isEmpty()) { + if (args.help || (args.input.isEmpty() && !args.formatHelp)) { if (!args.help) System.err.println("ERROR: no files or directories to delombok specified."); System.err.println(reader.generateCommandLineHelp("delombok")); System.exit(args.help ? 0 : 1); @@ -193,20 +197,20 @@ public class Delombok { Map formatPrefs = new HashMap(); - for (String format : args.format) { - if ("help".equalsIgnoreCase(format) || "list".equalsIgnoreCase(format)) { - System.out.println("Available format keys (to use, -f key:value -f key2:value2 -f ... ):"); - for (Map.Entry e : FormatPreferences.getKeysAndDescriptions().entrySet()) { - System.out.print(" "); - System.out.print(e.getKey()); - System.out.println(":"); - System.out.println(indentAndWordbreak(e.getValue(), 4, 70)); - } - System.out.println("Example: -f indent:4 -f emptyLines:indent"); - System.exit(0); - return; + if (args.formatHelp) { + System.out.println("Available format keys (to use, -f key:value -f key2:value2 -f ... ):"); + for (Map.Entry e : FormatPreferences.getKeysAndDescriptions().entrySet()) { + System.out.print(" "); + System.out.print(e.getKey()); + System.out.println(":"); + System.out.println(indentAndWordbreak(e.getValue(), 4, 70)); } - + System.out.println("Example: -f indent:4 -f emptyLines:indent"); + System.exit(0); + return; + } + + for (String format : args.format) { int idx = format.indexOf(':'); if (idx == -1) { System.err.println("Format keys need to be 2 values separated with a colon. Try -f help."); @@ -438,7 +442,7 @@ public class Delombok { if (classpath != null) options.putJavacOption("CLASSPATH", classpath); if (sourcepath != null) options.putJavacOption("SOURCEPATH", sourcepath); if (bootclasspath != null) options.putJavacOption("BOOTCLASSPATH", bootclasspath); - options.setFormatPreferences(formatPrefs); + options.setFormatPreferences(new FormatPreferences(formatPrefs)); options.put("compilePolicy", "check"); CommentCatcher catcher = CommentCatcher.create(context); diff --git a/src/delombok/lombok/delombok/FormatPreferences.java b/src/delombok/lombok/delombok/FormatPreferences.java index e733151d..2df0ac60 100644 --- a/src/delombok/lombok/delombok/FormatPreferences.java +++ b/src/delombok/lombok/delombok/FormatPreferences.java @@ -28,17 +28,25 @@ import java.util.Map; public final class FormatPreferences { private final String indent; - private final boolean filledEmpties; + private final Boolean filledEmpties; + private final boolean generateSuppressWarnings; + private final boolean generateFinalParams; static final Map KEYS; static { Map keys = new LinkedHashMap(); keys.put("indent", "The indent to use. 'tab' can be used to represent 1 tab. A number means that many spaces. Default: 'tab'"); keys.put("emptyLines", "Either 'indent' or 'blank'. indent means: Indent an empty line to the right level. Default: 'blank'"); + keys.put("suppressWarnings", "Either 'generate' or 'skip'. generate means: All lombok-generated methods get a @SuppressWarnings annotation. Default: 'generate'"); + keys.put("finalParams", "Either 'generate' or 'skip'. generate means: All lombok-generated methods set all parameters to final. Default: 'generate'"); KEYS = Collections.unmodifiableMap(keys); } - public FormatPreferences(Map preferences, String indent, boolean filledEmpties) { + public FormatPreferences(Map preferences) { + this(preferences, null, null); + } + + public FormatPreferences(Map preferences, String indent, Boolean filledEmpties) { if (preferences == null) preferences = Collections.emptyMap(); String indent_ = preferences.get("indent"); @@ -57,21 +65,49 @@ public final class FormatPreferences { if ("indent".equalsIgnoreCase(empties_)) filledEmpties = true; else if ("blank".equalsIgnoreCase(empties_)) filledEmpties = false; else if (empties_ != null && !"scan".equalsIgnoreCase(empties_)) { - throw new IllegalArgumentException("Legal values for 'emptyLines' is scan, indent, or blank."); + throw new IllegalArgumentException("Legal values for 'emptyLines' are 'scan', 'indent', or 'blank'."); } + this.indent = indent; this.filledEmpties = filledEmpties; + + String generateFinalParams_ = preferences.get("finalParams"); + if (generateFinalParams_ == null || "generate".equalsIgnoreCase(generateFinalParams_)) { + this.generateFinalParams = true; + } else if ("skip".equalsIgnoreCase(generateFinalParams_)) { + this.generateFinalParams = false; + } else { + throw new IllegalArgumentException("Legal values for 'finalParams' are 'generate', or 'skip'."); + } + + String generateSuppressWarnings_ = preferences.get("suppressWarnings"); + if (generateSuppressWarnings_ == null || "generate".equalsIgnoreCase(generateSuppressWarnings_)) { + this.generateSuppressWarnings = true; + } else if ("skip".equalsIgnoreCase(generateSuppressWarnings_)) { + this.generateSuppressWarnings = false; + } else { + throw new IllegalArgumentException("Legal values for 'suppressWarnings' are 'generate', or 'skip'."); + } } + public static Map getKeysAndDescriptions() { return KEYS; } /** If true, empty lines should still be appropriately indented. If false, empty lines should be completely blank. */ public boolean fillEmpties() { - return filledEmpties; + return filledEmpties == null ? false : filledEmpties; } public String indent() { - return indent; + return indent == null ? "\t" : indent; + } + + public boolean generateSuppressWarnings() { + return generateSuppressWarnings; + } + + public boolean generateFinalParams() { + return generateFinalParams; } } -- cgit