From d62cbff1056b48931445e99d3e30c6d9bf8aed40 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 14 Feb 2017 14:15:06 +0300 Subject: [PATCH] cleanup --- .../util/AbstractProgressIndicatorExBase.java | 107 +++--------------- .../intellij/testFramework/VfsTestUtil.java | 6 +- .../intellij/openapi/vfs/CharsetToolkit.java | 2 +- 3 files changed, 21 insertions(+), 94 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorExBase.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorExBase.java index 2c839151d572..24c8f58efbf5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorExBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorExBase.java @@ -30,55 +30,7 @@ import java.util.List; public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBase implements ProgressIndicatorEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.progress.util.ProgressIndicatorBase"); - private static final IndicatorAction CHECK_CANCELED_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull ProgressIndicatorEx each) { - each.checkCanceled(); - } - }; - private static final IndicatorAction STOP_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.stop(); - } - }; - private static final IndicatorAction START_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.start(); - } - }; - private static final IndicatorAction CANCEL_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.cancel(); - } - }; - private static final IndicatorAction PUSH_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.pushState(); - } - }; - private static final IndicatorAction POP_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.popState(); - } - }; - private static final IndicatorAction STARTNC_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.startNonCancelableSection(); - } - }; - private static final IndicatorAction FINISHNC_ACTION = new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.finishNonCancelableSection(); - } - }; - protected final boolean myReusable; + private final boolean myReusable; private volatile boolean myModalityEntered; private volatile List myStateDelegates; private volatile WeakList myFinished; @@ -97,7 +49,7 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa public void start() { synchronized (this) { super.start(); - delegateRunningChange(START_ACTION); + delegateRunningChange(ProgressIndicator::start); } myWasStarted = true; @@ -127,7 +79,7 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa @Override public void stop() { super.stop(); - delegateRunningChange(STOP_ACTION); + delegateRunningChange(ProgressIndicator::stop); exitModality(); } @@ -147,12 +99,7 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa @Override public void cancel() { super.cancel(); - delegateRunningChange(CANCEL_ACTION); - } - - @Override - public boolean isCanceled() { - return super.isCanceled(); + delegateRunningChange(ProgressIndicator::cancel); } @Override @@ -168,12 +115,7 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa } if (!finished.addIfAbsent(task)) return; - delegateRunningChange(new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.finish(task); - } - }); + delegateRunningChange(each -> each.finish(task)); } @Override @@ -198,71 +140,56 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa public final void checkCanceled() { super.checkCanceled(); - delegate(CHECK_CANCELED_ACTION); + delegate(ProgressIndicator::checkCanceled); } @Override public void setText(final String text) { super.setText(text); - delegateProgressChange(new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.setText(text); - } - }); + delegateProgressChange(each -> each.setText(text)); } @Override public void setText2(final String text) { super.setText2(text); - delegateProgressChange(new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.setText2(text); - } - }); + delegateProgressChange(each -> each.setText2(text)); } @Override public void setFraction(final double fraction) { super.setFraction(fraction); - delegateProgressChange(new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.setFraction(fraction); - } - }); + delegateProgressChange(each -> each.setFraction(fraction)); } @Override public synchronized void pushState() { super.pushState(); - delegateProgressChange(PUSH_ACTION); + delegateProgressChange(ProgressIndicator::pushState); } @Override public synchronized void popState() { super.popState(); - delegateProgressChange(POP_ACTION); + delegateProgressChange(ProgressIndicator::popState); } @Override public void startNonCancelableSection() { super.startNonCancelableSection(); - delegateProgressChange(STARTNC_ACTION); + delegateProgressChange(ProgressIndicator::startNonCancelableSection); } @Override public void finishNonCancelableSection() { super.finishNonCancelableSection(); - delegateProgressChange(FINISHNC_ACTION); + delegateProgressChange(ProgressIndicator::finishNonCancelableSection); } @Override @@ -274,12 +201,7 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa public void setIndeterminate(final boolean indeterminate) { super.setIndeterminate(indeterminate); - delegateProgressChange(new IndicatorAction() { - @Override - public void execute(@NotNull final ProgressIndicatorEx each) { - each.setIndeterminate(indeterminate); - } - }); + delegateProgressChange(each -> each.setIndeterminate(indeterminate)); } @Override @@ -342,6 +264,7 @@ public class AbstractProgressIndicatorExBase extends AbstractProgressIndicatorBa return myWasStarted; } + @FunctionalInterface protected interface IndicatorAction { void execute(@NotNull ProgressIndicatorEx each); } diff --git a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java index 4bd39aadd7b3..0b8a698bc92b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java @@ -46,18 +46,22 @@ public class VfsTestUtil { private VfsTestUtil() { } + @NotNull public static VirtualFile createFile(@NotNull VirtualFile root, @NotNull String relativePath) { return createFile(root, relativePath, ""); } + @NotNull public static VirtualFile createFile(@NotNull VirtualFile root, @NotNull String relativePath, @NotNull String text) { return createFileOrDir(root, relativePath, text, false); } + @NotNull public static VirtualFile createDir(@NotNull VirtualFile root, @NotNull String relativePath) { return createFileOrDir(root, relativePath, "", true); } + @NotNull private static VirtualFile createFileOrDir(VirtualFile root, String relativePath, String text, boolean dir) { try { return WriteAction.compute(() -> { @@ -107,7 +111,7 @@ public class VfsTestUtil { }); } - public static void overwriteTestData(String filePath, String actual) { + public static void overwriteTestData(@NotNull String filePath, @NotNull String actual) { try { FileUtil.writeToFile(new File(filePath), actual); } diff --git a/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java b/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java index 0797eb94bef5..e0bd880c61c2 100644 --- a/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java +++ b/platform/util/src/com/intellij/openapi/vfs/CharsetToolkit.java @@ -88,7 +88,7 @@ public class CharsetToolkit { private final byte[] buffer; @NotNull private final Charset defaultCharset; - private boolean enforce8Bit = false; + private boolean enforce8Bit; public static final byte[] UTF8_BOM = {0xffffffef, 0xffffffbb, 0xffffffbf}; public static final byte[] UTF16LE_BOM = {-1, -2, };