Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce --source argument for Delombok #3340

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/delombok/lombok/delombok/Delombok.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<File, File> fileToBase = new LinkedHashMap<File, File>();
private List<File> filesToParse = new ArrayList<File>();
private Map<String, String> formatPrefs = new HashMap<String, String>();
Expand Down Expand Up @@ -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<String> input = new ArrayList<String>();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");

Expand All @@ -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());
Expand Down