aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-26 01:24:16 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-26 01:26:37 +0100
commit320fbfee4dbf17b0e2c467311e0fd062448321c4 (patch)
tree0f9bea34a9dae4fa478df91df753e0262222b9ec
parent33281d857891b24cb1c40233807620769a158bbf (diff)
downloadlombok-320fbfee4dbf17b0e2c467311e0fd062448321c4.tar.gz
lombok-320fbfee4dbf17b0e2c467311e0fd062448321c4.tar.bz2
lombok-320fbfee4dbf17b0e2c467311e0fd062448321c4.zip
[fixes #2049] Delombok now figures out usages of ‘var’ and delomboks them as just ‘var’ instead of their actual type.
-rw-r--r--doc/changelog.markdown1
-rwxr-xr-xsrc/delombok/lombok/delombok/Delombok.java1
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java6
-rw-r--r--test/pretty/resource/after/Java11Var.javva6
-rw-r--r--test/pretty/resource/before/Java11Var.java7
5 files changed, 20 insertions, 1 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 7c1cfd1c..864f93db 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -6,6 +6,7 @@ Lombok Changelog
* FEATURE: When using `@NonNull`, or any other annotation that would result in a null-check, you can configure to generate an assert statement instead. [Issue #2078](https://github.com/rzwitserloot/lombok/issues/2078).
* BUGFIX: var/val on methods that return an intersection type would now work in Eclipse. [Issue #1986](https://github.com/rzwitserloot/lombok/issues/1986)
* BUGFIX: Fix for java6 regression if a field has javadoc. [Issue #2066](https://github.com/rzwitserloot/lombok/issues/2066)
+* BUGFIX: Delombok now delomboks java10's own `var` as `var` and not as the actual underlying type. [Issue #2049](https://github.com/rzwitserloot/lombok/issues/2049)
* IMPROBABLE BREAKING CHANGE: For fields and parameters marked non-null, if the method body starts with an assert statement to ensure the value isn't null, no code to throw an exception will be generated.
### v1.18.6 (February 12th, 2019)
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index 9582c3b8..8f4f99e5 100755
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -753,6 +753,7 @@ public class Delombok {
Object care = callAttributeMethodOnJavaCompiler(delegate, delegate.todo);
callFlowMethodOnJavaCompiler(delegate, care);
+
FormatPreferences fps = new FormatPreferences(formatPrefs);
for (JCCompilationUnit unit : roots) {
DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit), fps);
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 353bd753..832dbe0a 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -648,7 +648,11 @@ public class PrettyPrinter extends JCTree.Visitor {
*/
try {
innermostArrayBracketsAreVarargs = varargs;
- print(tree.vartype);
+ if (tree.vartype == null || tree.vartype.pos == -1) {
+ print("var");
+ } else {
+ print(tree.vartype);
+ }
} finally {
innermostArrayBracketsAreVarargs = false;
}
diff --git a/test/pretty/resource/after/Java11Var.javva b/test/pretty/resource/after/Java11Var.javva
new file mode 100644
index 00000000..cec4be6d
--- /dev/null
+++ b/test/pretty/resource/after/Java11Var.javva
@@ -0,0 +1,6 @@
+public class Java11Var {
+ public void test() {
+ var b = 10;
+ int c = 11;
+ }
+}
diff --git a/test/pretty/resource/before/Java11Var.java b/test/pretty/resource/before/Java11Var.java
new file mode 100644
index 00000000..cfbe1989
--- /dev/null
+++ b/test/pretty/resource/before/Java11Var.java
@@ -0,0 +1,7 @@
+//version 11:
+public class Java11Var {
+ public void test() {
+ var b = 10;
+ int c = 11;
+ }
+}