Skip to content

Commit f399d72

Browse files
committed
URLConstructorsToURI performance
1 parent 0219793 commit f399d72

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/main/java/org/openrewrite/java/migrate/net/URLConstructorsToURI.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@
1919
import com.google.errorprone.refaster.annotation.BeforeTemplate;
2020
import org.openrewrite.java.template.RecipeDescriptor;
2121

22+
import java.net.URI;
23+
import java.net.URL;
24+
2225
public class URLConstructorsToURI {
2326
@RecipeDescriptor(
2427
name = "Convert `new URL(String)` to `URI.create(String).toURL()`",
2528
description = "Converts `new URL(String)` constructors to `URI.create(String).toURL()`."
2629
)
2730
public static class URLSingleArgumentConstructor {
2831
@BeforeTemplate
29-
java.net.URL urlConstructor(String spec) throws Exception {
30-
return new java.net.URL(spec);
32+
URL urlConstructor(String spec) throws Exception {
33+
return new URL(spec);
3134
}
3235

3336
@AfterTemplate
34-
java.net.URL uriCreateToURL(String spec) throws Exception {
35-
return java.net.URI.create(spec).toURL();
37+
URL uriCreateToURL(String spec) throws Exception {
38+
return URI.create(spec).toURL();
3639
}
3740
}
3841

@@ -42,13 +45,13 @@ java.net.URL uriCreateToURL(String spec) throws Exception {
4245
)
4346
public static class URLThreeArgumentConstructor {
4447
@BeforeTemplate
45-
java.net.URL urlConstructor(String protocol, String host, String file) throws Exception {
46-
return new java.net.URL(protocol, host, file);
48+
URL urlConstructor(String protocol, String host, String file) throws Exception {
49+
return new URL(protocol, host, file);
4750
}
4851

4952
@AfterTemplate
50-
java.net.URL newUriToUrl(String protocol, String host, String file) throws Exception {
51-
return new java.net.URI(protocol, null, host, -1, file, null, null).toURL();
53+
URL newUriToUrl(String protocol, String host, String file) throws Exception {
54+
return new URI(protocol, null, host, -1, file, null, null).toURL();
5255
}
5356
}
5457

@@ -58,13 +61,13 @@ java.net.URL newUriToUrl(String protocol, String host, String file) throws Excep
5861
)
5962
public static class URLFourArgumentConstructor {
6063
@BeforeTemplate
61-
java.net.URL urlConstructor(String protocol, String host, int port, String file) throws Exception {
62-
return new java.net.URL(protocol, host, port, file);
64+
URL urlConstructor(String protocol, String host, int port, String file) throws Exception {
65+
return new URL(protocol, host, port, file);
6366
}
6467

6568
@AfterTemplate
66-
java.net.URL newUriToUrl(String protocol, String host, int port, String file) throws Exception {
67-
return new java.net.URI(protocol, null, host, port, file, null, null).toURL();
69+
URL newUriToUrl(String protocol, String host, int port, String file) throws Exception {
70+
return new URI(protocol, null, host, port, file, null, null).toURL();
6871
}
6972
}
7073
}

0 commit comments

Comments
 (0)