19
19
import com .google .errorprone .refaster .annotation .BeforeTemplate ;
20
20
import org .openrewrite .java .template .RecipeDescriptor ;
21
21
22
+ import java .net .URI ;
23
+ import java .net .URL ;
24
+
22
25
public class URLConstructorsToURI {
23
26
@ RecipeDescriptor (
24
27
name = "Convert `new URL(String)` to `URI.create(String).toURL()`" ,
25
28
description = "Converts `new URL(String)` constructors to `URI.create(String).toURL()`."
26
29
)
27
30
public static class URLSingleArgumentConstructor {
28
31
@ 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 );
31
34
}
32
35
33
36
@ 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 ();
36
39
}
37
40
}
38
41
@@ -42,13 +45,13 @@ java.net.URL uriCreateToURL(String spec) throws Exception {
42
45
)
43
46
public static class URLThreeArgumentConstructor {
44
47
@ 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 );
47
50
}
48
51
49
52
@ 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 ();
52
55
}
53
56
}
54
57
@@ -58,13 +61,13 @@ java.net.URL newUriToUrl(String protocol, String host, String file) throws Excep
58
61
)
59
62
public static class URLFourArgumentConstructor {
60
63
@ 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 );
63
66
}
64
67
65
68
@ 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 ();
68
71
}
69
72
}
70
73
}
0 commit comments