This commit is contained in:
Alexey Kudravtsev
2017-02-14 14:15:06 +03:00
parent 53dec997ed
commit d62cbff105
3 changed files with 21 additions and 94 deletions
@@ -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<ProgressIndicatorEx> myStateDelegates;
private volatile WeakList<TaskInfo> 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);
}
@@ -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);
}
@@ -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, };