@@ -65,13 +65,6 @@ class TemporaryFolderToTempDirVisitor extends JavaVisitor<ExecutionContext> {
65
65
private static final MethodMatcher NEW_TEMPORARY_FOLDER = new MethodMatcher (TEMPORARY_FOLDER + "<constructor>()" );
66
66
private static final MethodMatcher NEW_TEMPORARY_FOLDER_WITH_ARG = new MethodMatcher (TEMPORARY_FOLDER + "<constructor>(java.io.File)" );
67
67
68
- final JavaTemplate createTempDirTemplate = JavaTemplate .builder ("Files.createTempDirectory(\" junit\" ).toFile()" )
69
- .imports ("java.nio.file.Files" )
70
- .build ();
71
- final JavaTemplate createTempDirTemplateWithArg = JavaTemplate .builder ("Files.createTempDirectory(#{any(java.io.File)}.toPath(), \" junit\" ).toFile()" )
72
- .imports ("java.nio.file.Files" )
73
- .build ();
74
-
75
68
@ Override
76
69
public J visitCompilationUnit (J .CompilationUnit cu , ExecutionContext ctx ) {
77
70
J .CompilationUnit c = (J .CompilationUnit ) super .visitCompilationUnit (cu , ctx );
@@ -107,18 +100,17 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, Executi
107
100
108
101
@ Override
109
102
public @ Nullable J visitNewClass (J .NewClass newClass , ExecutionContext ctx ) {
110
- boolean hasRuleAnnotation = hasRuleAnnotation ();
111
103
if (NEW_TEMPORARY_FOLDER .matches (newClass )) {
112
- if ( hasRuleAnnotation ) {
113
- return null ;
114
- }
115
- return createTempDirTemplate .apply (getCursor (), newClass .getCoordinates ().replace ());
104
+ return hasRuleAnnotation () ? null : JavaTemplate . builder ( "Files.createTempDirectory( \" junit \" ).toFile()" )
105
+ . imports ( "java.nio.file.Files" )
106
+ . build ()
107
+ .apply (getCursor (), newClass .getCoordinates ().replace ());
116
108
}
117
109
if (NEW_TEMPORARY_FOLDER_WITH_ARG .matches (newClass )) {
118
- if ( hasRuleAnnotation ) {
119
- return null ;
120
- }
121
- return createTempDirTemplateWithArg .apply (getCursor (), newClass .getCoordinates ().replace (), newClass .getArguments ().get (0 ));
110
+ return hasRuleAnnotation () ? null : JavaTemplate . builder ( "Files.createTempDirectory(#{any(java.io.File)}.toPath(), \" junit \" ).toFile()" )
111
+ . imports ( "java.nio.file.Files" )
112
+ . build ()
113
+ .apply (getCursor (), newClass .getCoordinates ().replace (), newClass .getArguments ().get (0 ));
122
114
}
123
115
return super .visitNewClass (newClass , ctx );
124
116
}
0 commit comments