Skip to content

Fix TemporaryFolderToTempDir: Don't add methods to unrelated classes #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025

Conversation

amishra-u
Copy link
Contributor

What's changed?

The TemporaryFolderToTempDir recipe was previously adding newFolder and newFile methods to all classes in the compilation unit and this may produce uncompilable code. The updated code now adds these methods only to the relevant class.

Before

class MyTest {
      @Rule
      TemporaryFolder tempDir1 = new TemporaryFolder();
      void foo() throws IOException {
          File file1 = tempDir1.newFolder();
      }
      class InnerClass {
         private static File newFolder(File root, String... subDirs) throws IOException {}
      }
      
      private static File newFolder(File root, String... subDirs) throws IOException { }
  }

After

class MyTest {
      @Rule
      TemporaryFolder tempDir1 = new TemporaryFolder();
      void foo() throws IOException {
          File file1 = tempDir1.newFolder();
      }
      class InnerClass { }
      
      private static File newFolder(File root, String... subDirs) throws IOException { }
  }

Anyone you would like to review specifically?

@timtebeek

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite May 8, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 2583-2598
    • lines 3392-3391
    • lines 3427-3445

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes makes sense, thanks!

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite May 8, 2025
@timtebeek timtebeek merged commit 258cc3f into openrewrite:main May 8, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite May 8, 2025
@timtebeek timtebeek added the bug Something isn't working label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants