From 34c7fbc706ebe0cd4f746ad255bb1e22b728028c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 27 Jul 2015 21:42:50 +0200 Subject: [PATCH] Cleanup (duplicates; formatting; typos) --- .../intellij/compiler/impl/CompilerUtil.java | 27 ++++---------- .../jps/builders/JpsBuildTestCase.java | 9 +---- .../openapi/application/RunResult.java | 37 ++++++------------- .../openapi/application/WriteAction.java | 10 +++-- .../src/com/intellij/openapi/vfs/VfsUtil.java | 12 ++++++ .../vfs/impl/local/LocalFileSystemBase.java | 7 +--- .../intellij/openapi/util/io/FileUtil.java | 21 +++++++---- .../packaging/AbstractJavaFxPackager.java | 7 +--- .../idea/svn/SvnFileSystemListener.java | 14 ++----- 9 files changed, 59 insertions(+), 85 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java index 1881d088c61f..065cd6baf03f 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompilerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * created at Jan 3, 2002 - * @author Jeka - */ package com.intellij.compiler.impl; import com.intellij.openapi.compiler.CompileContext; @@ -38,6 +33,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +/** + * @author Jeka + * @since Jan 3, 2002 + */ public class CompilerUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.CompilerUtil"); @@ -49,10 +48,6 @@ public class CompilerUtil { return path; } - /** - * must not be called inside ReadAction - * @param files - */ public static void refreshIOFiles(@NotNull final Collection files) { if (!files.isEmpty()) { LocalFileSystem.getInstance().refreshIoFiles(files); @@ -60,16 +55,8 @@ public class CompilerUtil { } public static void refreshIODirectories(@NotNull final Collection files) { - final LocalFileSystem lfs = LocalFileSystem.getInstance(); - final List filesToRefresh = new ArrayList(); - for (File file : files) { - final VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file); - if (virtualFile != null) { - filesToRefresh.add(virtualFile); - } - } - if (!filesToRefresh.isEmpty()) { - RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh); + if (!files.isEmpty()) { + LocalFileSystem.getInstance().refreshIoFiles(files, false, true, null); } } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java index 7faa38d99dcd..c296c6201ed8 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -376,12 +376,7 @@ public abstract class JpsBuildTestCase extends UsefulTestCase { String fullTargetPath = getAbsolutePath(relativeTargetPath); File target = new File(fullTargetPath); try { - if (source.isDirectory()) { - FileUtil.copyDir(source, target); - } - else { - FileUtil.copy(source, target); - } + FileUtil.copyFileOrDir(source, target); } catch (IOException e) { throw new RuntimeException(e); diff --git a/platform/core-api/src/com/intellij/openapi/application/RunResult.java b/platform/core-api/src/com/intellij/openapi/application/RunResult.java index 4d41bbb86889..5494b179b2d0 100644 --- a/platform/core-api/src/com/intellij/openapi/application/RunResult.java +++ b/platform/core-api/src/com/intellij/openapi/application/RunResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,17 +17,14 @@ package com.intellij.openapi.application; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.util.ExceptionUtil; import org.jetbrains.annotations.NotNull; - public class RunResult extends Result { - private BaseActionRunnable myActionRunnable; - private Throwable myThrowable; - protected RunResult() { - } + protected RunResult() { } public RunResult(@NotNull BaseActionRunnable action) { myActionRunnable = action; @@ -38,18 +35,13 @@ public class RunResult extends Result { myActionRunnable.run(this); } catch (ProcessCanceledException e) { - throw e; // this exception may occur from time to time and it shouldn't be catched + throw e; // this exception may occur from time to time and it shouldn't be caught } - catch (Throwable throwable) { - myThrowable = throwable; + catch (Throwable t) { + myThrowable = t; if (!myActionRunnable.isSilentExecution()) { - if (throwable instanceof RuntimeException) throw (RuntimeException)throwable; - if (throwable instanceof Error) { - throw (Error)throwable; - } - else { - throw new RuntimeException(myThrowable); - } + ExceptionUtil.rethrowUnchecked(t); + throw new RuntimeException(myThrowable); } } finally { @@ -65,7 +57,7 @@ public class RunResult extends Result { @NotNull public RunResult logException(Logger logger) { - if (hasException()) { + if (myThrowable != null) { logger.error(myThrowable); } @@ -74,16 +66,11 @@ public class RunResult extends Result { @NotNull public RunResult throwException() throws RuntimeException, Error { - if (hasException()) { - if (myThrowable instanceof RuntimeException) { - throw (RuntimeException)myThrowable; - } - if (myThrowable instanceof Error) { - throw (Error)myThrowable; - } - + if (myThrowable != null) { + ExceptionUtil.rethrowUnchecked(myThrowable); throw new RuntimeException(myThrowable); } + return this; } diff --git a/platform/core-api/src/com/intellij/openapi/application/WriteAction.java b/platform/core-api/src/com/intellij/openapi/application/WriteAction.java index b8c5e16ceaf6..1ce5823fdd0a 100644 --- a/platform/core-api/src/com/intellij/openapi/application/WriteAction.java +++ b/platform/core-api/src/com/intellij/openapi/application/WriteAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,10 @@ import javax.swing.*; public abstract class WriteAction extends BaseActionRunnable { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.application.WriteAction"); + @NotNull @Override + @SuppressWarnings("InstanceofCatchParameter") public RunResult execute() { final RunResult result = new RunResult(this); @@ -35,7 +37,8 @@ public abstract class WriteAction extends BaseActionRunnable { } try { - if (!application.isDispatchThread() && application.isReadAccessAllowed()) { + boolean dispatchThread = application.isDispatchThread(); + if (!dispatchThread && application.isReadAccessAllowed()) { LOG.error("Must not start write action from within read action in the other thread - deadlock is coming"); } Runnable runnable = new Runnable() { @@ -49,7 +52,7 @@ public abstract class WriteAction extends BaseActionRunnable { }); } }; - if (application.isDispatchThread()) { + if (dispatchThread) { runnable.run(); } else if (application.isReadAccessAllowed()) { @@ -68,6 +71,7 @@ public abstract class WriteAction extends BaseActionRunnable { throw new Error(e); } } + return result; } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index be54f20f5ddd..bff5fb027d8d 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -533,6 +533,18 @@ public class VfsUtil extends VfsUtilCore { return children == null ? VirtualFile.EMPTY_ARRAY : children; } + @NotNull + public static List getChildren(@NotNull VirtualFile dir, @NotNull VirtualFileFilter filter) { + List result = null; + for (VirtualFile child : dir.getChildren()) { + if (filter.accept(child)) { + if (result == null) result = ContainerUtil.newSmartList(); + result.add(child); + } + } + return result != null ? result : ContainerUtil.emptyList(); + } + /** * @param url Url for virtual file * @return url for parent directory of virtual file diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java index fb3785d9dd6c..252472d7cd77 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java @@ -623,12 +623,7 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { if (!auxCopy(file, newParent, copyName)) { try { File ioFile = convertToIOFile(file); - if (attributes.isDirectory()) { - FileUtil.copyDir(ioFile, ioTarget); - } - else { - FileUtil.copy(ioFile, ioTarget); - } + FileUtil.copyFileOrDir(ioFile, ioTarget, attributes.isDirectory()); } catch (IOException e) { FileUtil.delete(ioTarget); 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 a30f43994841..76bf17d07fb4 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -540,6 +540,19 @@ public class FileUtil extends FileUtilRt { } } + public static void copyFileOrDir(@NotNull File from, @NotNull File to) throws IOException { + copyFileOrDir(from, to, from.isDirectory()); + } + + public static void copyFileOrDir(@NotNull File from, @NotNull File to, boolean isDir) throws IOException { + if (isDir) { + copyDir(from, to); + } + else { + copy(from, to); + } + } + public static void copyDir(@NotNull File fromDir, @NotNull File toDir) throws IOException { copyDir(fromDir, toDir, true); } @@ -555,13 +568,7 @@ public class FileUtil extends FileUtilRt { public static void copyDirContent(@NotNull File fromDir, @NotNull File toDir) throws IOException { File[] children = ObjectUtils.notNull(fromDir.listFiles(), ArrayUtil.EMPTY_FILE_ARRAY); for (File child : children) { - File target = new File(toDir, child.getName()); - if (child.isFile()) { - copy(child, target); - } - else { - copyDir(child, target, true); - } + copyFileOrDir(child, new File(toDir, child.getName())); } } diff --git a/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java b/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java index 0123556b4e62..14ba949ec5ae 100644 --- a/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java +++ b/plugins/javaFX/common-javaFX-plugin/src/org/jetbrains/plugins/javaFX/packaging/AbstractJavaFxPackager.java @@ -18,7 +18,6 @@ package org.jetbrains.plugins.javaFX.packaging; import com.intellij.execution.CommandLineUtil; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtilRt; @@ -137,11 +136,7 @@ public abstract class AbstractJavaFxPackager { final String fileName = file.getName(); if (ArrayUtilRt.find(generatedItems, fileName) < 0) { final File destination = new File(tempUnzippedArtifactOutput, fileName); - if (file.isFile()) { - FileUtil.copy(file, destination); - } else { - FileUtil.copyDir(file, destination, true); - } + FileUtil.copyFileOrDir(file, destination); } } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java index 4ec2e0b86286..4ae5446085e1 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -337,7 +337,7 @@ public class SvnFileSystemListener extends CommandAdapter implements LocalFileOp // check destination directory if (isUnversioned(vcs, dst.getParentFile())) { try { - copyFileOrDir(src, dst); + FileUtil.copyFileOrDir(src, dst); } catch (IOException e) { throw new SvnBindException(e); @@ -369,7 +369,7 @@ public class SvnFileSystemListener extends CommandAdapter implements LocalFileOp File newFile = new File(dst, relativePath); if (!newFile.exists()) { try { - copyFileOrDir(src, dst); + FileUtil.copyFileOrDir(src, dst); } catch (IOException e) { exc[0] = new SvnBindException(e); @@ -385,14 +385,6 @@ public class SvnFileSystemListener extends CommandAdapter implements LocalFileOp } } - private static void copyFileOrDir(File src, File dst) throws IOException { - if (src.isDirectory()) { - FileUtil.copyDir(src, dst); - } else { - FileUtil.copy(src, dst); - } - } - private static boolean doUsualMove(SvnVcs vcs, File src) { // if src is not under version control, do usual move. Status srcStatus = getFileStatus(vcs, src);