diff --git a/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java b/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java index 3ab40e223939..649b3f98a06f 100644 --- a/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java +++ b/platform/util-rt/src/com/intellij/openapi/util/io/FileUtilRt.java @@ -48,7 +48,7 @@ public class FileUtilRt { } // do not use getName to avoid extra String creation (File.getName() calls substring) - final String path = file.getPath(); + String path = file.getPath(); return StringUtilRt.endsWithIgnoreCase(path, ".jar") || StringUtilRt.endsWithIgnoreCase(path, ".zip"); } @@ -123,9 +123,9 @@ public class FileUtilRt { static { boolean initSuccess = false; try { - final Class pathClass = Class.forName("java.nio.file.Path"); - final Class visitorClass = Class.forName("java.nio.file.FileVisitor"); - final Class filesClass = Class.forName("java.nio.file.Files"); + Class pathClass = Class.forName("java.nio.file.Path"); + Class visitorClass = Class.forName("java.nio.file.FileVisitor"); + Class filesClass = Class.forName("java.nio.file.Files"); ourNoSuchFileExceptionClass = Class.forName("java.nio.file.NoSuchFileException"); ourAccessDeniedExceptionClass = Class.forName("java.nio.file.AccessDeniedException"); ourFileToPathMethod = Class.forName("java.io.File").getMethod("toPath"); @@ -231,8 +231,8 @@ public class FileUtilRt { @Contract("null, _, _, _ -> null; !null,_,_,_->!null") protected static String toCanonicalPath(@Nullable String path, - final char separatorChar, - final boolean removeLastSlash, + char separatorChar, + boolean removeLastSlash, @Nullable SymlinkResolver resolver) { if (path == null || path.isEmpty()) { return path; @@ -361,7 +361,7 @@ public class FileUtilRt { } @Contract("_, _, _, null -> true") - private static boolean processDots(@NotNull StringBuilder result, int dots, int start, SymlinkResolver symlinkResolver) { + private static boolean processDots(@NotNull StringBuilder result, int dots, int start, @Nullable SymlinkResolver symlinkResolver) { if (dots == 2) { int pos = -1; if (!StringUtilRt.endsWith(result, "/../") && !"../".contentEquals(result)) { @@ -437,18 +437,18 @@ public class FileUtilRt { } @NotNull - public static String toSystemDependentName(@NotNull String fileName) { - return toSystemDependentName(fileName, File.separatorChar); + public static String toSystemDependentName(@NotNull String path) { + return toSystemDependentName(path, File.separatorChar); } @NotNull - public static String toSystemDependentName(@NotNull String fileName, final char separatorChar) { - return fileName.replace('/', separatorChar).replace('\\', separatorChar); + public static String toSystemDependentName(@NotNull String path, char separatorChar) { + return path.replace('/', separatorChar).replace('\\', separatorChar); } @NotNull - public static String toSystemIndependentName(@NotNull String fileName) { - return fileName.replace('\\', '/'); + public static String toSystemIndependentName(@NotNull String path) { + return path.replace('\\', '/'); } /** @@ -510,7 +510,7 @@ public class FileUtilRt { } @NotNull - private static String ensureEnds(@NotNull String s, final char endsWith) { + private static String ensureEnds(@NotNull String s, char endsWith) { return StringUtilRt.endsWithChar(s, endsWith) ? s : s + endsWith; } @@ -532,7 +532,7 @@ public class FileUtilRt { @NotNull public static File createTempDirectory(@NotNull String prefix, @Nullable String suffix, boolean deleteOnExit) throws IOException { - final File dir = new File(getTempDirectory()); + File dir = new File(getTempDirectory()); return createTempDirectory(dir, prefix, suffix, deleteOnExit); } @@ -583,7 +583,7 @@ public class FileUtilRt { @NotNull public static File createTempFile(@NonNls @NotNull String prefix, @NonNls @Nullable String suffix, boolean deleteOnExit) throws IOException { - final File dir = new File(getTempDirectory()); + File dir = new File(getTempDirectory()); return createTempFile(dir, prefix, suffix, true, deleteOnExit); } @@ -680,7 +680,7 @@ public class FileUtilRt { @NotNull private static File normalizeFile(@NotNull File temp) throws IOException { - final File canonical = temp.getCanonicalFile(); + File canonical = temp.getCanonicalFile(); return SystemInfoRt.isWindows && canonical.getAbsolutePath().contains(" ") ? temp.getAbsoluteFile() : canonical; } @@ -694,9 +694,9 @@ public class FileUtilRt { @NotNull private static String calcCanonicalTempPath() { - final File file = new File(System.getProperty("java.io.tmpdir")); + File file = new File(System.getProperty("java.io.tmpdir")); try { - final String canonical = file.getCanonicalPath(); + String canonical = file.getCanonicalPath(); if (!SystemInfoRt.isWindows || !canonical.contains(" ")) { return canonical; } @@ -741,7 +741,7 @@ public class FileUtilRt { @NotNull public static String loadFile(@NotNull File file, @Nullable String encoding, boolean convertLineSeparators) throws IOException { - final String s = new String(loadFileText(file, encoding)); + String s = new String(loadFileText(file, encoding)); return convertLineSeparators ? StringUtilRt.convertLineSeparators(s) : s; } diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index c1495f97cb0a..cd21d24e5fe4 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -93,15 +93,15 @@ public class FileUtil extends FileUtilRt { } @Nullable - public static @NlsSafe String getRelativePath(@NotNull String basePath, @NotNull String filePath, final char separator) { + public static @NlsSafe String getRelativePath(@NotNull String basePath, @NotNull String filePath, char separator) { return FileUtilRt.getRelativePath(basePath, filePath, separator); } @Nullable public static @NlsSafe String getRelativePath(@NotNull String basePath, - @NotNull String filePath, - final char separator, - final boolean caseSensitive) { + @NotNull String filePath, + char separator, + boolean caseSensitive) { return FileUtilRt.getRelativePath(basePath, filePath, separator, caseSensitive); } @@ -205,7 +205,7 @@ public class FileUtil extends FileUtilRt { public static byte @NotNull [] loadFileBytes(@NotNull File file) throws IOException { byte[] bytes; try (InputStream stream = new FileInputStream(file)) { - final long len = file.length(); + long len = file.length(); if (len < 0) { throw new IOException("File length reported negative, probably doesn't exist"); } @@ -351,7 +351,7 @@ public class FileUtil extends FileUtilRt { if (isSameDrive) { // the optimization is reasonable only if destination dir is located on the same drive - final String originalFileName = file.getName(); + String originalFileName = file.getName(); File tempFile = getTempFile(originalFileName, tempDir); if (file.renameTo(tempFile)) { return tempFile; @@ -405,7 +405,7 @@ public class FileUtil extends FileUtilRt { performCopy(fromFile, toFile, false); } - private static void performCopy(@NotNull File fromFile, @NotNull File toFile, final boolean syncTimestamp) throws IOException { + private static void performCopy(@NotNull File fromFile, @NotNull File toFile, boolean syncTimestamp) throws IOException { if (filesEqual(fromFile, toFile)) return; try (FileOutputStream fos = openOutputStream(toFile); FileInputStream fis = new FileInputStream(fromFile)) { @@ -416,7 +416,7 @@ public class FileUtil extends FileUtilRt { } if (syncTimestamp) { - final long timeStamp = fromFile.lastModified(); + long timeStamp = fromFile.lastModified(); if (timeStamp < 0) { LOG.warn("Invalid timestamp " + timeStamp + " of '" + fromFile + "'"); } @@ -431,12 +431,12 @@ public class FileUtil extends FileUtilRt { } @NotNull - private static FileOutputStream openOutputStream(@NotNull final File file) throws IOException { + private static FileOutputStream openOutputStream(@NotNull File file) throws IOException { try { return new FileOutputStream(file); } catch (FileNotFoundException e) { - final File parentFile = file.getParentFile(); + File parentFile = file.getParentFile(); if (parentFile == null) { throw new IOException("Parent file is null for " + file.getPath(), e); } @@ -500,7 +500,7 @@ public class FileUtil extends FileUtilRt { copyDir(fromDir, toDir, copySystemFiles ? null : file -> !StringUtil.startsWithChar(file.getName(), '.')); } - public static void copyDir(@NotNull File fromDir, @NotNull File toDir, @Nullable final FileFilter filter) throws IOException { + public static void copyDir(@NotNull File fromDir, @NotNull File toDir, @Nullable FileFilter filter) throws IOException { ensureExists(toDir); if (isAncestor(fromDir, toDir, true)) { LOG.error(fromDir.getAbsolutePath() + " is ancestor of " + toDir + ". Can't copy to itself."); @@ -662,9 +662,9 @@ public class FileUtil extends FileUtilRt { @Contract("null, _, _, _ -> null; !null,_,_,_->!null") private static String toCanonicalPath(@Nullable String path, - final char separatorChar, - final boolean removeLastSlash, - final boolean resolveSymlinks) { + char separatorChar, + boolean removeLastSlash, + boolean resolveSymlinks) { SymlinkResolver symlinkResolver = resolveSymlinks ? SYMLINK_RESOLVER : null; return toCanonicalPath(path, separatorChar, removeLastSlash, symlinkResolver); } @@ -688,7 +688,7 @@ public class FileUtil extends FileUtilRt { } for (int i = start; i < path.length(); ++i) { - final char c = path.charAt(i); + char c = path.charAt(i); if (c == '/') { if (separator) { return normalizeTail(i, path, true); @@ -708,7 +708,7 @@ public class FileUtil extends FileUtilRt { @NotNull private static String normalizeTail(int prefixEnd, @NotNull String path, boolean separator) { - final StringBuilder result = new StringBuilder(path.length()); + StringBuilder result = new StringBuilder(path.length()); result.append(path, 0, prefixEnd); int start = prefixEnd; if (start==0 && SystemInfoRt.isWindows && (path.startsWith("//") || path.startsWith("\\\\"))) { @@ -718,7 +718,7 @@ public class FileUtil extends FileUtilRt { } for (int i = start; i < path.length(); ++i) { - final char c = path.charAt(i); + char c = path.charAt(i); if (c == '/' || c == '\\') { if (!separator) result.append('/'); separator = true; @@ -886,13 +886,13 @@ public class FileUtil extends FileUtilRt { @NotNull File root, @NotNull Pattern pattern, @NotNull List files) { - final File[] dirs = root.listFiles(); + File[] dirs = root.listFiles(); if (dirs == null) return; for (File dir : dirs) { if (dir.isFile()) { - final String relativePath = getRelativePath(absoluteRoot, dir); + String relativePath = getRelativePath(absoluteRoot, dir); if (relativePath != null) { - final String path = toSystemIndependentName(relativePath); + String path = toSystemIndependentName(relativePath); if (pattern.matcher(path).matches()) { files.add(dir); } @@ -921,21 +921,21 @@ public class FileUtil extends FileUtilRt { @RegExp @NotNull public static String convertAntToRegexp(@NotNull String antPattern, boolean ignoreStartingSlash) { - final StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder(); int asteriskCount = 0; boolean recursive = true; - final int start = + int start = ignoreStartingSlash && (StringUtil.startsWithChar(antPattern, '/') || StringUtil.startsWithChar(antPattern, '\\')) ? 1 : 0; for (int idx = start; idx < antPattern.length(); idx++) { - final char ch = antPattern.charAt(idx); + char ch = antPattern.charAt(idx); if (ch == '*') { asteriskCount++; continue; } - final boolean foundRecursivePattern = recursive && asteriskCount == 2 && (ch == '/' || ch == '\\'); - final boolean asterisksFound = asteriskCount > 0; + boolean foundRecursivePattern = recursive && asteriskCount == 2 && (ch == '/' || ch == '\\'); + boolean asterisksFound = asteriskCount > 0; asteriskCount = 0; recursive = ch == '/' || ch == '\\'; @@ -976,7 +976,7 @@ public class FileUtil extends FileUtilRt { } // handle ant shorthand: my_package/test/ is interpreted as if it were my_package/test/** - final boolean isTrailingSlash = builder.length() > 0 && builder.charAt(builder.length() - 1) == '/'; + boolean isTrailingSlash = builder.length() > 0 && builder.charAt(builder.length() - 1) == '/'; if (asteriskCount == 0 && isTrailingSlash || recursive && asteriskCount == 2) { if (isTrailingSlash) { builder.setLength(builder.length() - 1); @@ -1134,16 +1134,17 @@ public class FileUtil extends FileUtilRt { */ @Deprecated @ApiStatus.ScheduledForRemoval(inVersion = "2021.3") - public static boolean processFilesRecursively(@NotNull File root, @NotNull Processor processor, - @Nullable final Processor directoryFilter) { - final LinkedList queue = new LinkedList<>(); + public static boolean processFilesRecursively(@NotNull File root, + @NotNull Processor processor, + @Nullable Processor directoryFilter) { + LinkedList queue = new LinkedList<>(); queue.add(root); while (!queue.isEmpty()) { - final File file = queue.removeFirst(); + File file = queue.removeFirst(); if (!processor.process(file)) return false; if (directoryFilter != null && (!file.isDirectory() || !directoryFilter.process(file))) continue; - final File[] children = file.listFiles(); + File[] children = file.listFiles(); if (children != null) { ContainerUtil.addAll(queue, children); } @@ -1207,7 +1208,7 @@ public class FileUtil extends FileUtilRt { * @return path of the first of found files or empty string or null. */ @Nullable - public static @NlsSafe String findFileInProvidedPath(String providedPath, String... fileNames) { + public static @NlsSafe String findFileInProvidedPath(@NotNull String providedPath, @NotNull String @NotNull ... fileNames) { if (Strings.isEmpty(providedPath)) { return ""; } @@ -1309,7 +1310,7 @@ public class FileUtil extends FileUtilRt { return false; } - final int lineBreak = Strings.indexOf(firstCharsIfText, '\n', 2); + int lineBreak = Strings.indexOf(firstCharsIfText, '\n', 2); return lineBreak >= 0 && Strings.indexOf(firstCharsIfText, marker, 2, lineBreak) != -1; }