From 52b8a940ae1249a8965f0c9f8ab18f7e8d115937 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Wed, 1 Feb 2023 09:24:29 +0100 Subject: [PATCH 1/2] Introduce `--source` argument for delombok --- src/delombok/lombok/delombok/Delombok.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index e4f1760222..f68216182f 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -99,7 +99,7 @@ public void setWriter(Writer writer) { private boolean onlyChanged; private boolean force = false; private boolean disablePreview; - private String classpath, sourcepath, bootclasspath, modulepath; + private String classpath, sourcepath, bootclasspath, modulepath, source; private LinkedHashMap fileToBase = new LinkedHashMap(); private List filesToParse = new ArrayList(); private Map formatPrefs = new HashMap(); @@ -154,6 +154,9 @@ private static class CmdArgs { @FullName("module-path") private String modulepath; + @Description("Source version (analogous to javac -source option)") + private String source; + @Description("Files to delombok. Provide either a file, or a directory. If you use a directory, all files in it (recursive) are delombok-ed") @Sequential private List input = new ArrayList(); @@ -308,6 +311,7 @@ public static void main(String[] rawArgs) { if (args.sourcepath != null) delombok.setSourcepath(args.sourcepath); if (args.bootclasspath != null) delombok.setBootclasspath(args.bootclasspath); if (args.modulepath != null) delombok.setModulepath(args.modulepath); + if (args.source != null) delombok.setSource(args.source); try { for (String in : args.input) { @@ -560,6 +564,10 @@ public void setModulepath(String modulepath) { this.modulepath = modulepath; } + public void setSource(String source) { + this.source = source; + } + public void addDirectory(File base) throws IOException { addDirectory0(false, base, "", 0); } @@ -682,6 +690,7 @@ public boolean delombok() throws IOException { if (classpath != null) options.putJavacOption("CLASSPATH", unpackClasspath(classpath)); if (sourcepath != null) options.putJavacOption("SOURCEPATH", sourcepath); if (bootclasspath != null) options.putJavacOption("BOOTCLASSPATH", unpackClasspath(bootclasspath)); + if (source != null) options.putJavacOption("SOURCE", source); options.setFormatPreferences(new FormatPreferences(formatPrefs)); options.put("compilePolicy", "check"); @@ -700,6 +709,10 @@ public boolean delombok() throws IOException { argsList.add("--boot-class-path"); argsList.add(options.get("--boot-class-path")); } + if (source != null) { + argsList.add("-source"); + argsList.add(options.get("-source")); + } if (charset != null) { argsList.add("-encoding"); argsList.add(charset.name()); From 97e61aa826cad6a0b01fee6bb734305af84a53d9 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Wed, 1 Feb 2023 14:54:47 +0100 Subject: [PATCH 2/2] Handle different primary names of javac SOURCE option --- src/delombok/lombok/delombok/Delombok.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index f68216182f..188b97bc37 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -711,7 +711,11 @@ public boolean delombok() throws IOException { } if (source != null) { argsList.add("-source"); - argsList.add(options.get("-source")); + if (Javac.getJavaCompilerVersion() < 12) { + argsList.add(options.get("-source")); + } else { + argsList.add(options.get("--source")); + } } if (charset != null) { argsList.add("-encoding");