mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 12:19:00 +00:00
[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.
This commit is contained in:
4 files changed
+30
-2
No files matched your search
@@ -3,6 +3,7 @@ Lombok Changelog
|
||||
|
||||
### v1.18.11 "Edgy Guinea Pig"
|
||||
* PLATFORM: Support for JDK13 (including `yield` in switch expressions, as well as delombok having a nicer style for arrow-style switch blocks, and text blocks).
|
||||
* PLATFORM: Support for JDK14 (including `pattern match` instanceof expressions).
|
||||
* FEATURE: In [`lombok.config`](https://projectlombok.org/features/configuration) it is possible to import other config files, even from a `.zip` or `.jar`.
|
||||
* FEATURE: You can now configure a builder's 'setter' prefixes via `@Builder(setterPrefix = "set")` for example. We discourage doing this, but if some library you use requires them, have at it. [Pull Request #2174](https://github.com/rzwitserloot/lombok/pull/2174], [Issue #1805](https://github.com/rzwitserloot/lombok/issues/1805).
|
||||
* FEATURE: If you use `@Builder`'s `@Singular`, a plural form is also generated, which has the effect of adding all elements in the passed collection. If you pass a null reference, this would result in a message-less `NullPointerException`. Now, it results in that exception but with a useful message attached, and you can choose other behaviors as well via a parameter on the `@Singular` annotation and via `lombok.config`; you can even choose treat them as empty collections; this can be useful when deserializing (e.g. Jackson JSON) and JPA/Hibernate code. [Issue #2221](https://github.com/rzwitserloot/lombok/issues/2221]. [singular documentation](https://projectlombok.org/features/Builder).
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
public class PatternInstanceOf {
|
||||
public void foo(Object o) {
|
||||
if (o instanceof String y) {
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// version 14:
|
||||
public class PatternInstanceOf {
|
||||
public void foo(Object o) {
|
||||
if (o instanceof String y) {
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user