diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index e4f1760222..188b97bc37 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,14 @@ public boolean delombok() throws IOException { argsList.add("--boot-class-path"); argsList.add(options.get("--boot-class-path")); } + if (source != null) { + argsList.add("-source"); + if (Javac.getJavaCompilerVersion() < 12) { + argsList.add(options.get("-source")); + } else { + argsList.add(options.get("--source")); + } + } if (charset != null) { argsList.add("-encoding"); argsList.add(charset.name());