Apply "instanceof pattern matching" in spring-webflux

Closes gh-29635
This commit is contained in:
divcon
2022-12-04 22:33:45 +09:00
committed by Sam Brannen
parent 918edaba2e
commit f64397d822
22 changed files with 68 additions and 70 deletions

View File

@@ -84,8 +84,8 @@ class WebClientDataBufferAllocatingTests extends AbstractDataBufferAllocatingTes
private ReactorClientHttpConnector initConnector() {
assertThat(super.bufferFactory).isNotNull();
if (super.bufferFactory instanceof NettyDataBufferFactory) {
ByteBufAllocator allocator = ((NettyDataBufferFactory) super.bufferFactory).getByteBufAllocator();
if (super.bufferFactory instanceof NettyDataBufferFactory nettyDataBufferFactory) {
ByteBufAllocator allocator = nettyDataBufferFactory.getByteBufAllocator();
return new ReactorClientHttpConnector(this.factory,
client -> client.option(ChannelOption.ALLOCATOR, allocator));
}

View File

@@ -144,8 +144,8 @@ public final class Msg extends
*/
public String getFoo() {
Object ref = foo_;
if (ref instanceof String) {
return (String) ref;
if (ref instanceof String stringRef) {
return stringRef;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
@@ -162,10 +162,9 @@ public final class Msg extends
public com.google.protobuf.ByteString
getFooBytes() {
Object ref = foo_;
if (ref instanceof String) {
if (ref instanceof String stringRef) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(String) ref);
com.google.protobuf.ByteString.copyFromUtf8(stringRef);
foo_ = b;
return b;
} else {
@@ -405,8 +404,8 @@ public final class Msg extends
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof Msg) {
return mergeFrom((Msg)other);
if (other instanceof Msg msg) {
return mergeFrom(msg);
} else {
super.mergeFrom(other);
return this;
@@ -463,13 +462,13 @@ public final class Msg extends
*/
public String getFoo() {
Object ref = foo_;
if (!(ref instanceof String)) {
if (!(ref instanceof String stringRef)) {
String s = ((com.google.protobuf.ByteString) ref)
.toStringUtf8();
foo_ = s;
return s;
} else {
return (String) ref;
return stringRef;
}
}
/**
@@ -478,10 +477,9 @@ public final class Msg extends
public com.google.protobuf.ByteString
getFooBytes() {
Object ref = foo_;
if (ref instanceof String) {
if (ref instanceof String stringRef) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(String) ref);
com.google.protobuf.ByteString.copyFromUtf8(stringRef);
foo_ = b;
return b;
} else {

View File

@@ -304,8 +304,8 @@ public final class SecondMsg extends
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof SecondMsg) {
return mergeFrom((SecondMsg)other);
if (other instanceof SecondMsg secondMsg) {
return mergeFrom(secondMsg);
} else {
super.mergeFrom(other);
return this;

View File

@@ -354,7 +354,7 @@ class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
}
private static String partDescription(Part part) {
return part instanceof FilePart ? part.name() + ":" + ((FilePart) part).filename() : part.name();
return part instanceof FilePart filePart? part.name() + ":" + filePart.filename() : part.name();
}
static class FormBean {

View File

@@ -142,15 +142,15 @@ abstract class AbstractReactiveWebSocketIntegrationTests {
// Set dynamically chosen port
this.port = this.server.getPort();
if (this.client instanceof Lifecycle) {
((Lifecycle) this.client).start();
if (this.client instanceof Lifecycle lifecycle) {
lifecycle.start();
}
}
@AfterEach
void stopServer() {
if (this.client instanceof Lifecycle) {
((Lifecycle) this.client).stop();
if (this.client instanceof Lifecycle lifecycle) {
lifecycle.stop();
}
this.server.stop();
}