aboutsummaryrefslogtreecommitdiff
path: root/src/delombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-01-29 03:07:21 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-01-29 03:07:21 +0100
commit229cde2bf084e243913030ddad4bce13f6c38732 (patch)
tree2a211dfec7a570f50ff83971b323bf3a933f3db3 /src/delombok
parente95680a76733c22ee5937a586ee50c703d5ba621 (diff)
downloadlombok-229cde2bf084e243913030ddad4bce13f6c38732.tar.gz
lombok-229cde2bf084e243913030ddad4bce13f6c38732.tar.bz2
lombok-229cde2bf084e243913030ddad4bce13f6c38732.zip
[Fixes #2349] Support for JDK 14
Added the ability to parse and pretty-print the new 'x instanceof String y' pattern concept. Added a test to the pretty printer to confirm that it works.
Diffstat (limited to 'src/delombok')
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index fc5eaec2..2db70f7f 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 The Project Lombok Authors.
+ * Copyright (C) 2016-2020 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
@@ -1071,7 +1071,11 @@ public class PrettyPrinter extends JCTree.Visitor {
@Override public void visitTypeTest(JCInstanceOf tree) {
print(tree.expr);
print(" instanceof ");
- print(tree.clazz);
+
+ /** With java14, instead of a type (field 'clazz'), there's now a pattern (field 'pattern', of type JCTree, which is either a JCPattern for new-style instanceof, or if not it's the same as what 'clazz' held) */
+ JCTree c = readObject(tree, "clazz", null); // JDK-13
+ if (c == null) c = readObject(tree, "pattern", null); // JDK14+
+ print(c);
}
@Override public void visitTypeCast(JCTypeCast tree) {
@@ -1379,6 +1383,12 @@ public class PrettyPrinter extends JCTree.Visitor {
println(";", tree);
}
+ void printBindingPattern(JCTree tree) {
+ print((JCExpression) readObject(tree, "vartype", null));
+ print(" ");
+ print((Name) readObject(tree, "name", null));
+ }
+
@Override public void visitTry(JCTry tree) {
aPrint("try ");
List<?> resources = readObject(tree, "resources", List.nil());
@@ -1601,6 +1611,8 @@ public class PrettyPrinter extends JCTree.Visitor {
printSwitchExpression(tree);
} else if ("JCYield".equals(simpleName)) { // Introduced as preview feature in JDK13, part of switch expressions.
printYieldExpression(tree);
+ } else if ("JCBindingPattern".equals(simpleName)) { // Introduced as preview in JDK14
+ printBindingPattern(tree);
} else {
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}