From b0072a17eba21cdc6f8ba51693bb39d1c9aba319 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 29 Nov 2010 22:43:44 +0100 Subject: lombok.val import now gets removed. Only adding lombok.val flags the compilation unit as changed. --- src/core/lombok/javac/DeleteLombokAnnotations.java | 35 ---------------- src/core/lombok/javac/JavacNode.java | 7 ++-- src/core/lombok/javac/JavacTransformer.java | 10 +++-- src/core/lombok/javac/LombokOptions.java | 47 ++++++++++++++++++++++ src/core/lombok/javac/TrackChangedAsts.java | 10 ----- src/delombok/lombok/delombok/Delombok.java | 16 +++----- .../resource/after-delombok/ValInFor.java | 8 ++-- test/transform/resource/before/ValComplex.java | 2 + test/transform/resource/before/ValErrors.java | 2 + test/transform/resource/before/ValInFor.java | 6 ++- test/transform/resource/before/ValLessSimple.java | 2 + test/transform/resource/before/ValSimple.java | 2 + test/transform/resource/before/ValWeirdTypes.java | 1 + .../messages-delombok/ValErrors.java.messages | 4 +- 14 files changed, 81 insertions(+), 71 deletions(-) delete mode 100644 src/core/lombok/javac/DeleteLombokAnnotations.java create mode 100644 src/core/lombok/javac/LombokOptions.java delete mode 100644 src/core/lombok/javac/TrackChangedAsts.java diff --git a/src/core/lombok/javac/DeleteLombokAnnotations.java b/src/core/lombok/javac/DeleteLombokAnnotations.java deleted file mode 100644 index 425c4365..00000000 --- a/src/core/lombok/javac/DeleteLombokAnnotations.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2010 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.javac; - -/** Used as marker in javac's Context object when delombok is running to signal that all lombok annotations should be deleted as they are processed. */ -public class DeleteLombokAnnotations { - private final boolean deleteLombokAnnotations; - - public DeleteLombokAnnotations(boolean deleteLombokAnnotations) { - this.deleteLombokAnnotations = deleteLombokAnnotations; - } - - public boolean isDeleteLombokAnnotations() { - return deleteLombokAnnotations; - } -} diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java index 7dd49644..83eb9088 100644 --- a/src/core/lombok/javac/JavacNode.java +++ b/src/core/lombok/javac/JavacNode.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,6 +39,7 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; /** @@ -197,8 +198,8 @@ public class JavacNode extends lombok.core.LombokNode changed = new HashSet(); + + public static LombokOptions replaceWithDelombokOptions(Context context) { + Options options = Options.instance(context); + context.put(optionsKey, (Options)null); + LombokOptions result = new LombokOptions(context); + result.putAll(options); + return result; + } + + private LombokOptions(Context context) { + super(context); + } +} diff --git a/src/core/lombok/javac/TrackChangedAsts.java b/src/core/lombok/javac/TrackChangedAsts.java deleted file mode 100644 index fa6c0f18..00000000 --- a/src/core/lombok/javac/TrackChangedAsts.java +++ /dev/null @@ -1,10 +0,0 @@ -package lombok.javac; - -import java.util.HashSet; -import java.util.Set; - -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; - -public class TrackChangedAsts { - public final Set changed = new HashSet(); -} \ No newline at end of file diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index f3069c25..0bc60877 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -44,14 +44,12 @@ import java.util.Map; import javax.tools.DiagnosticListener; import javax.tools.JavaFileObject; -import lombok.javac.DeleteLombokAnnotations; -import lombok.javac.TrackChangedAsts; +import lombok.javac.LombokOptions; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.Options; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.Excludes; @@ -70,7 +68,7 @@ public class Delombok { } public Delombok() { - context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true)); +// context.put(DeleteLombokAnnotations.class, new DeleteLombokAnnotations(true)); } private PrintStream feedback = System.err; @@ -349,7 +347,7 @@ public class Delombok { } public boolean delombok() throws IOException { - Options options = Options.instance(context); + LombokOptions options = LombokOptions.replaceWithDelombokOptions(context); options.put(OptionName.ENCODING, charset.name()); if (classpath != null) options.put(OptionName.CLASSPATH, classpath); if (sourcepath != null) options.put(OptionName.SOURCEPATH, sourcepath); @@ -383,13 +381,9 @@ public class Delombok { return false; } - TrackChangedAsts tca = new TrackChangedAsts(); - - context.put(TrackChangedAsts.class, tca); - JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots))); for (JCCompilationUnit unit : roots) { - DelombokResult result = new DelombokResult(commentsMap.get(unit).comments.toList(), unit, force || tca.changed.contains(unit)); + DelombokResult result = new DelombokResult(commentsMap.get(unit).comments.toList(), unit, force || options.changed.contains(unit)); if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged"); Writer rawWriter; if (presetWriter != null) rawWriter = presetWriter; diff --git a/test/transform/resource/after-delombok/ValInFor.java b/test/transform/resource/after-delombok/ValInFor.java index a04d0f0c..013cd02e 100644 --- a/test/transform/resource/after-delombok/ValInFor.java +++ b/test/transform/resource/after-delombok/ValInFor.java @@ -9,11 +9,11 @@ public class ValInFor { final java.lang.String v = a; } } -/* public void enhancedFor() { + public void enhancedFor() { java.util.List list = java.util.Arrays.asList("Hello, World!"); - for (val shouldBeString : list) { + for (final java.lang.String shouldBeString : list) { System.out.println(shouldBeString.toLowerCase()); - val shouldBeString2 = shouldBeString; + final java.lang.String shouldBeString2 = shouldBeString; } - }*/ + } } \ No newline at end of file diff --git a/test/transform/resource/before/ValComplex.java b/test/transform/resource/before/ValComplex.java index 5f718003..c2e53011 100644 --- a/test/transform/resource/before/ValComplex.java +++ b/test/transform/resource/before/ValComplex.java @@ -1,3 +1,5 @@ +import lombok.val; + public class ValComplex { private ValSimple field = new ValSimple(); private static final int CONSTANT = 20; diff --git a/test/transform/resource/before/ValErrors.java b/test/transform/resource/before/ValErrors.java index 7c5c0a8b..96181638 100644 --- a/test/transform/resource/before/ValErrors.java +++ b/test/transform/resource/before/ValErrors.java @@ -1,3 +1,5 @@ +import lombok.val; + public class ValErrors { public void unresolvableExpression() { val c = d; diff --git a/test/transform/resource/before/ValInFor.java b/test/transform/resource/before/ValInFor.java index af13540e..ebe7287c 100644 --- a/test/transform/resource/before/ValInFor.java +++ b/test/transform/resource/before/ValInFor.java @@ -1,3 +1,5 @@ +import lombok.val; + public class ValInFor { { val x = 10; @@ -10,11 +12,11 @@ public class ValInFor { } } -/* public void enhancedFor() { + public void enhancedFor() { java.util.List list = java.util.Arrays.asList("Hello, World!"); for (val shouldBeString : list) { System.out.println(shouldBeString.toLowerCase()); val shouldBeString2 = shouldBeString; } - }*/ + } } \ No newline at end of file diff --git a/test/transform/resource/before/ValLessSimple.java b/test/transform/resource/before/ValLessSimple.java index bae7b73b..31f8030d 100644 --- a/test/transform/resource/before/ValLessSimple.java +++ b/test/transform/resource/before/ValLessSimple.java @@ -1,3 +1,5 @@ +import lombok.val; + public class ValLessSimple { private short field2 = 5; diff --git a/test/transform/resource/before/ValSimple.java b/test/transform/resource/before/ValSimple.java index 15508bbc..04763be2 100644 --- a/test/transform/resource/before/ValSimple.java +++ b/test/transform/resource/before/ValSimple.java @@ -1,3 +1,5 @@ +import lombok.val; + public class ValSimple { private String field = "field"; private short field2 = 5; diff --git a/test/transform/resource/before/ValWeirdTypes.java b/test/transform/resource/before/ValWeirdTypes.java index 855fb91f..302ef841 100644 --- a/test/transform/resource/before/ValWeirdTypes.java +++ b/test/transform/resource/before/ValWeirdTypes.java @@ -1,4 +1,5 @@ import java.util.*; +import lombok.val; public class ValWeirdTypes { private final List fieldList; diff --git a/test/transform/resource/messages-delombok/ValErrors.java.messages b/test/transform/resource/messages-delombok/ValErrors.java.messages index ca7baeab..bd59ad3b 100644 --- a/test/transform/resource/messages-delombok/ValErrors.java.messages +++ b/test/transform/resource/messages-delombok/ValErrors.java.messages @@ -1,2 +1,2 @@ -3:21 ERROR Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved -7:21 ERROR 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... }) +5:21 ERROR Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved +9:21 ERROR 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... }) -- cgit