diff options
-rw-r--r-- | src/core/lombok/javac/JavacNode.java | 7 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacTransformer.java | 10 | ||||
-rw-r--r-- | src/core/lombok/javac/LombokOptions.java (renamed from src/core/lombok/javac/DeleteLombokAnnotations.java) | 28 | ||||
-rw-r--r-- | src/core/lombok/javac/TrackChangedAsts.java | 10 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/Delombok.java | 16 | ||||
-rw-r--r-- | test/transform/resource/after-delombok/ValInFor.java | 8 | ||||
-rw-r--r-- | test/transform/resource/before/ValComplex.java | 2 | ||||
-rw-r--r-- | test/transform/resource/before/ValErrors.java | 2 | ||||
-rw-r--r-- | test/transform/resource/before/ValInFor.java | 6 | ||||
-rw-r--r-- | test/transform/resource/before/ValLessSimple.java | 2 | ||||
-rw-r--r-- | test/transform/resource/before/ValSimple.java | 2 | ||||
-rw-r--r-- | test/transform/resource/before/ValWeirdTypes.java | 1 | ||||
-rw-r--r-- | test/transform/resource/messages-delombok/ValErrors.java.messages | 4 |
13 files changed, 54 insertions, 44 deletions
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<JavacAST, JavacNode, JCTre } public boolean shouldDeleteLombokAnnotations() { - DeleteLombokAnnotations dla = ast.getContext().get(DeleteLombokAnnotations.class); - return dla != null && dla.isDeleteLombokAnnotations(); + Options options = ast.getContext().get(Options.optionsKey); + return options instanceof LombokOptions && ((LombokOptions)options).deleteLombokAnnotations; } /** diff --git a/src/core/lombok/javac/JavacTransformer.java b/src/core/lombok/javac/JavacTransformer.java index f9757894..beef6924 100644 --- a/src/core/lombok/javac/JavacTransformer.java +++ b/src/core/lombok/javac/JavacTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 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 @@ -25,6 +25,7 @@ import java.util.ArrayList; import javax.annotation.processing.Messager; + import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -32,6 +33,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.List; +import com.sun.tools.javac.util.Options; public class JavacTransformer { private final HandlerLibrary handlers; @@ -78,9 +80,9 @@ public class JavacTransformer { } } - TrackChangedAsts changes = context.get(TrackChangedAsts.class); - if (changes != null) for (JavacAST ast : asts) { - if (ast.isChanged()) changes.changed.add((JCCompilationUnit) ast.top().get()); + Options options = context.get(Options.optionsKey); + if (options instanceof LombokOptions) for (JavacAST ast : asts) { + if (ast.isChanged()) ((LombokOptions)options).changed.add((JCCompilationUnit) ast.top().get()); } } diff --git a/src/core/lombok/javac/DeleteLombokAnnotations.java b/src/core/lombok/javac/LombokOptions.java index 425c4365..4c750bde 100644 --- a/src/core/lombok/javac/DeleteLombokAnnotations.java +++ b/src/core/lombok/javac/LombokOptions.java @@ -1,5 +1,5 @@ /* - * Copyright © 2010 Reinier Zwitserloot and Roel Spilker. + * Copyright © 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 @@ -21,15 +21,27 @@ */ 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; +import java.util.HashSet; +import java.util.Set; + +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Options; + +public class LombokOptions extends Options { - public DeleteLombokAnnotations(boolean deleteLombokAnnotations) { - this.deleteLombokAnnotations = deleteLombokAnnotations; + public boolean deleteLombokAnnotations = true; + public final Set<JCCompilationUnit> changed = new HashSet<JCCompilationUnit>(); + + 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; } - public boolean isDeleteLombokAnnotations() { - return deleteLombokAnnotations; + 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<JCCompilationUnit> changed = new HashSet<JCCompilationUnit>(); -}
\ 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<String> 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<String> 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<Z> { private final List<Z> 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 { ... }) |