-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java 17 instanceof pattern matching for modules #82341
Conversation
…ntions through modules
Pinging @elastic/es-core-infra (Team:Core/Infra) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except a few smaller things, no need for another round.
Thanks for improving this!
@@ -1209,8 +1209,7 @@ private void sync(Path sourceRoot, Path destinationRoot, BiConsumer<Path, Path> | |||
} | |||
}); | |||
} catch (UncheckedIOException e) { | |||
if (e.getCause() instanceof NoSuchFileException) { | |||
NoSuchFileException cause = (NoSuchFileException) e.getCause(); | |||
if (e.getCause()instanceof NoSuchFileException cause) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing space
if (e.getCause()instanceof NoSuchFileException cause) { | |
if (e.getCause() instanceof NoSuchFileException cause) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henningandersen unfortunately, that whitespace missing there is the result of spotless, because of a bug. https://bugs.eclipse.org/bugs/show_bug.cgi?id=574437
Even if it was fixed on the Eclipse side, we need to wait for Spotless to upgrade. I think diffplug/spotless#1046 this is the issue we are waiting for to be fixed.
@@ -58,8 +58,8 @@ public MapXContentParser( | |||
|
|||
@Override | |||
protected boolean doBooleanValue() throws IOException { | |||
if (iterator != null && iterator.currentValue() instanceof Boolean) { | |||
return (Boolean) iterator.currentValue(); | |||
if (iterator != null && iterator.currentValue()instanceof Boolean aBoolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space
if (iterator != null && iterator.currentValue()instanceof Boolean aBoolean) { | |
if (iterator != null && iterator.currentValue() instanceof Boolean aBoolean) { |
@@ -216,8 +216,8 @@ public NumberType numberType() throws IOException { | |||
|
|||
@Override | |||
public byte[] binaryValue() throws IOException { | |||
if (iterator != null && iterator.currentValue() instanceof byte[]) { | |||
return (byte[]) iterator.currentValue(); | |||
if (iterator != null && iterator.currentValue()instanceof byte[] bytes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space:
if (iterator != null && iterator.currentValue()instanceof byte[] bytes) { | |
if (iterator != null && iterator.currentValue() instanceof byte[] bytes) { |
@@ -621,22 +621,19 @@ public void visitStringConcatenation(StringConcatenationNode irStringConcatenati | |||
int j = i; | |||
irRightNode.visit(this, (e) -> irStringConcatenationNode.getArgumentNodes().set(j + 1, e)); | |||
|
|||
if (irLeftNode instanceof ConstantNode && irRightNode instanceof ConstantNode) { | |||
ConstantNode irConstantNode = (ConstantNode) irLeftNode; | |||
if (irLeftNode instanceof ConstantNode irConstantNode && irRightNode instanceof ConstantNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems slightly inconsistently used here, in that the cast to ConstantNode
seems unnecessary. I would prefer to either cast/pattern match both left and right nodes or none of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I didn't particularly like this block of code changes either. Seems too compact and the code too similar between the conditional branches to make it easy to read. I've reverted the changes. Even if the instanceof pattern matching is not used, the readability of the code is slightly better this way.
irConstantNode.attachDecoration( | ||
new IRDConstant( | ||
"" + irConstantNode.getDecorationValue(IRDConstant.class) + irRightNode.getDecorationValue(IRDConstant.class) | ||
) | ||
); | ||
irConstantNode.attachDecoration(new IRDExpressionType(String.class)); | ||
irStringConcatenationNode.getArgumentNodes().remove(i + 1); | ||
} else if (irLeftNode instanceof NullNode && irRightNode instanceof ConstantNode) { | ||
ConstantNode irConstantNode = (ConstantNode) irRightNode; | ||
} else if (irLeftNode instanceof NullNode && irRightNode instanceof ConstantNode irConstantNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, seems simpler to just use irRightNode
in the block? Also easier to read.
irConstantNode.attachDecoration(new IRDConstant("" + null + irRightNode.getDecorationValue(IRDConstant.class))); | ||
irConstantNode.attachDecoration(new IRDExpressionType(String.class)); | ||
irStringConcatenationNode.getArgumentNodes().remove(i); | ||
} else if (irLeftNode instanceof ConstantNode && irRightNode instanceof NullNode) { | ||
ConstantNode irConstantNode = (ConstantNode) irLeftNode; | ||
} else if (irLeftNode instanceof ConstantNode irConstantNode && irRightNode instanceof NullNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
💚 Backport successful
|
Switch to Java 17 instanceof pattern matching for folders build-conventions through modules
Switch to Java 17
instanceof
pattern matching for foldersbuild-conventions
throughmodules
.