Skip to content

Commit 0ad2c51

Browse files
committed
Add now required import
1 parent 51579f4 commit 0ad2c51

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/main/java/org/openrewrite/java/migrate/IllegalArgumentExceptionToAlreadyConnectedException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public J.Try visitTry(J.Try tryStatement, ExecutionContext ctx) {
5454
}
5555
return try_.withCatches(ListUtils.map(try_.getCatches(), catch_ -> {
5656
if (TypeUtils.isOfClassType(catch_.getParameter().getType(), ILLEGAL_ARGUMENT_EXCEPTION)) {
57+
maybeAddImport(ALREADY_CONNECTED_EXCEPTION);
5758
return (J.Try.Catch) new ChangeType(ILLEGAL_ARGUMENT_EXCEPTION, ALREADY_CONNECTED_EXCEPTION, true)
5859
.getVisitor().visit(catch_, ctx);
5960
}

src/test/java/org/openrewrite/java/migrate/IllegalArgumentExceptionToAlreadyConnectedExceptionTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void catchException() {
4040
import java.net.SocketAddress;
4141
import java.nio.channels.DatagramChannel;
4242
43-
public class Test {
44-
public void sendDataCatch() {
43+
class Test {
44+
void sendDataCatch() {
4545
try {
4646
DatagramChannel channel = DatagramChannel.open();
4747
channel.send(ByteBuffer.allocate(1024), new java.net.InetSocketAddress("localhost", 8080));
@@ -53,11 +53,12 @@ public void sendDataCatch() {
5353
""",
5454
"""
5555
import java.nio.ByteBuffer;
56+
import java.nio.channels.AlreadyConnectedException;
5657
import java.net.SocketAddress;
5758
import java.nio.channels.DatagramChannel;
5859
59-
public class Test {
60-
public void sendDataCatch() {
60+
class Test {
61+
void sendDataCatch() {
6162
try {
6263
DatagramChannel channel = DatagramChannel.open();
6364
channel.send(ByteBuffer.allocate(1024), new java.net.InetSocketAddress("localhost", 8080));
@@ -81,8 +82,8 @@ void rethrowException() {
8182
import java.net.SocketAddress;
8283
import java.nio.channels.DatagramChannel;
8384
84-
public class Test {
85-
public void sendDataRethrow() {
85+
class Test {
86+
void sendDataRethrow() {
8687
try {
8788
DatagramChannel channel = DatagramChannel.open();
8889
channel.send(ByteBuffer.allocate(1024), new java.net.InetSocketAddress("localhost", 8080));
@@ -94,11 +95,12 @@ public void sendDataRethrow() {
9495
""",
9596
"""
9697
import java.nio.ByteBuffer;
98+
import java.nio.channels.AlreadyConnectedException;
9799
import java.net.SocketAddress;
98100
import java.nio.channels.DatagramChannel;
99101
100-
public class Test {
101-
public void sendDataRethrow() {
102+
class Test {
103+
void sendDataRethrow() {
102104
try {
103105
DatagramChannel channel = DatagramChannel.open();
104106
channel.send(ByteBuffer.allocate(1024), new java.net.InetSocketAddress("localhost", 8080));
@@ -118,12 +120,13 @@ void retainOtherCaughtExceptions() {
118120
//language=java
119121
java(
120122
"""
121-
import java.io.IOException;import java.nio.ByteBuffer;
123+
import java.io.IOException;
124+
import java.nio.ByteBuffer;
122125
import java.net.SocketAddress;
123126
import java.nio.channels.DatagramChannel;
124127
125-
public class Test {
126-
public void sendData() {
128+
class Test {
129+
void sendData() {
127130
try {
128131
DatagramChannel channel = DatagramChannel.open();
129132
channel.send(ByteBuffer.allocate(1024), new java.net.InetSocketAddress("localhost", 8080));

0 commit comments

Comments
 (0)