aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/core/Main.java8
-rw-r--r--src/core/lombok/eclipse/handlers/HandleBuilder.java45
-rw-r--r--src/core/lombok/eclipse/handlers/HandleConstructor.java1
-rw-r--r--src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java2
-rw-r--r--src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java4
-rw-r--r--src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java23
-rw-r--r--src/delombok/lombok/delombok/Delombok.java175
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTask.java30
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTaskImpl.java4
10 files changed, 249 insertions, 45 deletions
diff --git a/src/core/lombok/core/Main.java b/src/core/lombok/core/Main.java
index 6952ab78..47afaefd 100644
--- a/src/core/lombok/core/Main.java
+++ b/src/core/lombok/core/Main.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2012 The Project Lombok Authors.
+ * Copyright (C) 2009-2018 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,9 @@ public class Main {
Thread.currentThread().setContextClassLoader(Main.class.getClassLoader());
int err = new Main(SpiLoadUtil.readAllFromIterator(
SpiLoadUtil.findServices(LombokApp.class)), Arrays.asList(args)).go();
- System.exit(err);
+ if (err != 0) {
+ System.exit(err);
+ }
}
@ProviderFor(LombokApp.class)
@@ -143,7 +145,7 @@ public class Main {
out.println("------------------------------");
}
out.println("projectlombok.org " + Version.getFullVersion());
- out.println("Copyright (C) 2009-2015 The Project Lombok Authors.");
+ out.println("Copyright (C) 2009-2018 The Project Lombok Authors.");
out.println("Run 'lombok license' to see the lombok license agreement.");
out.println();
out.println("Run lombok without any parameters to start the graphical installer.");
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index 09765efc..89cf81e0 100644
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -25,6 +25,7 @@ import static lombok.eclipse.Eclipse.*;
import static lombok.core.handlers.HandlerUtil.*;
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -46,6 +47,7 @@ import org.eclipse.jdt.internal.compiler.ast.FalseLiteral;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
+import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
@@ -443,6 +445,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
cleanDecl.declarationSourceEnd = -1;
cleanDecl.modifiers = ClassFileConstants.AccPrivate;
cleanDecl.type = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
+ cleanDecl.traverse(new SetGeneratedByVisitor(ast), (MethodScope) null);
injectFieldAndMarkGenerated(builderType, cleanDecl);
}
@@ -502,15 +505,12 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
}
}
- private static final char[] EMPTY_LIST = "emptyList".toCharArray();
+ private static final char[] BUILDER_TEMP_VAR = {'b', 'u', 'i', 'l', 'd', 'e', 'r'};
private MethodDeclaration generateToBuilderMethod(String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List<BuilderFieldData> builderFields, boolean fluent, ASTNode source) {
- // return new ThingieBuilder<A, B>().setA(this.a).setB(this.b);
-
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long) pS << 32 | pE;
- MethodDeclaration out = new MethodDeclaration(
- ((CompilationUnitDeclaration) type.top().get()).compilationResult);
+ MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);
out.selector = methodName.toCharArray();
out.modifiers = ClassFileConstants.AccPublic;
out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
@@ -519,6 +519,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
Expression receiver = invoke;
+ List<Statement> statements = null;
for (BuilderFieldData bfd : builderFields) {
char[] setterName = fluent ? bfd.name : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray();
MessageSend ms = new MessageSend();
@@ -542,22 +543,34 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
tgt[i] = obtainExpr;
}
}
+
+ ms.selector = setterName;
if (bfd.singularData == null) {
ms.arguments = tgt;
+ ms.receiver = receiver;
+ receiver = ms;
} else {
- Expression ifNull = new EqualExpression(tgt[0], new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL);
- MessageSend emptyList = new MessageSend();
- emptyList.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.UTIL, "Collections".toCharArray());
- emptyList.selector = EMPTY_LIST;
- emptyList.typeArguments = copyTypes(bfd.singularData.getTypeArgs().toArray(new TypeReference[0]));
- ms.arguments = new Expression[] {new ConditionalExpression(ifNull, emptyList, tgt[1])};
+ ms.arguments = new Expression[] {tgt[1]};
+ ms.receiver = new SingleNameReference(BUILDER_TEMP_VAR, p);
+ EqualExpression isNotNull = new EqualExpression(tgt[0], new NullLiteral(pS, pE), OperatorIds.NOT_EQUAL);
+ if (statements == null) statements = new ArrayList<Statement>();
+ statements.add(new IfStatement(isNotNull, ms, pS, pE));
}
- ms.receiver = receiver;
- ms.selector = setterName;
- receiver = ms;
}
- out.statements = new Statement[] {new ReturnStatement(receiver, pS, pE)};
+ if (statements != null) {
+ out.statements = new Statement[statements.size() + 2];
+ for (int i = 0; i < statements.size(); i++) out.statements[i + 1] = statements.get(i);
+ LocalDeclaration b = new LocalDeclaration(BUILDER_TEMP_VAR, pS, pE);
+ out.statements[0] = b;
+ b.modifiers |= Modifier.FINAL;
+ b.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
+ b.type.sourceStart = pS; b.type.sourceEnd = pE;
+ b.initialization = receiver;
+ out.statements[out.statements.length - 1] = new ReturnStatement(new SingleNameReference(BUILDER_TEMP_VAR, p), pS, pE);
+ } else {
+ out.statements = new Statement[] {new ReturnStatement(receiver, pS, pE)};
+ }
out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
return out;
@@ -617,7 +630,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
inv.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters);
args.add(new ConditionalExpression(
- new SingleNameReference(bfd.nameOfSetFlag, 0L),
+ new SingleNameReference(bfd.nameOfSetFlag, 0L),
new SingleNameReference(bfd.name, 0L),
inv));
} else {
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index cb07115a..82859e4b 100644
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -484,6 +484,7 @@ public class HandleConstructor {
for (EclipseNode node : type.down()) {
if (node.getKind() != Kind.FIELD) continue top;
FieldDeclaration fd = (FieldDeclaration) node.get();
+ if (fd.initialization != null) continue top;
if ((fd.modifiers & ClassFileConstants.AccFinal) == 0) continue top;
if ((fd.modifiers & ClassFileConstants.AccStatic) != 0) continue top;
for (EclipseNode ftp : fieldsToParam) if (node == ftp) continue top;
diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java
index 17fc5e09..4b094a9f 100644
--- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java
+++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java
@@ -94,6 +94,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
buildField.modifiers = ClassFileConstants.AccPrivate;
buildField.declarationSourceEnd = -1;
buildField.type = type;
+
data.setGeneratedByRecursive(buildField);
return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField));
}
@@ -117,6 +118,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
md.returnType = returnType;
md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
+ data.setGeneratedByRecursive(md);
injectMethod(builderType, md);
}
diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java
index c7315790..11314bd3 100644
--- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java
+++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java
@@ -85,6 +85,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
buildField.modifiers = ClassFileConstants.AccPrivate;
buildField.declarationSourceEnd = -1;
buildField.type = type;
+
data.setGeneratedByRecursive(buildField);
return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField));
}
@@ -117,6 +118,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
md.statements = returnStatement != null ? new Statement[] {clearStatement, returnStatement} : new Statement[] {clearStatement};
md.returnType = returnType;
md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
+
+ data.setGeneratedByRecursive(md);
injectMethod(builderType, md);
}
@@ -149,7 +152,6 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
data.setGeneratedByRecursive(md);
-
HandleNonNull.INSTANCE.fix(injectMethod(builderType, md));
}
diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java
index 174cd5fc..55f6cadd 100644
--- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java
+++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java
@@ -127,6 +127,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
buildValueField.declarationSourceEnd = -1;
buildValueField.type = type;
}
+
data.setGeneratedByRecursive(buildKeyField);
data.setGeneratedByRecursive(buildValueField);
EclipseNode keyFieldNode = injectFieldAndMarkGenerated(builderType, buildKeyField);
@@ -174,6 +175,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
md.returnType = returnType;
md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
+ data.setGeneratedByRecursive(md);
injectMethod(builderType, md);
}
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index bc1a8072..c5c1e1ca 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -484,6 +484,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
sb.append("__ERR__");
}
+ private static final String BUILDER_TEMP_VAR = "builder";
private JCMethodDecl generateToBuilderMethod(String toBuilderMethodName, String builderClassName, JavacNode type, List<JCTypeParameter> typeParams, java.util.List<BuilderFieldData> builderFields, boolean fluent, JCAnnotation ast) {
// return new ThingieBuilder<A, B>().setA(this.a).setB(this.b);
JavacTreeMaker maker = type.getTreeMaker();
@@ -495,6 +496,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
JCExpression call = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), List.<JCExpression>nil(), null);
JCExpression invoke = call;
+ ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
for (BuilderFieldData bfd : builderFields) {
Name setterName = fluent ? bfd.name : type.toName(HandlerUtil.buildAccessorName("set", bfd.name.toString()));
JCExpression[] tgt = new JCExpression[bfd.singularData == null ? 1 : 2];
@@ -519,18 +521,21 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
JCExpression arg;
if (bfd.singularData == null) {
arg = tgt[0];
+ invoke = maker.Apply(List.<JCExpression>nil(), maker.Select(invoke, setterName), List.of(arg));
} else {
- JCExpression eqNull = maker.Binary(CTC_EQUAL, tgt[0], maker.Literal(CTC_BOT, null));
- List<JCExpression> tas = cloneTypes(maker, bfd.singularData.getTypeArgs(), ast, type.getContext());
- JCExpression emptyList = maker.Apply(tas, chainDots(type, "java", "util", "Collections", "emptyList"), List.<JCExpression>nil());
- arg = maker.Conditional(eqNull, emptyList, tgt[1]);
+ JCExpression isNotNull = maker.Binary(CTC_NOT_EQUAL, tgt[0], maker.Literal(CTC_BOT, null));
+ JCExpression invokeBuilder = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(type.toName(BUILDER_TEMP_VAR)), setterName), List.<JCExpression>of(tgt[1]));
+ statements.append(maker.If(isNotNull, maker.Exec(invokeBuilder), null));
}
-
- invoke = maker.Apply(List.<JCExpression>nil(), maker.Select(invoke, setterName), List.of(arg));
}
- JCStatement statement = maker.Return(invoke);
-
- JCBlock body = maker.Block(0, List.<JCStatement>of(statement));
+ if (!statements.isEmpty()) {
+ JCExpression tempVarType = namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams);
+ statements.prepend(maker.VarDef(maker.Modifiers(Flags.FINAL), type.toName(BUILDER_TEMP_VAR), tempVarType, invoke));
+ statements.append(maker.Return(maker.Ident(type.toName(BUILDER_TEMP_VAR))));
+ } else {
+ statements.append(maker.Return(invoke));
+ }
+ JCBlock body = maker.Block(0, statements.toList());
return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName(toBuilderMethodName), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
}
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index f5372fbb..0b97b4be 100644
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2017 The Project Lombok Authors.
+ * Copyright (C) 2009-2018 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,14 +26,18 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
+import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
@@ -88,7 +92,7 @@ public class Delombok {
private boolean noCopy;
private boolean onlyChanged;
private boolean force = false;
- private String classpath, sourcepath, bootclasspath;
+ private String classpath, sourcepath, bootclasspath, modulepath;
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>();
@@ -138,6 +142,10 @@ public class Delombok {
@Description("override Bootclasspath (analogous to javac -bootclasspath option)")
private String bootclasspath;
+ @Description("Module path (analogous to javac --module-path option)")
+ @FullName("module-path")
+ private String modulepath;
+
@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>();
@@ -182,21 +190,50 @@ public class Delombok {
return out.toString();
}
+ static String getPathOfSelf() {
+ String url = Delombok.class.getResource("Delombok.class").toString();
+ if (url.endsWith("lombok/delombok/Delombok.class")) {
+ url = urlDecode(url.substring(0, url.length() - "lombok/delombok/Delombok.class".length()));
+ } else if (url.endsWith("lombok/delombok/Delombok.SCL.lombok")) {
+ url = urlDecode(url.substring(0, url.length() - "lombok/delombok/Delombok.SCL.lombok".length()));
+ } else {
+ return null;
+ }
+ if (url.startsWith("jar:file:") && url.endsWith("!/")) return url.substring(9, url.length() - 2);
+ if (url.startsWith("file:")) return url.substring(5);
+ return null;
+ }
+
+ private static String urlDecode(String in) {
+ try {
+ return URLDecoder.decode(in, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new InternalError("UTF-8 not supported");
+ }
+ }
+
public static void main(String[] rawArgs) {
+ try {
+ rawArgs = fileExpand(rawArgs);
+ } catch (IOException e) {
+ System.out.println(e.getMessage());
+ System.exit(1);
+ }
+
CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class);
CmdArgs args;
try {
args = reader.make(rawArgs);
} catch (InvalidCommandLineException e) {
System.err.println("ERROR: " + e.getMessage());
- System.err.println(reader.generateCommandLineHelp("delombok"));
+ System.err.println(cmdHelp(reader));
System.exit(1);
return;
}
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.err.println(cmdHelp(reader));
System.exit(args.help ? 0 : 1);
return;
}
@@ -253,6 +290,7 @@ public class Delombok {
if (args.classpath != null) delombok.setClasspath(args.classpath);
if (args.sourcepath != null) delombok.setSourcepath(args.sourcepath);
if (args.bootclasspath != null) delombok.setBootclasspath(args.bootclasspath);
+ if (args.modulepath != null) delombok.setModulepath(args.modulepath);
try {
for (String in : args.input) {
@@ -273,15 +311,123 @@ public class Delombok {
if (!args.quiet) {
String msg = e.getMessage();
if (msg != null && msg.startsWith("DELOMBOK: ")) System.err.println(msg.substring("DELOMBOK: ".length()));
- else {
- e.printStackTrace();
- }
+ else e.printStackTrace();
System.exit(1);
return;
}
}
}
+ private static String cmdHelp(CmdReader<CmdArgs> reader) {
+ String x = reader.generateCommandLineHelp("delombok");
+ int idx = x.indexOf('\n');
+ return x.substring(0, idx) + "\n You can use @filename.args to read arguments from the file 'filename.args'.\n" + x.substring(idx);
+ }
+
+ private static String[] fileExpand(String[] rawArgs) throws IOException {
+ String[] out = rawArgs;
+ int offset = 0;
+ for (int i = 0; i < rawArgs.length; i++) {
+ if (rawArgs[i].length() > 0 && rawArgs[i].charAt(0) == '@') {
+ String[] parts = readArgsFromFile(rawArgs[i].substring(1));
+ String[] newOut = new String[out.length + parts.length - 1];
+ System.arraycopy(out, 0, newOut, 0, i + offset);
+ System.arraycopy(parts, 0, newOut, i + offset, parts.length);
+ System.arraycopy(out, i + offset + 1, newOut, i + offset + parts.length, out.length - (i + offset + 1));
+ offset += parts.length - 1;
+ out = newOut;
+ }
+ }
+
+ return out;
+ }
+
+ private static String[] readArgsFromFile(String file) throws IOException {
+ InputStream in = new FileInputStream(file);
+ StringBuilder s = new StringBuilder();
+ try {
+ InputStreamReader isr = new InputStreamReader(in, "UTF-8");
+ char[] c = new char[4096];
+ while (true) {
+ int r = isr.read(c);
+ if (r == -1) break;
+ s.append(c, 0, r);
+ }
+ } finally {
+ in.close();
+ }
+
+ List<String> x = new ArrayList<String>();
+ StringBuilder a = new StringBuilder();
+ int state = 1;
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (state < 0) {
+ state = -state;
+ if (c != '\n') a.append(c);
+ continue;
+ }
+ if (state == 1) {
+ if (c == '\\') {
+ state = -1;
+ continue;
+ }
+ if (c == '"') {
+ state = 2;
+ continue;
+ }
+ if (c == '\'') {
+ state = 3;
+ continue;
+ }
+ if (Character.isWhitespace(c)) {
+ String aa = a.toString();
+ if (!aa.isEmpty()) x.add(aa);
+ a.setLength(0);
+ continue;
+ }
+ a.append(c);
+ continue;
+ }
+ if (state == 2) {
+ if (c == '\\') {
+ state = -2;
+ continue;
+ }
+ if (c == '"') {
+ state = 1;
+ x.add(a.toString());
+ a.setLength(0);
+ continue;
+ }
+ a.append(c);
+ continue;
+ }
+ if (state == 3) {
+ if (c == '\'') {
+ state = 1;
+ x.add(a.toString());
+ a.setLength(0);
+ continue;
+ }
+ a.append(c);
+ continue;
+ }
+ }
+ if (state == 1) {
+ String aa = a.toString();
+ if (!aa.isEmpty()) x.add(aa);
+ } else if (state < 0) {
+ throw new IOException("Unclosed backslash escape in @ file");
+ } else if (state == 2) {
+ throw new IOException("Unclosed \" in @ file");
+ } else if (state == 3) {
+ throw new IOException("Unclosed ' in @ file");
+ }
+
+ return x.toArray(new String[x.size()]);
+ }
+
public static class InvalidFormatOptionException extends Exception {
public InvalidFormatOptionException(String msg) {
super(msg);
@@ -385,6 +531,10 @@ public class Delombok {
this.output = null;
}
+ public void setModulepath(String modulepath) {
+ this.modulepath = modulepath;
+ }
+
public void addDirectory(File base) throws IOException {
addDirectory0(false, base, "", 0);
}
@@ -525,8 +675,19 @@ public class Delombok {
argsList.add("-encoding");
argsList.add(charset.name());
}
+ String pathToSelfJar = getPathOfSelf();
+ if (pathToSelfJar != null) {
+ argsList.add("--module-path");
+ argsList.add((modulepath == null || modulepath.isEmpty()) ? pathToSelfJar : (pathToSelfJar + File.pathSeparator + modulepath));
+ } else if (modulepath != null && !modulepath.isEmpty()) {
+ argsList.add("--module-path");
+ argsList.add(modulepath);
+ }
String[] argv = argsList.toArray(new String[0]);
args.init("javac", argv);
+ options.put("diags.legacy", "TRUE");
+ } else {
+ if (modulepath != null && !modulepath.isEmpty()) throw new IllegalStateException("DELOMBOK: Option --module-path requires usage of JDK9 or higher.");
}
CommentCatcher catcher = CommentCatcher.create(context);
diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java
index 06bbe3e0..adaf43dd 100644
--- a/src/delombok/lombok/delombok/ant/DelombokTask.java
+++ b/src/delombok/lombok/delombok/ant/DelombokTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 The Project Lombok Authors.
+ * Copyright (C) 2009-2018 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -78,6 +78,7 @@ class Tasks {
private File fromDir, toDir;
private Path classpath;
private Path sourcepath;
+ private Path modulepath;
private boolean verbose;
private String encoding;
private Path path;
@@ -92,9 +93,7 @@ class Tasks {
}
public Path createClasspath() {
- if (classpath == null) {
- classpath = new Path(getProject());
- }
+ if (classpath == null) classpath = new Path(getProject());
return classpath.createPath();
}
@@ -111,9 +110,7 @@ class Tasks {
}
public Path createSourcepath() {
- if (sourcepath == null) {
- sourcepath = new Path(getProject());
- }
+ if (sourcepath == null) sourcepath = new Path(getProject());
return sourcepath.createPath();
}
@@ -121,6 +118,23 @@ class Tasks {
createSourcepath().setRefid(r);
}
+ public void setModulepath(Path modulepath) {
+ if (this.modulepath == null) {
+ this.modulepath = modulepath;
+ } else {
+ this.modulepath.append(modulepath);
+ }
+ }
+
+ public Path createModulepath() {
+ if (modulepath == null) modulepath = new Path(getProject());
+ return modulepath.createPath();
+ }
+
+ public void setModulepathRef(Reference r) {
+ createModulepath().setRefid(r);
+ }
+
public void setFrom(File dir) {
this.fromDir = dir;
}
@@ -180,7 +194,7 @@ class Tasks {
try {
Object instance = shadowLoadClass("lombok.delombok.ant.DelombokTaskImpl").newInstance();
- for(Field selfField : getClass().getDeclaredFields()) {
+ for (Field selfField : getClass().getDeclaredFields()) {
if (selfField.isSynthetic() || Modifier.isStatic(selfField.getModifiers())) continue;
Field otherField = instance.getClass().getDeclaredField(selfField.getName());
otherField.setAccessible(true);
diff --git a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java
index 470819cd..bd2f93e7 100644
--- a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java
+++ b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 The Project Lombok Authors.
+ * Copyright (C) 2009-2018 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,6 +40,7 @@ public class DelombokTaskImpl {
private File fromDir, toDir;
private Path classpath;
private Path sourcepath;
+ private Path modulepath;
private boolean verbose;
private String encoding;
private Path path;
@@ -60,6 +61,7 @@ public class DelombokTaskImpl {
if (classpath != null) delombok.setClasspath(classpath.toString());
if (sourcepath != null) delombok.setSourcepath(sourcepath.toString());
+ if (modulepath != null) delombok.setModulepath(modulepath.toString());
try {
delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions));