FileRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$).* as compiler argument.

Table of contents
  1. PathOfUri
  2. PathOfString
  3. PathInstance
  4. FilesReadStringWithCharset
  5. FilesReadString
  6. FilesCreateTempFileToFile
  7. FilesCreateTempFileInCustomDirectoryToFile
  8. PathToFileMkDirsFilesExists
  9. FileMkDirsFileExists
  10. FilesNewBufferedReaderPathOf
  11. FilesNewBufferedReaderToPath
  12. FilesNewBufferedReaderPathOfWithCharset
  13. FilesNewBufferedReaderToPathWithCharset

PathOfUri

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathOfUri") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathOfUri).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Path testPathOfUri() {
-  return Paths.get(URI.create("foo"));
+  return Path.of(URI.create("foo"));
 }

PathOfString

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathOfString") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathOfString).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Path> testPathOfString() {
-  return ImmutableSet.of(Paths.get("foo"), Paths.get("bar", "baz", "qux"));
+  return ImmutableSet.of(Path.of("foo"), Path.of("bar", "baz", "qux"));
 }

PathInstance

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathInstance") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathInstance).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 Path testPathInstance() {
-  return Path.of("foo").toFile().toPath();
+  return Path.of("foo");
 }

FilesReadStringWithCharset

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesReadStringWithCharset") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesReadStringWithCharset).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 String testFilesReadStringWithCharset() throws IOException {
-  return new String(Files.readAllBytes(Paths.get("foo")), StandardCharsets.ISO_8859_1);
+  return Files.readString(Paths.get("foo"), StandardCharsets.ISO_8859_1);
 }

FilesReadString

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesReadString") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesReadString).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 String testFilesReadString() throws IOException {
-  return Files.readString(Paths.get("foo"), StandardCharsets.UTF_8);
+  return Files.readString(Paths.get("foo"));
 }

FilesCreateTempFileToFile

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesCreateTempFileToFile") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesCreateTempFileToFile).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<File> testFilesCreateTempFileToFile() throws IOException {
   return ImmutableSet.of(
-      File.createTempFile("foo", "bar"), File.createTempFile("baz", "qux", null));
+      Files.createTempFile("foo", "bar").toFile(), Files.createTempFile("baz", "qux").toFile());
 }

FilesCreateTempFileInCustomDirectoryToFile

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesCreateTempFileInCustomDirectoryToFile") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesCreateTempFileInCustomDirectoryToFile).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 File testFilesCreateTempFileInCustomDirectoryToFile() throws IOException {
-  return File.createTempFile("foo", "bar", new File("baz"));
+  return Files.createTempFile(new File("baz").toPath(), "foo", "bar").toFile();
 }

PathToFileMkDirsFilesExists

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("PathToFileMkDirsFilesExists") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$PathToFileMkDirsFilesExists).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Boolean> testPathToFileMkDirsFilesExists() {
   return ImmutableSet.of(
-      Files.exists(Path.of("foo")) || Path.of("foo").toFile().mkdirs(),
-      !Files.exists(Path.of("bar")) && !Path.of("bar").toFile().mkdirs());
+      Path.of("foo").toFile().mkdirs() || Files.exists(Path.of("foo")),
+      !Path.of("bar").toFile().mkdirs() && !Files.exists(Path.of("bar")));
 }

FileMkDirsFileExists

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FileMkDirsFileExists") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FileMkDirsFileExists).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Boolean> testFileMkDirsFileExists() {
   return ImmutableSet.of(
-      new File("foo").exists() || new File("foo").mkdirs(),
-      !new File("bar").exists() && !new File("bar").mkdirs());
+      new File("foo").mkdirs() || new File("foo").exists(),
+      !new File("bar").mkdirs() && !new File("bar").exists());
 }

FilesNewBufferedReaderPathOf

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedReaderPathOf") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedReaderPathOf).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<BufferedReader> testFilesNewBufferedReaderPathOf() throws IOException {
   return ImmutableSet.of(
-      Files.newBufferedReader(Path.of("foo"), StandardCharsets.UTF_8),
-      new BufferedReader(new InputStreamReader(new FileInputStream("bar"))));
+      Files.newBufferedReader(Path.of("foo")), Files.newBufferedReader(Path.of("bar")));
 }

FilesNewBufferedReaderToPath

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedReaderToPath") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedReaderToPath).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<BufferedReader> testFilesNewBufferedReaderToPath() throws IOException {
   return ImmutableSet.of(
-      Files.newBufferedReader(new File("foo").toPath(), StandardCharsets.UTF_8),
-      new BufferedReader(new InputStreamReader(new FileInputStream(new File("bar")))));
+      Files.newBufferedReader(new File("foo").toPath()),
+      Files.newBufferedReader(new File("bar").toPath()));
 }

FilesNewBufferedReaderPathOfWithCharset

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedReaderPathOfWithCharset") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedReaderPathOfWithCharset).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 BufferedReader testFilesNewBufferedReaderPathOfWithCharset() throws IOException {
-  return new BufferedReader(
-      new InputStreamReader(new FileInputStream("foo"), StandardCharsets.UTF_8));
+  return Files.newBufferedReader(Path.of("foo"), StandardCharsets.UTF_8);
 }

FilesNewBufferedReaderToPathWithCharset

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("FilesNewBufferedReaderToPathWithCharset") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!FileRules\$FilesNewBufferedReaderToPathWithCharset).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 BufferedReader testFilesNewBufferedReaderToPathWithCharset() throws IOException {
-  return new BufferedReader(
-      new InputStreamReader(new FileInputStream(new File("foo")), StandardCharsets.UTF_8));
+  return Files.newBufferedReader(new File("foo").toPath(), StandardCharsets.UTF_8);
 }

Copyright © 2017-2024 Picnic Technologies BV