Merge remote-tracking branch 'origin/master'

This commit is contained in:
Yann Cébron
2014-09-18 12:17:26 +02:00
45 changed files with 1096 additions and 728 deletions
@@ -35,7 +35,7 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.project.DumbModeAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
@@ -244,7 +244,7 @@ public class CompilerTask extends Task.Backgroundable {
if (!(indicator instanceof ProgressIndicatorEx)) {
return;
}
((ProgressIndicatorEx)indicator).addStateDelegate(new ProgressIndicatorBase() {
((ProgressIndicatorEx)indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -25,6 +25,7 @@ import com.intellij.notification.NotificationType;
import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.progress.util.ProgressWindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
@@ -54,12 +55,14 @@ public class HotSwapProgressImpl extends HotSwapProgress{
public void processSentToBackground() {
}
}, null, null, true) {
}, null, null, true);
myProgressWindow.addStateDelegate(new AbstractProgressIndicatorExBase(){
@Override
public void cancel() {
HotSwapProgressImpl.this.cancel();
super.cancel();
HotSwapProgressImpl.this.cancel();
}
};
});
}
public void finished() {
@@ -111,7 +111,12 @@ public class CompilingEvaluator implements ExpressionEvaluator {
try {
// invoke base evaluator on call code
final Project project = myPsiContext.getProject();
final Project project = ApplicationManager.getApplication().runReadAction(new Computable<Project>() {
@Override
public Project compute() {
return myPsiContext.getProject();
}
});
ExpressionEvaluator evaluator =
DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable<ExpressionEvaluator>() {
@Override
@@ -156,7 +161,7 @@ public class CompilingEvaluator implements ExpressionEvaluator {
DebugProcess process,
ThreadReference threadReference,
ClassLoaderReference classLoader)
throws EvaluateException, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
throws EvaluateException, InvalidTypeException, ClassNotLoadedException {
VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl)process.getVirtualMachineProxy();
for (OutputFileObject cls : classes) {
@@ -259,11 +264,17 @@ public class CompilingEvaluator implements ExpressionEvaluator {
///////////////// Compiler stuff
@NotNull
private Collection<OutputFileObject> compile() throws EvaluateException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
MemoryFileManager manager = new MemoryFileManager(compiler);
DiagnosticCollector<JavaFileObject> diagnostic = new DiagnosticCollector<JavaFileObject>();
Module module = ModuleUtilCore.findModuleForPsiElement(myPsiContext);
Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
@Override
public Module compute() {
return ModuleUtilCore.findModuleForPsiElement(myPsiContext);
}
});
PathsList cp = null;
if (module != null) {
cp = ModuleRootManager.getInstance(module).orderEntries().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList();
@@ -28,9 +28,10 @@ import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.concurrency.SwingWorker;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.java.JavaResourceRootType;
import org.jetbrains.jps.model.java.JavaSourceRootType;
@@ -72,14 +73,14 @@ public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
return contentEntries;
}
private static void addSourceRoots(final Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) {
private static void addSourceRoots(@NotNull Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) {
final HashMap<ContentEntry, Collection<JavaModuleSourceRoot>> entryToRootMap = new HashMap<ContentEntry, Collection<JavaModuleSourceRoot>>();
final Map<File, ContentEntry> fileToEntryMap = new HashMap<File, ContentEntry>();
for (final ContentEntry contentEntry : contentEntries) {
final VirtualFile file = contentEntry.getFile();
if (file != null) {
entryToRootMap.put(contentEntry, null);
fileToEntryMap.put(VfsUtil.virtualToIoFile(file), contentEntry);
fileToEntryMap.put(VfsUtilCore.virtualToIoFile(file), contentEntry);
}
}
@@ -113,7 +114,7 @@ public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
for (final JavaModuleSourceRoot suggestedRoot : suggestedRoots) {
final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.getDirectory());
final VirtualFile fileContent = contentEntry.getFile();
if (sourceRoot != null && fileContent != null && VfsUtil.isAncestor(fileContent, sourceRoot, false)) {
if (sourceRoot != null && fileContent != null && VfsUtilCore.isAncestor(fileContent, sourceRoot, false)) {
contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getPackagePrefix());
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.highlighting.HighlightUsagesHandler;
import com.intellij.ide.DataManager;
import com.intellij.injected.editor.EditorWindow;
@@ -74,10 +75,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
final FileEditorManager instance = FileEditorManager.getInstance(myProject);
if (file.getFileType().isBinary()) return null;
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
Editor editor = instance.openTextEditor(new OpenFileDescriptor(myProject, file, 0), false);
((EditorImpl)editor).setCaretActive();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
DaemonCodeAnalyzer.getInstance(getProject()).restart();
return editor;
}
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.daemon.impl;
import com.intellij.openapi.progress.StandardProgressIndicator;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorBase;
import com.intellij.openapi.util.TraceableDisposable;
import org.jetbrains.annotations.NotNull;
@@ -24,7 +25,7 @@ import org.jetbrains.annotations.TestOnly;
/**
* @author cdr
*/
public class DaemonProgressIndicator extends AbstractProgressIndicatorBase {
public class DaemonProgressIndicator extends AbstractProgressIndicatorBase implements StandardProgressIndicator {
private static boolean debug;
private final TraceableDisposable myTraceableDisposable = new TraceableDisposable(debug ? new Throwable() : null);
@@ -44,11 +45,21 @@ public class DaemonProgressIndicator extends AbstractProgressIndicatorBase {
}
@Override
public void cancel() {
public final void cancel() {
myTraceableDisposable.kill("Daemon Progress Canceled");
super.cancel();
}
@Override
public final boolean isCanceled() {
return super.isCanceled();
}
@Override
public final void checkCanceled() {
super.checkCanceled();
}
public void cancel(@NotNull Throwable cause) {
myTraceableDisposable.kill("Daemon Progress Canceled because of "+cause);
super.cancel();
@@ -19,7 +19,7 @@ package com.intellij.openapi.progress;
import com.intellij.openapi.application.ModalityState;
import org.jetbrains.annotations.NotNull;
public class EmptyProgressIndicator implements ProgressIndicator {
public class EmptyProgressIndicator implements StandardProgressIndicator {
private volatile boolean myIsRunning = false;
private volatile boolean myIsCanceled = false;
@@ -40,16 +40,23 @@ public class EmptyProgressIndicator implements ProgressIndicator {
}
@Override
public void cancel() {
public final void cancel() {
myIsCanceled = true;
ProgressManager.canceled(this);
}
@Override
public boolean isCanceled() {
public final boolean isCanceled() {
return myIsCanceled;
}
@Override
public final void checkCanceled() {
if (myIsCanceled) {
throw new ProcessCanceledException();
}
}
@Override
public void setText(String text) {
}
@@ -117,13 +124,6 @@ public class EmptyProgressIndicator implements ProgressIndicator {
public void setIndeterminate(boolean indeterminate) {
}
@Override
public void checkCanceled() {
if (myIsCanceled) {
throw new ProcessCanceledException();
}
}
@Override
public boolean isPopupWasShown() {
return false;
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@@ -199,6 +200,19 @@ public abstract class ProgressManager extends ProgressIndicatorProvider {
}
}
private static final Collection<ProgressIndicator> nonStandardIndicators = new ConcurrentHashSet<ProgressIndicator>();
protected static void callCheckCancelForNonStandardIndicators() {
for (ProgressIndicator indicator : nonStandardIndicators) {
try {
indicator.checkCanceled();
}
catch (ProcessCanceledException e) {
indicator.cancel();
}
}
}
public void executeProcessUnderProgress(@NotNull Runnable process,
@Nullable("null means reuse current progress") ProgressIndicator progress)
throws ProcessCanceledException {
@@ -221,6 +235,7 @@ public abstract class ProgressManager extends ProgressIndicatorProvider {
private static void registerIndicatorAndRun(@NotNull ProgressIndicator progress, @NotNull Thread currentThread, @NotNull Runnable process) {
Set<Thread> underIndicator;
boolean alreadyUnder;
boolean addedToPerverse;
synchronized (threadsUnderIndicator) {
underIndicator = threadsUnderIndicator.get(progress);
if (underIndicator == null) {
@@ -228,6 +243,7 @@ public abstract class ProgressManager extends ProgressIndicatorProvider {
threadsUnderIndicator.put(progress, underIndicator);
}
alreadyUnder = !underIndicator.add(currentThread);
addedToPerverse = !(progress instanceof StandardProgressIndicator) && nonStandardIndicators.add(progress);
}
try {
@@ -245,6 +261,9 @@ public abstract class ProgressManager extends ProgressIndicatorProvider {
threadsUnderIndicator.remove(progress);
}
threadsUnderCanceledIndicator.remove(currentThread);
if (addedToPerverse) {
nonStandardIndicators.remove(progress);
}
}
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.progress;
/**
* Marker interface which means this indicator cancellation behaves in a standard way:
* - checkCanceled() checks for isCanceled() and throws PCE if returned true
* - cancel() sets the corresponding flag
* - isCanceled() is true after cancel() call
* - all methods above are final
*/
public interface StandardProgressIndicator extends ProgressIndicator {
}
@@ -23,20 +23,40 @@
package com.intellij.openapi.progress.util;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.StandardProgressIndicator;
import com.intellij.openapi.progress.WrappedProgressIndicator;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ProgressWrapper extends AbstractProgressIndicatorBase implements WrappedProgressIndicator {
public class ProgressWrapper extends AbstractProgressIndicatorBase implements WrappedProgressIndicator, StandardProgressIndicator {
private final ProgressIndicator myOriginal;
private final boolean myCheckCanceledForMe;
protected ProgressWrapper(@NotNull ProgressIndicator original) {
this(original, false);
}
protected ProgressWrapper(@NotNull ProgressIndicator original, boolean checkCanceledForMe) {
myOriginal = original;
myCheckCanceledForMe = checkCanceledForMe;
}
@Override
public final void cancel() {
super.cancel();
}
@Override
public final boolean isCanceled() {
return myOriginal.isCanceled() || myCheckCanceledForMe && super.isCanceled();
}
@Override
public boolean isCanceled() {
return myOriginal.isCanceled();
public final void checkCanceled() {
super.checkCanceled();
}
@Override
@@ -45,11 +65,12 @@ public class ProgressWrapper extends AbstractProgressIndicatorBase implements Wr
return myOriginal;
}
@Nullable
@Contract(value = "null -> null; !null -> !null", pure = true)
public static ProgressWrapper wrap(@Nullable ProgressIndicator indicator) {
return indicator == null || indicator instanceof ProgressWrapper ? (ProgressWrapper)indicator : new ProgressWrapper(indicator);
}
@Contract(value = "null -> null; !null -> !null", pure = true)
public static ProgressIndicator unwrap(ProgressIndicator indicator) {
return indicator instanceof ProgressWrapper ?
((ProgressWrapper)indicator).getOriginalProgressIndicator() : indicator;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -64,6 +64,7 @@ class EmptyFileManager implements FileManager {
@Override
public void cleanupForNextTest() {
myVFileToViewProviderMap.clear();
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -67,7 +67,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
import com.intellij.openapi.roots.libraries.Library;
@@ -441,7 +441,7 @@ public class ExternalSystemUtil {
if(project.isDisposed()) return;
if (indicator instanceof ProgressIndicatorEx) {
((ProgressIndicatorEx)indicator).addStateDelegate(new ProgressIndicatorBase() {
((ProgressIndicatorEx)indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
super.cancel();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -18,10 +18,12 @@ package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.UserDataHolder;
import org.jetbrains.annotations.NotNull;
public interface ModuleConfigurationState extends UserDataHolder {
ModulesProvider getModulesProvider();
FacetsProvider getFacetsProvider();
ModifiableRootModel getRootModel();
@NotNull
Project getProject();
}
@@ -273,11 +273,6 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
}
@Override
public void cancel() {
super.cancel();
}
private boolean isOutdated() {
return CompletionServiceImpl.getCompletionPhase().indicator != this;
}
@@ -56,6 +56,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.*;
@@ -65,8 +66,8 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
private static final Logger LOG = Logger.getInstance("#" + ShowImplementationsAction.class.getName());
private WeakReference<JBPopup> myPopupRef;
private WeakReference<BackgroundUpdaterTask> myTaskRef;
private Reference<JBPopup> myPopupRef;
private Reference<ImplementationsUpdaterTask> myTaskRef;
public ShowImplementationsAction() {
setEnabledInModalContext(true);
@@ -284,7 +285,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
@Override
public boolean process(JBPopup popup) {
usageView.set(component.showInUsageView());
myTaskRef = new WeakReference<BackgroundUpdaterTask>(null);
myTaskRef = null;
popup.cancel();
return false;
}
@@ -292,10 +293,8 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
.setCancelCallback(new Computable<Boolean>() {
@Override
public Boolean compute() {
final BackgroundUpdaterTask task = SoftReference.dereference(myTaskRef);
if (task != null) {
task.setCanceled();
}
ImplementationsUpdaterTask task = SoftReference.dereference(myTaskRef);
cancelTask(task);
return Boolean.TRUE;
}
})
@@ -310,27 +309,31 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
}
}
private static boolean cancelTask(ImplementationsUpdaterTask task) {
if (task != null) {
ProgressIndicator indicator = task.myIndicator;
if (indicator != null) {
indicator.cancel();
}
return task.setCanceled();
}
return false;
}
private void updateInBackground(Editor editor,
@Nullable PsiElement element,
ImplementationViewComponent component,
String title,
AbstractPopup popup, Ref<UsageView> usageView) {
final BackgroundUpdaterTask updaterTask = SoftReference.dereference(myTaskRef);
if (updaterTask != null) {
updaterTask.setCanceled();
}
final ImplementationsUpdaterTask updaterTask = SoftReference.dereference(myTaskRef);
cancelTask(updaterTask);
if (element == null) return; //already found
final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf());
task.init(popup, component, usageView);
myTaskRef = new WeakReference<BackgroundUpdaterTask>(task);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task) {
@Override
public boolean isCanceled() {
return super.isCanceled() || task.isCanceled();
}
});
myTaskRef = new WeakReference<ImplementationsUpdaterTask>(task);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}
protected boolean isIncludeAlwaysSelf() {
@@ -402,6 +405,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
private final PsiElement myElement;
private final boolean myIncludeSelf;
private PsiElement[] myElements;
private volatile ProgressIndicator myIndicator;
public ImplementationsUpdaterTask(final PsiElement element, final Editor editor, final String caption, boolean includeSelf) {
super(element.getProject(), ImplementationSearcher.SEARCHING_FOR_IMPLEMENTATIONS);
@@ -434,6 +438,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
myIndicator = indicator;
super.run(indicator);
final ImplementationSearcher.BackgroundableImplementationSearcher implementationSearcher =
new ImplementationSearcher.BackgroundableImplementationSearcher() {
@@ -465,7 +470,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
@Override
public void onSuccess() {
if (!setCanceled()) {
if (!cancelTask(this)) {
myComponent.update(myElements, myComponent.getIndex());
}
super.onSuccess();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -21,13 +21,9 @@ import com.intellij.ide.IdeBundle;
import com.intellij.ide.OccurenceNavigator;
import com.intellij.ide.OccurenceNavigatorSupport;
import com.intellij.ide.PsiCopyPasteManager;
import com.intellij.ide.dnd.DnDAction;
import com.intellij.ide.dnd.DnDDragStartBean;
import com.intellij.ide.dnd.DnDManager;
import com.intellij.ide.dnd.DnDSource;
import com.intellij.ide.dnd.*;
import com.intellij.ide.dnd.aware.DnDAwareTree;
import com.intellij.ide.projectView.impl.ProjectViewTree;
import com.intellij.ide.dnd.TransferableWrapper;
import com.intellij.ide.util.scopeChooser.EditScopesDialog;
import com.intellij.ide.util.treeView.NodeDescriptor;
import com.intellij.openapi.actionSystem.*;
@@ -35,7 +31,6 @@ import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
@@ -82,7 +77,7 @@ public abstract class HierarchyBrowserBaseEx extends HierarchyBrowserBase implem
private boolean myCachedIsValidBase = false;
private final HashMap<String, OccurenceNavigator> myOccurrenceNavigators = new HashMap<String, OccurenceNavigator>();
private final Map<String, OccurenceNavigator> myOccurrenceNavigators = new HashMap<String, OccurenceNavigator>();
private static final OccurenceNavigator EMPTY_NAVIGATOR = new OccurenceNavigator() {
@Override
@@ -745,11 +740,4 @@ public abstract class HierarchyBrowserBaseEx extends HierarchyBrowserBase implem
}
}
}
// will throw PCE during update when canceled
public void setProgressIndicator(@NotNull ProgressIndicator indicator) {
for (HierarchyTreeBuilder builder : myBuilders.values()) {
builder.setProgressIndicator(indicator);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -84,28 +84,10 @@ public class HierarchyTreeBuilder extends AbstractTreeBuilder {
}
private MyStatusBarProgress myProgress;
@Override
@NotNull
protected ProgressIndicator createProgressIndicator() {
return myProgress = new MyStatusBarProgress();
}
public void setProgressIndicator(@NotNull ProgressIndicator indicator) {
myProgress.setSecondaryIndicator(indicator);
}
private static class MyStatusBarProgress extends StatusBarProgress {
private ProgressIndicator mySecondaryIndicator;
public void setSecondaryIndicator(ProgressIndicator indicator) {
mySecondaryIndicator = indicator;
}
@Override
public boolean isCanceled() {
return super.isCanceled() || mySecondaryIndicator != null && mySecondaryIndicator.isCanceled();
}
return new StatusBarProgress();
}
private final class MyPsiTreeChangeListener extends PsiTreeChangeAdapter {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -78,7 +78,6 @@ public class ScopeEditorPanel {
private JLabel myCaretPositionLabel;
private int myCaretPosition = 0;
private boolean myTextChanged = false;
private JPanel myMatchingCountPanel;
private JPanel myPositionPanel;
private JLabel myRecursivelyIncluded;
@@ -187,7 +186,7 @@ public class ScopeEditorPanel {
private void onTextChange() {
if (!myIsInUpdate) {
myUpdateAlarm.cancelAllRequests();
myTextChanged = true;
cancelCurrentProgress();
final String text = myPatternField.getText();
myCurrentScope = new InvalidPackageSet(text);
try {
@@ -602,12 +601,12 @@ public class ScopeEditorPanel {
ProgressManager.getInstance().runProcess(updateModel, progress);
}
protected PanelProgressIndicator createProgressIndicator(final boolean requestFocus) {
private PanelProgressIndicator createProgressIndicator(final boolean requestFocus) {
return new MyPanelProgressIndicator(requestFocus);
}
public void cancelCurrentProgress(){
if (myCurrentProgress != null && myCurrentProgress.isRunning()){
if (myCurrentProgress != null){
myCurrentProgress.cancel();
}
}
@@ -748,12 +747,6 @@ public class ScopeEditorPanel {
}
});
myRequestFocus = requestFocus;
myTextChanged = false;
}
@Override
public boolean isCanceled() {
return super.isCanceled() || myTextChanged;
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -50,6 +50,7 @@ public class ModuleConfigurationStateImpl extends UserDataHolderBase implements
return null;
}
@NotNull
@Override
public Project getProject() {
return myProject;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -24,6 +24,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.navigation.History;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -33,14 +34,14 @@ import javax.swing.*;
* Time: 7:24:37 PM
*/
public abstract class ModuleElementsEditor implements ModuleConfigurationEditor {
protected final Project myProject;
@NotNull protected final Project myProject;
protected JComponent myComponent;
private final CompositeDisposable myDisposables = new CompositeDisposable();
protected History myHistory;
private final ModuleConfigurationState myState;
protected ModuleElementsEditor(ModuleConfigurationState state) {
protected ModuleElementsEditor(@NotNull ModuleConfigurationState state) {
myProject = state.getProject();
myState = state;
}
@@ -58,6 +59,7 @@ public abstract class ModuleElementsEditor implements ModuleConfigurationEditor
return myState.getRootModel();
}
@NotNull
protected ModuleConfigurationState getState() {
return myState;
}
@@ -22,7 +22,6 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.PsiElement;
@@ -124,14 +123,6 @@ public class UsageContextCallHierarchyPanel extends UsageContextPanelBase {
if (browser instanceof HierarchyBrowserBaseEx) {
HierarchyBrowserBaseEx browserEx = (HierarchyBrowserBaseEx)browser;
browserEx.changeView(CallHierarchyBrowserBase.CALLER_TYPE);
final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
Disposer.register(browserEx, new Disposable() {
@Override
public void dispose() {
indicator.cancel();
}
});
browserEx.setProgressIndicator(indicator);
}
return browser;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -18,6 +18,7 @@ package com.intellij.util.download.impl;
import com.google.common.base.Throwables;
import com.google.common.util.concurrent.AtomicDouble;
import com.intellij.concurrency.SensitiveProgressWrapper;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.Result;
@@ -30,7 +31,6 @@ import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
@@ -71,13 +71,13 @@ public class FileDownloaderImpl implements FileDownloader {
@NonNls private static final String LIB_SCHEMA = "lib://";
private final List<? extends DownloadableFileDescription> myFileDescriptions;
private JComponent myParentComponent;
private @Nullable Project myProject;
private final JComponent myParentComponent;
@Nullable private final Project myProject;
private String myDirectoryForDownloadedFilesPath;
private final String myDialogTitle;
public FileDownloaderImpl(@NotNull List<? extends DownloadableFileDescription> fileDescriptions,
final @Nullable Project project,
@Nullable final Project project,
@Nullable JComponent parentComponent,
@NotNull String presentableDownloadName) {
myProject = project;
@@ -305,8 +305,8 @@ public class FileDownloaderImpl implements FileDownloader {
}
@NotNull
private static File downloadFile(final @NotNull DownloadableFileDescription fileDescription, final @NotNull File existingFile,
final @NotNull ProgressIndicator indicator) throws IOException {
private static File downloadFile(@NotNull final DownloadableFileDescription fileDescription, @NotNull final File existingFile,
@NotNull final ProgressIndicator indicator) throws IOException {
final String presentableUrl = fileDescription.getPresentableDownloadUrl();
indicator.setText2(IdeBundle.message("progress.connecting.to.download.file.text", presentableUrl));
indicator.setIndeterminate(true);
@@ -380,7 +380,7 @@ public class FileDownloaderImpl implements FileDownloader {
private final int myTasksCount;
private final AtomicDouble myTotalFraction;
private final Object myLock = new Object();
private LinkedHashMap<SubTaskProgressIndicator, String> myText2Stack = new LinkedHashMap<SubTaskProgressIndicator, String>();
private final LinkedHashMap<SubTaskProgressIndicator, String> myText2Stack = new LinkedHashMap<SubTaskProgressIndicator, String>();
private ConcurrentTasksProgressManager(ProgressIndicator parent, int tasksCount) {
myParent = parent;
@@ -417,11 +417,12 @@ public class FileDownloaderImpl implements FileDownloader {
}
}
private static class SubTaskProgressIndicator extends AbstractProgressIndicatorBase {
private static class SubTaskProgressIndicator extends SensitiveProgressWrapper {
private final AtomicDouble myFraction;
private final ConcurrentTasksProgressManager myProgressManager;
private SubTaskProgressIndicator(ConcurrentTasksProgressManager progressManager) {
super(progressManager.myParent);
myProgressManager = progressManager;
myFraction = new AtomicDouble();
}
@@ -452,10 +453,5 @@ public class FileDownloaderImpl implements FileDownloader {
setFraction(1);
myProgressManager.setText2(this, null);
}
@Override
public boolean isCanceled() {
return super.isCanceled() || myProgressManager.myParent.isCanceled();
}
}
}
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.NotNull;
* @author Eugene Zhuravlev
* Date: Jul 12, 2007
*/
public class DelegatingProgressIndicator implements WrappedProgressIndicator {
public class DelegatingProgressIndicator implements WrappedProgressIndicator, StandardProgressIndicator {
private final ProgressIndicator myIndicator;
public DelegatingProgressIndicator(@NotNull ProgressIndicator indicator) {
@@ -51,12 +51,12 @@ public class DelegatingProgressIndicator implements WrappedProgressIndicator {
}
@Override
public void cancel() {
public final void cancel() {
myIndicator.cancel();
}
@Override
public boolean isCanceled() {
public final boolean isCanceled() {
return myIndicator.isCanceled();
}
@@ -137,7 +137,7 @@ public class DelegatingProgressIndicator implements WrappedProgressIndicator {
}
@Override
public void checkCanceled() throws ProcessCanceledException {
public final void checkCanceled() throws ProcessCanceledException {
myIndicator.checkCanceled();
}
@@ -18,6 +18,7 @@ package com.intellij.ide.util.treeView;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.UiActivity;
import com.intellij.ide.UiActivityMonitor;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -238,6 +239,14 @@ public class AbstractTreeUi {
setUpdater(getBuilder().createUpdater());
myProgress = getBuilder().createProgressIndicator();
Disposer.register(getBuilder(), getUpdater());
if (myProgress != null) {
Disposer.register(getBuilder(), new Disposable() {
@Override
public void dispose() {
myProgress.cancel();
}
});
}
final UiNotifyConnector uiNotify = new UiNotifyConnector(tree, new Activatable() {
@Override
@@ -5111,5 +5120,4 @@ public class AbstractTreeUi {
}
});
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -24,11 +24,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class SensitiveProgressWrapper extends ProgressWrapper {
public SensitiveProgressWrapper(@NotNull ProgressIndicator indicator) {
super(indicator);
super(indicator, true);
}
@Override
public boolean isCanceled() {
return super.isCanceled() || getOriginalProgressIndicator().isCanceled();
}
}
@@ -21,9 +21,10 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.ide.plugins.PluginNode;
import com.intellij.openapi.options.OptionsBundle;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.updateSettings.impl.PluginDownloader;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.JBColor;
import com.intellij.ui.border.CustomLineBorder;
@@ -121,7 +122,7 @@ public class CustomizeFeaturedPluginsStepPanel extends AbstractCustomizeWizardSt
wrapperLayout.show(buttonWrapper, "button");
final ProgressIndicatorBase indicator = new ProgressIndicatorBase(true) {
final ProgressIndicatorEx indicator = new AbstractProgressIndicatorExBase(true) {
@Override
public void start() {
@@ -2789,6 +2789,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
if (extensions != null && !extensions.isEmpty()) {
for (LineExtensionInfo info : extensions) {
final String text = info.getText();
additionalText += text;
drawStringWithSoftWraps(g, text, 0, text.length(), position, clip,
info.getEffectColor() == null ? effectColor : info.getEffectColor(),
info.getEffectType() == null ? effectType : info.getEffectType(),
@@ -0,0 +1,154 @@
/*
* Copyright 2000-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.progress.impl;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.progress.NonCancelableSection;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.StandardProgressIndicator;
import org.jetbrains.annotations.NotNull;
class NonCancelableIndicator implements NonCancelableSection, StandardProgressIndicator {
protected final ProgressIndicator myOld;
NonCancelableIndicator() {
myOld = ProgressManager.getInstance().getProgressIndicator();
}
@Override
public void done() {
ProgressIndicator currentIndicator = ProgressManager.getInstance().getProgressIndicator();
if (currentIndicator != this) {
throw new AssertionError("Trying do .done() NonCancelableSection, which is already done");
}
}
@Override
public final void checkCanceled() {
}
@Override
public void start() {
}
@Override
public void stop() {
}
@Override
public boolean isRunning() {
return true;
}
@Override
public final void cancel() {
}
@Override
public final boolean isCanceled() {
return false;
}
@Override
public void setText(String text) {
}
@Override
public String getText() {
return null;
}
@Override
public void setText2(String text) {
}
@Override
public String getText2() {
return null;
}
@Override
public double getFraction() {
return 0;
}
@Override
public void setFraction(double fraction) {
}
@Override
public void pushState() {
}
@Override
public void popState() {
}
@Override
public void startNonCancelableSection() {
}
@Override
public void finishNonCancelableSection() {
}
@Override
public boolean isModal() {
return false;
}
@NotNull
@Override
public ModalityState getModalityState() {
return ModalityState.NON_MODAL;
}
@Override
public void setModalityProgress(ProgressIndicator modalityProgress) {
}
@Override
public boolean isIndeterminate() {
return false;
}
@Override
public void setIndeterminate(boolean indeterminate) {
}
@Override
public boolean isPopupWasShown() {
return false;
}
@Override
public boolean isShowing() {
return false;
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.progress.impl;
import com.intellij.concurrency.JobScheduler;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
@@ -40,9 +41,11 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class ProgressManagerImpl extends ProgressManager {
public class ProgressManagerImpl extends ProgressManager implements Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.progress.impl.ProgressManagerImpl");
public static final int CHECK_CANCELED_DELAY_MILLIS = 10;
private final AtomicInteger myCurrentUnsafeProgressCount = new AtomicInteger(0);
@@ -50,6 +53,22 @@ public class ProgressManagerImpl extends ProgressManager {
private static volatile int ourLockedCheckCounter = 0;
private static final boolean DISABLED = "disabled".equals(System.getProperty("idea.ProcessCanceledException"));
private final ScheduledFuture<?> myCheckCancelledFuture;
public ProgressManagerImpl() {
myCheckCancelledFuture = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
callCheckCancelForNonStandardIndicators();
}
}, 0, CHECK_CANCELED_DELAY_MILLIS, TimeUnit.MILLISECONDS);
}
@Override
public void dispose() {
myCheckCancelledFuture.cancel(true);
}
@Override
protected void doCheckCanceled() throws ProcessCanceledException {
@@ -76,39 +95,27 @@ public class ProgressManagerImpl extends ProgressManager {
}
}
private static class NonCancelableIndicator extends EmptyProgressIndicator implements NonCancelableSection {
private final ProgressIndicator myOld;
private NonCancelableIndicator() {
myOld = myThreadIndicator.get();
}
@Override
public void done() {
ProgressIndicator currentIndicator = myThreadIndicator.get();
if (currentIndicator != this) {
throw new AssertionError("Trying do .done() NonCancelableSection, which is already done");
}
myThreadIndicator.set(myOld);
}
@Override
public void checkCanceled() {
}
}
@NotNull
@Override
public final NonCancelableSection startNonCancelableSection() {
NonCancelableIndicator nonCancelor = new NonCancelableIndicator();
NonCancelableIndicator nonCancelor = createNonCancelableIndicator();
myThreadIndicator.set(nonCancelor);
return nonCancelor;
}
@Override
public void executeNonCancelableSection(@NotNull Runnable runnable) {
executeProcessUnderProgress(runnable, new NonCancelableIndicator());
executeProcessUnderProgress(runnable, createNonCancelableIndicator());
}
@NotNull
private static NonCancelableIndicator createNonCancelableIndicator() {
return new NonCancelableIndicator(){
@Override
public void done() {
myThreadIndicator.set(myOld);
}
};
}
@Override
@@ -116,7 +123,7 @@ public class ProgressManagerImpl extends ProgressManager {
ProgressIndicator progressIndicator = getProgressIndicator();
if (progressIndicator != null) {
if (progressIndicator instanceof SmoothProgressAdapter && cancelButtonText != null) {
ProgressIndicator original = ((SmoothProgressAdapter)progressIndicator).getOriginal();
ProgressIndicator original = ((SmoothProgressAdapter)progressIndicator).getOriginalProgressIndicator();
if (original instanceof ProgressWindow) {
((ProgressWindow)original).setCancelButtonText(cancelButtonText);
}
@@ -0,0 +1,350 @@
/*
* Copyright 2000-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.progress.util;
import com.intellij.openapi.application.impl.LaterInvocator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.TaskInfo;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.WeakList;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
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 volatile boolean myModalityEntered;
private volatile List<ProgressIndicatorEx> myStateDelegates;
private volatile WeakList<TaskInfo> myFinished;
private volatile boolean myWasStarted;
private TaskInfo myOwnerTask;
public AbstractProgressIndicatorExBase(boolean reusable) {
myReusable = reusable;
}
public AbstractProgressIndicatorExBase() {
this(false);
}
@Override
public void start() {
synchronized (this) {
super.start();
delegateRunningChange(START_ACTION);
}
myWasStarted = true;
enterModality();
}
protected final void enterModality() {
if (myModalityProgress == this) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
doEnterModality();
}
});
}
}
private void doEnterModality() {
if (!myModalityEntered) {
LaterInvocator.enterModal(this);
myModalityEntered = true;
}
}
@Override
public void stop() {
super.stop();
delegateRunningChange(STOP_ACTION);
exitModality();
}
protected final void exitModality() {
if (myModalityProgress == this) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
doExitModality();
}
});
}
}
private void doExitModality() {
if (myModalityEntered) {
LaterInvocator.leaveModal(this);
myModalityEntered = false;
}
}
@Override
public void cancel() {
super.cancel();
delegateRunningChange(CANCEL_ACTION);
}
@Override
public boolean isCanceled() {
return super.isCanceled();
}
@Override
public void finish(@NotNull final TaskInfo task) {
WeakList<TaskInfo> finished = myFinished;
if (finished == null) {
synchronized (this) {
finished = myFinished;
if (finished == null) {
myFinished = finished = new WeakList<TaskInfo>();
}
}
}
if (!finished.addIfAbsent(task)) return;
delegateRunningChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx each) {
each.finish(task);
}
});
}
@Override
public boolean isFinished(@NotNull final TaskInfo task) {
List<TaskInfo> list = myFinished;
return list != null && list.contains(task);
}
protected void setOwnerTask(TaskInfo owner) {
myOwnerTask = owner;
}
@Override
public void processFinish() {
if (myOwnerTask != null) {
finish(myOwnerTask);
myOwnerTask = null;
}
}
@Override
public final void checkCanceled() {
super.checkCanceled();
delegate(CHECK_CANCELED_ACTION);
}
@Override
public void setText(final String text) {
super.setText(text);
delegateProgressChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx 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);
}
});
}
@Override
public void setFraction(final double fraction) {
super.setFraction(fraction);
delegateProgressChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx each) {
each.setFraction(fraction);
}
});
}
@Override
public synchronized void pushState() {
super.pushState();
delegateProgressChange(PUSH_ACTION);
}
@Override
public synchronized void popState() {
super.popState();
delegateProgressChange(POP_ACTION);
}
@Override
public void startNonCancelableSection() {
super.startNonCancelableSection();
delegateProgressChange(STARTNC_ACTION);
}
@Override
public void finishNonCancelableSection() {
super.finishNonCancelableSection();
delegateProgressChange(FINISHNC_ACTION);
}
@Override
protected boolean isReuseable() {
return myReusable;
}
@Override
public void setIndeterminate(final boolean indeterminate) {
super.setIndeterminate(indeterminate);
delegateProgressChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx each) {
each.setIndeterminate(indeterminate);
}
});
}
@Override
public final void addStateDelegate(@NotNull ProgressIndicatorEx delegate) {
delegate.initStateFrom(this);
synchronized (this) {
List<ProgressIndicatorEx> stateDelegates = myStateDelegates;
if (stateDelegates == null) {
myStateDelegates = stateDelegates = ContainerUtil.createLockFreeCopyOnWriteList();
}
else {
LOG.assertTrue(!stateDelegates.contains(delegate), "Already registered: " + delegate);
}
stateDelegates.add(delegate);
}
}
private void delegateProgressChange(@NotNull IndicatorAction action) {
delegate(action);
onProgressChange();
}
private void delegateRunningChange(@NotNull IndicatorAction action) {
delegate(action);
onRunningChange();
}
private void delegate(@NotNull IndicatorAction action) {
List<ProgressIndicatorEx> list = myStateDelegates;
if (list != null && !list.isEmpty()) {
for (ProgressIndicatorEx each : list) {
action.execute(each);
}
}
}
protected void onProgressChange() {
}
protected void onRunningChange() {
}
@Override
public boolean isModalityEntered() {
return myModalityEntered;
}
@Override
public synchronized void initStateFrom(@NotNull final ProgressIndicator indicator) {
super.initStateFrom(indicator);
if (indicator instanceof ProgressIndicatorEx) {
myModalityEntered = ((ProgressIndicatorEx)indicator).isModalityEntered();
}
}
@Override
public boolean wasStarted() {
return myWasStarted;
}
private interface IndicatorAction {
void execute(@NotNull ProgressIndicatorEx each);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -15,6 +15,8 @@
*/
package com.intellij.openapi.progress.util;
public abstract class BlockingProgressIndicator extends ProgressIndicatorBase {
public abstract void startBlocking();
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
public interface BlockingProgressIndicator extends ProgressIndicatorEx {
public void startBlocking();
}
@@ -15,336 +15,24 @@
*/
package com.intellij.openapi.progress.util;
import com.intellij.openapi.application.impl.LaterInvocator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.TaskInfo;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.WeakList;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.progress.StandardProgressIndicator;
import java.util.List;
public class ProgressIndicatorBase extends AbstractProgressIndicatorExBase implements StandardProgressIndicator {
public ProgressIndicatorBase() {
this(false);
}
public class ProgressIndicatorBase extends AbstractProgressIndicatorBase implements ProgressIndicatorEx {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.progress.util.ProgressIndicatorBase");
private final boolean myReusable;
private volatile boolean myModalityEntered;
private volatile List<ProgressIndicatorEx> myStateDelegates;
private volatile WeakList<TaskInfo> myFinished;
private volatile boolean myWasStarted;
private TaskInfo myOwnerTask;
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();
}
};
public ProgressIndicatorBase() { this(false); }
public ProgressIndicatorBase(boolean reusable) {
myReusable = reusable;
super(reusable);
}
@Override
public void start() {
synchronized (this) {
super.start();
delegateRunningChange(START_ACTION);
}
myWasStarted = true;
enterModality();
}
protected final void enterModality() {
if (myModalityProgress == this) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
doEnterModality();
}
});
}
}
private void doEnterModality() {
if (!myModalityEntered) {
LaterInvocator.enterModal(this);
myModalityEntered = true;
}
}
@Override
public void stop() {
super.stop();
delegateRunningChange(STOP_ACTION);
exitModality();
}
protected final void exitModality() {
if (myModalityProgress == this) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
doExitModality();
}
});
}
}
private void doExitModality() {
if (myModalityEntered) {
LaterInvocator.leaveModal(this);
myModalityEntered = false;
}
}
@Override
public void cancel() {
public final void cancel() {
super.cancel();
delegateRunningChange(CANCEL_ACTION);
}
@Override
public void finish(@NotNull final TaskInfo task) {
WeakList<TaskInfo> finished = myFinished;
if (finished == null) {
synchronized (this) {
finished = myFinished;
if (finished == null) {
myFinished = finished = new WeakList<TaskInfo>();
}
}
}
if (!finished.addIfAbsent(task)) return;
delegateRunningChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx each) {
each.finish(task);
}
});
}
@Override
public boolean isFinished(@NotNull final TaskInfo task) {
List<TaskInfo> list = myFinished;
return list != null && list.contains(task);
}
protected void setOwnerTask(TaskInfo owner) {
myOwnerTask = owner;
}
@Override
public void processFinish() {
if (myOwnerTask != null) {
finish(myOwnerTask);
myOwnerTask = null;
}
}
@Override
public final void checkCanceled() {
super.checkCanceled();
delegate(CHECK_CANCELED_ACTION);
}
@Override
public void setText(final String text) {
super.setText(text);
delegateProgressChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx 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);
}
});
}
@Override
public void setFraction(final double fraction) {
super.setFraction(fraction);
delegateProgressChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx each) {
each.setFraction(fraction);
}
});
}
@Override
public synchronized void pushState() {
super.pushState();
delegateProgressChange(PUSH_ACTION);
}
@Override
public synchronized void popState() {
super.popState();
delegateProgressChange(POP_ACTION);
}
@Override
public void startNonCancelableSection() {
super.startNonCancelableSection();
delegateProgressChange(STARTNC_ACTION);
}
@Override
public void finishNonCancelableSection() {
super.finishNonCancelableSection();
delegateProgressChange(FINISHNC_ACTION);
}
@Override
protected boolean isReuseable() {
return myReusable;
}
@Override
public void setIndeterminate(final boolean indeterminate) {
super.setIndeterminate(indeterminate);
delegateProgressChange(new IndicatorAction() {
@Override
public void execute(@NotNull final ProgressIndicatorEx each) {
each.setIndeterminate(indeterminate);
}
});
}
@Override
public final void addStateDelegate(@NotNull ProgressIndicatorEx delegate) {
delegate.initStateFrom(this);
synchronized (this) {
List<ProgressIndicatorEx> stateDelegates = myStateDelegates;
if (stateDelegates == null) {
myStateDelegates = stateDelegates = ContainerUtil.createLockFreeCopyOnWriteList();
}
else {
LOG.assertTrue(!stateDelegates.contains(delegate), "Already registered: " + delegate);
}
stateDelegates.add(delegate);
}
}
private void delegateProgressChange(@NotNull IndicatorAction action) {
delegate(action);
onProgressChange();
}
private void delegateRunningChange(@NotNull IndicatorAction action) {
delegate(action);
onRunningChange();
}
private void delegate(@NotNull IndicatorAction action) {
List<ProgressIndicatorEx> list = myStateDelegates;
if (list != null && !list.isEmpty()) {
for (ProgressIndicatorEx each : list) {
action.execute(each);
}
}
}
private interface IndicatorAction {
void execute(@NotNull ProgressIndicatorEx each);
}
protected void onProgressChange() {
}
protected void onRunningChange() {
}
@Override
public boolean isModalityEntered() {
return myModalityEntered;
}
@Override
public synchronized void initStateFrom(@NotNull final ProgressIndicator indicator) {
super.initStateFrom(indicator);
if (indicator instanceof ProgressIndicatorEx) {
myModalityEntered = ((ProgressIndicatorEx)indicator).isModalityEntered();
}
}
@Override
public boolean wasStarted() {
return myWasStarted;
public final boolean isCanceled() {
return super.isCanceled();
}
}
@@ -46,7 +46,7 @@ import java.awt.event.*;
import java.io.File;
@SuppressWarnings({"NonStaticInitializer"})
public class ProgressWindow extends BlockingProgressIndicator implements Disposable {
public class ProgressWindow extends ProgressIndicatorBase implements BlockingProgressIndicator, Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.progress.util.ProgressWindow");
/**
@@ -114,6 +114,15 @@ public class ProgressWindow extends BlockingProgressIndicator implements Disposa
Disposer.register(this, myDialog);
myFocusTrackback.registerFocusComponent(myDialog.getPanel());
addStateDelegate(new AbstractProgressIndicatorExBase(){
@Override
public void cancel() {
super.cancel();
if (myDialog != null) {
myDialog.cancel();
}
}
});
}
@Override
@@ -289,14 +298,6 @@ public class ProgressWindow extends BlockingProgressIndicator implements Disposa
return myDialog != null && myDialog.getPanel() != null && myDialog.getPanel().isShowing();
}
@Override
public void cancel() {
super.cancel();
if (myDialog != null) {
myDialog.cancel();
}
}
public void background() {
final Runnable backgroundHandler = myBackgroundHandler;
if (backgroundHandler != null) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -18,14 +18,11 @@ package com.intellij.openapi.progress.util;
import com.intellij.openapi.project.Project;
import javax.swing.*;
import java.util.LinkedList;
/**
* @author lex
*/
public class ProgressWindowWithNotification extends ProgressWindow {
private final LinkedList<ProgressIndicatorListener> myListeners = new LinkedList<ProgressIndicatorListener>();
public ProgressWindowWithNotification(boolean shouldShowCancel, Project project) {
super(shouldShowCancel, project);
}
@@ -42,25 +39,20 @@ public class ProgressWindowWithNotification extends ProgressWindow {
super(shouldShowCancel, shouldShowBackground, project, parentComponent, cancelText);
}
public void cancel() {
super.cancel();
for (final ProgressIndicatorListener progressIndicatorListener : myListeners) {
progressIndicatorListener.cancelled();
}
public void addListener(final ProgressIndicatorListener listener) {
addStateDelegate(new AbstractProgressIndicatorExBase(){
@Override
public void cancel() {
super.cancel();
listener.cancelled();
}
@Override
public void stop() {
super.stop();
listener.stopped();
}
});
}
public synchronized void stop() {
for (final ProgressIndicatorListener progressIndicatorListener : myListeners) {
progressIndicatorListener.stopped();
}
super.stop();
}
public void addListener(ProgressIndicatorListener listener) {
myListeners.addFirst(listener);
}
public void removeListener(ProgressIndicatorListener listener) {
myListeners.remove(listener);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -18,15 +18,19 @@ package com.intellij.openapi.progress.util;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.StandardProgressIndicator;
import com.intellij.openapi.progress.WrappedProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.Alarm;
import com.intellij.util.concurrency.Semaphore;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
public class SmoothProgressAdapter extends BlockingProgressIndicator {
public class SmoothProgressAdapter extends AbstractProgressIndicatorExBase implements BlockingProgressIndicator, WrappedProgressIndicator,
StandardProgressIndicator {
private static final int SHOW_DELAY = 500;
private final Alarm myStartupAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD);
@@ -34,11 +38,12 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
protected ProgressIndicator myOriginal;
private final Project myProject;
private boolean myOriginalStarted;
private volatile boolean myOriginalStarted;
private DialogWrapper myDialog;
private final Runnable myShowRequest = new Runnable() {
@Override
public void run() {
synchronized(SmoothProgressAdapter.this){
if (!isRunning()) {
@@ -55,24 +60,33 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
}
};
public SmoothProgressAdapter(ProgressIndicator original, Project project){
public SmoothProgressAdapter(@NotNull ProgressIndicator original, @NotNull Project project){
myOriginal = original;
myProject = project;
if (myOriginal.isModal()) {
myOriginal.setModalityProgress(this);
this.setModalityProgress(this);
setModalityProgress(this);
}
}
@NotNull
@Override
public ProgressIndicator getOriginalProgressIndicator() {
return myOriginal;
}
@Override
public void setIndeterminate(boolean indeterminate) {
super.setIndeterminate(indeterminate);
myOriginal.setIndeterminate(indeterminate);
}
@Override
public boolean isIndeterminate() {
return myOriginal.isIndeterminate();
}
@Override
public synchronized void start() {
if (isRunning()) return;
@@ -81,6 +95,7 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
myStartupAlarm.addRequest(myShowRequest, SHOW_DELAY);
}
@Override
public void startBlocking() {
ApplicationManager.getApplication().assertIsDispatchThread();
start();
@@ -98,10 +113,12 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
setResizable(false);
}
@Override
protected boolean isProgressDialog() {
return true;
}
@Override
protected JComponent createCenterPanel() {
return null;
}
@@ -112,6 +129,7 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
}
}
@Override
public synchronized void stop() {
if (myOriginal.isRunning()) {
myOriginal.stop();
@@ -131,6 +149,7 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
SwingUtilities.invokeLater(
new Runnable() {
@Override
public void run() {
semaphore.waitFor();
if (myDialog != null){
@@ -150,6 +169,7 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
}
}
@Override
public synchronized void setText(String text) {
super.setText(text);
if (myOriginal.isRunning()) {
@@ -157,6 +177,7 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
}
}
@Override
public synchronized void setFraction(double fraction) {
super.setFraction(fraction);
if (myOriginal.isRunning()) {
@@ -164,6 +185,7 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
}
}
@Override
public synchronized void setText2(String text) {
super.setText2(text);
if (myOriginal.isRunning()) {
@@ -171,21 +193,15 @@ public class SmoothProgressAdapter extends BlockingProgressIndicator {
}
}
public void cancel() {
@Override
public final void cancel() {
super.cancel();
myOriginal.cancel();
}
public boolean isCanceled() {
@Override
public final boolean isCanceled() {
if (super.isCanceled()) return true;
if (!myOriginalStarted) return false;
return myOriginal.isCanceled();
return myOriginalStarted && myOriginal.isCanceled();
}
public ProgressIndicator getOriginal() {
return myOriginal;
}
}
@@ -26,6 +26,7 @@ import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
import com.intellij.openapi.fileEditor.impl.EditorsSplitters;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.TaskInfo;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.Balloon;
@@ -609,12 +610,13 @@ public class InfoAndProgressPanel extends JPanel implements CustomStatusBarWidge
super(compact, task);
myOriginal = original;
original.addStateDelegate(this);
}
@Override
public void cancel() {
super.cancel();
updateProgress();
addStateDelegate(new AbstractProgressIndicatorExBase(){
@Override
public void cancel() {
super.cancel();
updateProgress();
}
});
}
@Override
@@ -16,6 +16,7 @@
package com.intellij.openapi.progress.util;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.progress.*;
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
@@ -189,26 +190,13 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
private volatile boolean checkCanceledCalled;
private volatile boolean taskCanceled;
private volatile boolean taskSucceeded;
private volatile boolean taskFinished;
private volatile Throwable exception;
public void testProgressManagerCheckCanceledDoesNotDelegateToProgressIndicatorIfThereAreNoCanceledIndicators() throws Throwable {
final long warmupEnd = System.currentTimeMillis() + 1000;
final long end = warmupEnd + 1000;
final long end = warmupEnd + 10000;
checkCanceledCalled = false;
final ProgressIndicator myIndicator = new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
checkCanceledCalled = true;
assertTrue(isCanceled());
super.checkCanceled();
}
@Override
public void processFinish() {
taskFinished = true;
}
};
taskCanceled = taskSucceeded = taskFinished = false;
final ProgressIndicatorBase myIndicator = new ProgressIndicatorBase();
taskCanceled = taskSucceeded = false;
exception = null;
Future<?> future = ProgressManagerImpl.runProcessWithProgressAsynchronously(new Task.Backgroundable(getProject(), "xxx") {
@Override
@@ -220,6 +208,11 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
ProgressManager.checkCanceled();
}
}
catch (ProcessCanceledException e) {
exception = e;
checkCanceledCalled = true;
throw e;
}
catch (RuntimeException e) {
exception = e;
throw e;
@@ -251,8 +244,6 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
myIndicator.cancel();
}
}
assertTrue(taskFinished);
// invokeLater in runProcessWithProgressAsynchronously
UIUtil.dispatchAllInvocationEvents();
@@ -262,7 +253,39 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
assertTrue(String.valueOf(exception), exception instanceof ProcessCanceledException);
}
private static class ProgressIndicatorStub extends EmptyProgressIndicator implements ProgressIndicatorEx {
private volatile boolean myFlag;
public void testPerverseIndicator() {
checkCanceledCalled = false;
ProgressIndicator indicator = new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
checkCanceledCalled = true;
if (myFlag) throw new ProcessCanceledException();
}
};
myFlag = false;
Alarm alarm = new Alarm(myTestRootDisposable);
alarm.addRequest(new Runnable() {
@Override
public void run() {
myFlag = true;
}
}, 100);
final long start = System.currentTimeMillis();
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
while (System.currentTimeMillis() - start < 10000) {
ProgressManager.checkCanceled();
}
}
}, indicator);
assertTrue(checkCanceledCalled);
}
private static class ProgressIndicatorStub implements ProgressIndicatorEx {
private volatile boolean myCanceled;
@Override
public void addStateDelegate(@NotNull ProgressIndicatorEx delegate) {
throw new RuntimeException();
@@ -318,5 +341,122 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
public int getNonCancelableCount() {
throw new RuntimeException();
}
@Override
public void start() {
}
@Override
public void stop() {
}
@Override
public void setText(String text) {
throw new RuntimeException();
}
@Override
public String getText() {
throw new RuntimeException();
}
@Override
public String getText2() {
throw new RuntimeException();
}
@Override
public void setText2(String text) {
throw new RuntimeException();
}
@Override
public double getFraction() {
throw new RuntimeException();
}
@Override
public void setFraction(double fraction) {
throw new RuntimeException();
}
@Override
public void pushState() {
throw new RuntimeException();
}
@Override
public void popState() {
throw new RuntimeException();
}
@Override
public void startNonCancelableSection() {
throw new RuntimeException();
}
@Override
public void finishNonCancelableSection() {
throw new RuntimeException();
}
@Override
public boolean isModal() {
return false;
}
@NotNull
@Override
public ModalityState getModalityState() {
throw new RuntimeException();
}
@Override
public void setModalityProgress(ProgressIndicator modalityProgress) {
throw new RuntimeException();
}
@Override
public boolean isIndeterminate() {
throw new RuntimeException();
}
@Override
public void setIndeterminate(boolean indeterminate) {
throw new RuntimeException();
}
@Override
public boolean isPopupWasShown() {
throw new RuntimeException();
}
@Override
public boolean isShowing() {
throw new RuntimeException();
}
@Override
public boolean isRunning() {
return true;
}
@Override
public void cancel() {
myCanceled = true;
ProgressManager.canceled(this);
}
@Override
public boolean isCanceled() {
return myCanceled;
}
@Override
public void checkCanceled() throws ProcessCanceledException {
if (myCanceled) throw new ProcessCanceledException();
}
}
}
@@ -24,6 +24,7 @@ import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.fileTypes.impl.FileTypeRenderer;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
@@ -509,13 +510,15 @@ public class SearchDialog extends DialogWrapper implements ConfigurationCreator
new Factory<ProgressIndicator>() {
@Override
public ProgressIndicator create() {
return new FindProgressIndicator(searchContext.getProject(), presentation.getScopeText()) {
FindProgressIndicator indicator = new FindProgressIndicator(searchContext.getProject(), presentation.getScopeText());
indicator.addStateDelegate(new AbstractProgressIndicatorExBase(){
@Override
public void cancel() {
context.getCommand().stopAsyncSearch();
super.cancel();
context.getCommand().stopAsyncSearch();
}
};
});
return indicator;
}
}
);
@@ -15,6 +15,7 @@
*/
package com.intellij.testFramework;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
import com.intellij.ide.DataManager;
import com.intellij.injected.editor.DocumentWindow;
@@ -178,7 +179,10 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
}
protected static Editor createEditor(@NotNull VirtualFile file) {
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
Editor editor = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file, 0), false);
DaemonCodeAnalyzer.getInstance(getProject()).restart();
((EditorImpl)editor).setCaretActive();
return editor;
}
@@ -43,6 +43,7 @@ import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.module.impl.ModuleManagerImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.project.impl.ProjectManagerImpl;
import com.intellij.openapi.project.impl.TooManyProjectLeakedException;
@@ -341,6 +342,12 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().cleanupForNextTest();
}
ProjectManagerImpl projectManager = (ProjectManagerImpl)ProjectManager.getInstance();
if (projectManager.isDefaultProjectInitialized()) {
Project defaultProject = projectManager.getDefaultProject();
((PsiManagerEx)PsiManager.getInstance(defaultProject)).getFileManager().cleanupForNextTest();
}
LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance();
if (localFileSystem != null) {
localFileSystem.cleanupForNextTest();
@@ -1468,9 +1468,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
private Editor createEditor(@NotNull VirtualFile file) {
final Project project = getProject();
final FileEditorManager instance = FileEditorManager.getInstance(project);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
Editor editor = instance.openTextEditor(new OpenFileDescriptor(project, file), false);
if (editor != null) {
editor.getCaretModel().moveToOffset(0);
DaemonCodeAnalyzer.getInstance(getProject()).restart();
}
return editor;
}
@@ -45,10 +45,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl;
import com.intellij.testFramework.EditorListenerTracker;
import com.intellij.testFramework.LightPlatformTestCase;
@@ -245,6 +242,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
protected void run() throws Throwable {
virtualFile[0] = dir.createChildData(this, StringUtil.getShortName(relativePath, '/'));
VfsUtil.saveText(virtualFile[0], fileText);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}
}.execute();
return ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
@@ -138,6 +138,7 @@ class SearchForUsagesRunnable implements Runnable {
resultLines.add(shortMessage);
resultListener = addHrefHandling(resultListener, LARGE_FILES_HREF_TARGET, new Runnable() {
@Override
public void run() {
String detailedMessage = detailedLargeFilesMessage(largeFiles);
List<String> strings = new ArrayList<String>(lines);
@@ -247,9 +248,15 @@ class SearchForUsagesRunnable implements Runnable {
};
}
private static PsiElement getPsiElement(UsageTarget[] searchFor) {
if (!(searchFor[0] instanceof PsiElementUsageTarget)) return null;
return ((PsiElementUsageTarget)searchFor[0]).getElement();
private static PsiElement getPsiElement(@NotNull UsageTarget[] searchFor) {
final UsageTarget target = searchFor[0];
if (!(target instanceof PsiElementUsageTarget)) return null;
return ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
@Override
public PsiElement compute() {
return ((PsiElementUsageTarget)target).getElement();
}
});
}
private static void flashUsageScriptaculously(@NotNull final Usage usage) {
@@ -321,6 +328,7 @@ class SearchForUsagesRunnable implements Runnable {
private void searchUsages(@NotNull final AtomicBoolean findStartedBalloonShown) {
ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
assert indicator != null : "must run find usages under progress";
TooManyUsagesStatus.createFor(indicator);
Alarm findUsagesStartedBalloon = new Alarm();
findUsagesStartedBalloon.addRequest(new Runnable() {
@@ -337,7 +345,8 @@ class SearchForUsagesRunnable implements Runnable {
@Override
public boolean process(final Usage usage) {
ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
if (indicator != null && indicator.isCanceled()) return false;
assert indicator != null : "must run find usages under progress";
if (indicator.isCanceled()) return false;
if (!UsageViewManagerImpl.isInScope(usage, mySearchScopeToWarnOfFallingOutOf)) {
myOutOfScopeUsages.incrementAndGet();
@@ -368,7 +377,7 @@ class SearchForUsagesRunnable implements Runnable {
});
}
}
return indicator == null || !indicator.isCanceled();
return !indicator.isCanceled();
}
});
if (getUsageView(indicator) != null) {
@@ -1,119 +0,0 @@
/*
* Copyright 2000-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.util.Consumer;
import com.intellij.util.concurrency.Semaphore;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
// competes to calculate The Result
public class ConcurrentTasks<T> {
private volatile boolean myResultKnown;
private final Semaphore mySemaphore;
private volatile T myResult;
private AtomicInteger myCntAlive;
private final ProgressIndicator myParentIndicator;
private final List<Consumer<Consumer<T>>> myTasks;
public void compute() {
final EmptyProgressIndicator pi = new EmptyProgressIndicator() {
@Override
public void checkCanceled() {
if (myResultKnown || (myParentIndicator != null) && myParentIndicator.isCanceled()) {
super.cancel();
}
super.checkCanceled();
}
};
myCntAlive = new AtomicInteger(myTasks.size());
mySemaphore.down();
final List<Future<?>> futures = new LinkedList<Future<?>>();
for (final Consumer<Consumer<T>> task : myTasks) {
if (myResultKnown) {
final int decremented = myCntAlive.decrementAndGet();
continue;
}
final Runnable computableProxy = new Runnable() {
public void run() {
try {
task.consume(new Consumer<T>() {
public void consume(T t) {
if (myResultKnown) return;
myResult = t;
myResultKnown = true;
}
});
}
finally {
final int decremented = myCntAlive.decrementAndGet();
if (decremented == 0 || myResultKnown) {
mySemaphore.up();
}
}
}
};
final Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
ProgressManager.getInstance().runProcess(computableProxy, pi);
}
});
futures.add(future);
}
while (true) {
if (myResultKnown) break;
if (myCntAlive.get() <= 0) break;
pi.checkCanceled();
mySemaphore.waitFor(300);
}
// in it possible to even interrupt() threads involved, but at the moment it's better for tasks themselves to check cancel status
for (Future<?> future : futures) {
if ((! future.isCancelled() && (! future.isDone()))) {
future.cancel(true);
}
}
}
public boolean isResultKnown() {
return myResultKnown;
}
public T getResult() {
return myResult;
}
public ConcurrentTasks(final ProgressIndicator parentIndicator, final Consumer<Consumer<T>>... tasks) {
myParentIndicator = parentIndicator;
myTasks = Arrays.asList(tasks);
mySemaphore = new Semaphore();
}
public ConcurrentTasks(final ProgressIndicator parentIndicator, final List<Consumer<Consumer<T>>> tasks) {
myParentIndicator = parentIndicator;
myTasks = tasks;
mySemaphore = new Semaphore();
}
}
@@ -46,10 +46,7 @@ import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.impl.*;
import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.*;
import com.intellij.ui.EditorNotifications;
import com.intellij.util.*;
import com.intellij.util.concurrency.Semaphore;
@@ -110,25 +107,26 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
private final IgnoredFilesComponent myIgnoredIdeaLevel;
private boolean myExcludedConvertedToIgnored;
private ProgressIndicator myUpdateChangesProgressIndicator;
private volatile ProgressIndicator myUpdateChangesProgressIndicator = createProgressIndicator();
public static final Topic<LocalChangeListsLoadedListener> LISTS_LOADED = new Topic<LocalChangeListsLoadedListener>(
"LOCAL_CHANGE_LISTS_LOADED", LocalChangeListsLoadedListener.class);
private boolean myShowLocalChangesInvalidated;
private AtomicReference<String> myFreezeName;
private final AtomicReference<String> myFreezeName;
// notifies myListeners on the same thread that local changes update is done
private final DelayedNotificator myDelayedNotificator;
private final VcsListener myVcsListener = new VcsListener() {
@Override
public void directoryMappingChanged() {
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
}
};
private final ChangelistConflictTracker myConflictTracker;
private VcsDirtyScopeManager myDirtyScopeManager;
private VcsDirtyScopeVfsListener myVfsListener;
private final VcsDirtyScopeVfsListener myVfsListener;
private boolean myModalNotificationsBlocked;
@NotNull private final Collection<LocalChangeList> myListsToBeDeleted = new HashSet<LocalChangeList>();
@@ -170,6 +168,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
!oldList.isReadOnly()) {
invokeAfterUpdate(new Runnable() {
@Override
public void run() {
if (getChangeList(oldList.getId()) == null) {
return; // removed already
@@ -224,10 +223,12 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
VcsConfirmationDialog dialog = new VcsConfirmationDialog(myProject, new VcsShowConfirmationOption() {
@Override
public Value getValue() {
return config.REMOVE_EMPTY_INACTIVE_CHANGELISTS;
}
@Override
public void setValue(Value value) {
config.REMOVE_EMPTY_INACTIVE_CHANGELISTS = value;
}
@@ -262,6 +263,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myListsToBeDeleted.clear();
}
@Override
public void projectOpened() {
initializeForNewProject();
@@ -273,6 +275,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
else {
((ProjectLevelVcsManagerImpl)vcsManager).addInitializationRequest(
VcsInitObject.CHANGE_LIST_MANAGER, new DumbAwareRunnable() {
@Override
public void run() {
myUpdater.initialized();
broadcastStateAfterLoad();
@@ -332,27 +335,29 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public void projectClosed() {
ProjectLevelVcsManager.getInstance(myProject).removeVcsListener(myVcsListener);
synchronized (myDataLock) {
if (myUpdateChangesProgressIndicator != null) {
myUpdateChangesProgressIndicator.cancel();
}
myUpdateChangesProgressIndicator.cancel();
}
myUpdater.stop();
myConflictTracker.stopTracking();
}
@Override
@NotNull @NonNls
public String getComponentName() {
return "ChangeListManager";
}
@Override
public void initComponent() {
}
@Override
public void disposeComponent() {
}
@@ -360,6 +365,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
* update itself might produce actions done on AWT thread (invoked-after),
* so waiting for its completion on AWT thread is not good runnable is invoked on AWT thread
*/
@Override
public void invokeAfterUpdate(final Runnable afterUpdate,
final InvokeAfterUpdateMode mode,
@Nullable final String title,
@@ -367,6 +373,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myUpdater.invokeAfterUpdate(afterUpdate, mode, title, null, state);
}
@Override
public void invokeAfterUpdate(final Runnable afterUpdate, final InvokeAfterUpdateMode mode, final String title,
final Consumer<VcsDirtyScopeManager> dirtyScopeManagerFiller, final ModalityState state) {
myUpdater.invokeAfterUpdate(afterUpdate, mode, title, dirtyScopeManagerFiller, state);
@@ -374,6 +381,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
static class DisposedException extends RuntimeException {}
@Override
public void freeze(final ContinuationPause context, final String reason) {
myUpdater.setIgnoreBackgroundOperation(true);
// this update is nessesary for git, to refresh local changes before
@@ -391,6 +399,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
public void freezeImmediately(@Nullable String reason) {
myUpdater.setIgnoreBackgroundOperation(false);
myUpdater.pause();
myUpdateChangesProgressIndicator.cancel();
myFreezeName.set(reason);
}
@@ -400,14 +409,17 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myFreezeName.set(null);
}
@Override
public String isFreezed() {
return myFreezeName.get();
}
@Override
public void scheduleUpdate() {
myUpdater.schedule();
}
@Override
public void scheduleUpdate(boolean updateUnversionedFiles) {
myUpdater.schedule();
}
@@ -471,8 +483,6 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
private void updateImmediately() {
final DataHolder dataHolder;
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
if (!vcsManager.hasActiveVcss()) return;
@@ -488,6 +498,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
// copy existsing data to objects that would be updated.
// mark for "modifier" that update started (it would create duplicates of modification commands done by user during update;
// after update of copies of objects is complete, it would apply the same modifications to copies.)
final DataHolder dataHolder;
synchronized (myDataLock) {
dataHolder = new DataHolder((FileHolderComposite)myComposite.copy(), myWorker.copy(), wasEverythingDirty);
myModifier.enterUpdate();
@@ -519,6 +530,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
clearCurrentRevisionsCache(invalidated);
// for the case of project being closed we need a read action here -> to be more consistent
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (myProject.isDisposed()) {
return;
@@ -653,18 +665,9 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
private EmptyProgressIndicator createProgressIndicator() {
return new EmptyProgressIndicator() {
@Override
public boolean isCanceled() {
return myUpdater.isStopped();
}
@Override
public void checkCanceled() {
checkIfDisposed();
}
};
@NotNull
private static ProgressIndicator createProgressIndicator() {
return new EmptyProgressIndicator();
}
private class DataHolder {
@@ -779,6 +782,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
return before != null && scope.belongsTo(before.getFile()) || after != null && scope.belongsTo(after.getFile());
}
@Override
public List<LocalChangeList> getChangeListsCopy() {
synchronized (myDataLock) {
return myWorker.getListsCopy();
@@ -789,6 +793,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
* @deprecated this method made equivalent to {@link #getChangeListsCopy()} so to don't be confused by method name,
* better use {@link #getChangeListsCopy()}
*/
@Override
@NotNull
public List<LocalChangeList> getChangeLists() {
synchronized (myDataLock) {
@@ -796,12 +801,14 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public List<File> getAffectedPaths() {
synchronized (myDataLock) {
return myWorker.getAffectedPaths();
}
}
@Override
@NotNull
public List<VirtualFile> getAffectedFiles() {
synchronized (myDataLock) {
@@ -809,6 +816,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
@NotNull
public Collection<Change> getAllChanges() {
synchronized (myDataLock) {
@@ -901,12 +909,14 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public boolean isFileAffected(final VirtualFile file) {
synchronized (myDataLock) {
return myWorker.getStatus(file) != null;
}
}
@Override
@Nullable
public LocalChangeList findChangeList(final String name) {
synchronized (myDataLock) {
@@ -921,6 +931,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public LocalChangeList addChangeList(@NotNull final String name, @Nullable final String comment) {
return addChangeList(name, comment, null);
}
@@ -940,6 +951,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
@Override
public void removeChangeList(final String name) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
@@ -952,6 +964,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
});
}
@Override
public void removeChangeList(LocalChangeList list) {
removeChangeList(list.getName());
}
@@ -959,6 +972,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
/**
* does no modification to change lists, only notification is sent
*/
@Override
@NotNull
public Runnable prepareForChangeDeletion(final Collection<Change> changes) {
final Map<String, LocalChangeList> lists = new HashMap<String, LocalChangeList>();
@@ -967,6 +981,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
map = myWorker.listsForChanges(changes, lists);
}
return new Runnable() {
@Override
public void run() {
final ChangeListListener multicaster = myDelayedNotificator.getProxyDispatcher();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@@ -997,6 +1012,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
};
}
@Override
public void setDefaultChangeList(@NotNull final LocalChangeList list) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
@@ -1009,6 +1025,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myChangesViewManager.scheduleRefresh();
}
@Override
@Nullable
public LocalChangeList getDefaultChangeList() {
synchronized (myDataLock) {
@@ -1021,6 +1038,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
return list instanceof LocalChangeList && myWorker.isDefaultList((LocalChangeList)list);
}
@Override
@NotNull
public Collection<LocalChangeList> getInvolvedListsFilterChanges(final Collection<Change> changes, final List<Change> validChanges) {
synchronized (myDataLock) {
@@ -1028,6 +1046,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
@Nullable
public LocalChangeList getChangeList(@NotNull Change change) {
synchronized (myDataLock) {
@@ -1045,6 +1064,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
/**
* @deprecated better use normal comparison, with equals
*/
@Override
@Nullable
public LocalChangeList getIdentityChangeList(Change change) {
synchronized (myDataLock) {
@@ -1067,6 +1087,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
@Nullable
public Change getChange(@NotNull VirtualFile file) {
synchronized (myDataLock) {
@@ -1097,6 +1118,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
@Nullable
public Change getChange(final FilePath file) {
synchronized (myDataLock) {
@@ -1104,12 +1126,14 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public boolean isUnversioned(VirtualFile file) {
synchronized (myDataLock) {
return myComposite.getVFHolder(FileHolder.HolderType.UNVERSIONED).containsFile(file);
}
}
@Override
@NotNull
public FileStatus getStatus(VirtualFile file) {
synchronized (myDataLock) {
@@ -1127,6 +1151,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
@NotNull
public Collection<Change> getChangesIn(VirtualFile dir) {
return getChangesIn(new FilePathImpl(dir));
@@ -1141,6 +1166,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
@NotNull
public Collection<Change> getChangesIn(final FilePath dirPath) {
synchronized (myDataLock) {
@@ -1148,6 +1174,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public void moveChangesTo(final LocalChangeList list, final Change... changes) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
@@ -1178,6 +1205,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
final List<VcsException> exceptions = new ArrayList<VcsException>();
final Set<VirtualFile> allProcessedFiles = new HashSet<VirtualFile>();
ChangesUtil.processVirtualFilesByVcs(myProject, files, new ChangesUtil.PerVcsProcessor<VirtualFile>() {
@Override
public void process(final AbstractVcs vcs, final List<VirtualFile> items) {
final CheckinEnvironment environment = vcs.getCheckinEnvironment();
if (environment != null) {
@@ -1219,6 +1247,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
if (!list.isDefault()) {
// find the changes for the added files and move them to the necessary changelist
invokeAfterUpdate(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
@@ -1252,23 +1281,28 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public Project getProject() {
return myProject;
}
@Override
public void addChangeListListener(ChangeListListener listener) {
myListeners.addListener(listener);
}
@Override
public void removeChangeListListener(ChangeListListener listener) {
myListeners.removeListener(listener);
}
@Override
public void registerCommitExecutor(CommitExecutor executor) {
myExecutors.add(executor);
}
@Override
public void commitChanges(LocalChangeList changeList, List<Change> changes) {
doCommit(changeList, changes, false);
}
@@ -1277,17 +1311,20 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
FileDocumentManager.getInstance().saveAllDocuments();
return new CommitHelper(myProject, changeList, changes, changeList.getName(),
StringUtil.isEmpty(changeList.getComment()) ? changeList.getName() : changeList.getComment(),
new ArrayList<CheckinHandler>(), false, synchronously, NullableFunction.NULL, null).doCommit();
new ArrayList<CheckinHandler>(), false, synchronously, FunctionUtil.nullConstant(), null).doCommit();
}
@Override
public void commitChangesSynchronously(LocalChangeList changeList, List<Change> changes) {
doCommit(changeList, changes, true);
}
@Override
public boolean commitChangesSynchronouslyWithResult(final LocalChangeList changeList, final List<Change> changes) {
return doCommit(changeList, changes, true);
}
@Override
@SuppressWarnings({"unchecked"})
public void readExternal(Element element) throws InvalidDataException {
if (!myProject.isDefault()) {
@@ -1303,6 +1340,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
if (!myProject.isDefault()) {
final IgnoredFilesComponent ignoredFilesComponent;
@@ -1320,8 +1358,9 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
// used in TeamCity
@Override
public void reopenFiles(List<FilePath> paths) {
final ReadonlyStatusHandlerImpl readonlyStatusHandler = (ReadonlyStatusHandlerImpl)ReadonlyStatusHandlerImpl.getInstance(myProject);
final ReadonlyStatusHandlerImpl readonlyStatusHandler = (ReadonlyStatusHandlerImpl)ReadonlyStatusHandler.getInstance(myProject);
final boolean savedOption = readonlyStatusHandler.getState().SHOW_DIALOG;
readonlyStatusHandler.getState().SHOW_DIALOG = false;
try {
@@ -1332,12 +1371,13 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public List<CommitExecutor> getRegisteredExecutors() {
return Collections.unmodifiableList(myExecutors);
}
private static class MyDirtyFilesScheduler {
private final static int ourPiecesLimit = 100;
private static final int ourPiecesLimit = 100;
final List<VirtualFile> myFiles = new ArrayList<VirtualFile>();
final List<VirtualFile> myDirs = new ArrayList<VirtualFile>();
private boolean myEveryThing;
@@ -1377,6 +1417,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public void addFilesToIgnore(final IgnoredFileBean... filesToIgnore) {
myIgnoredIdeaLevel.add(filesToIgnore);
scheduleUnversionedUpdate();
@@ -1405,6 +1446,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
scheduler.arise();
}
@Override
public void setFilesToIgnore(final IgnoredFileBean... filesToIgnore) {
myIgnoredIdeaLevel.set(filesToIgnore);
scheduleUnversionedUpdate();
@@ -1429,14 +1471,17 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public IgnoredFileBean[] getFilesToIgnore() {
return myIgnoredIdeaLevel.getFilesToIgnore();
}
@Override
public boolean isIgnoredFile(@NotNull VirtualFile file) {
return myIgnoredIdeaLevel.isIgnoredFile(file);
}
@Override
@Nullable
public String getSwitchedBranch(final VirtualFile file) {
synchronized (myDataLock) {
@@ -1459,9 +1504,10 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
return VfsUtil.toVirtualFileArray(result);
return VfsUtilCore.toVirtualFileArray(result);
}
@Override
public boolean setReadOnly(final String name, final boolean value) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
@@ -1475,6 +1521,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
});
}
@Override
public boolean editName(@NotNull final String fromName, @NotNull final String toName) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
@@ -1488,6 +1535,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
});
}
@Override
public String editComment(@NotNull final String fromName, final String newComment) {
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
@@ -1536,6 +1584,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
ourUpdateAlarm.get().execute(r);
}
@Override
@TestOnly
public boolean ensureUpToDate(final boolean canBeCanceled) {
if (ApplicationManager.getApplication().isDispatchThread()) {
@@ -1571,7 +1620,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
private static class MyChangesDeltaForwarder implements PlusMinusModify<BaseRevision> {
private RemoteRevisionsCache myRevisionsCache;
private final RemoteRevisionsCache myRevisionsCache;
private final ProjectLevelVcsManager myVcsManager;
private final Project myProject;
private final AtomicReference<ScheduledExecutorService> myService;
@@ -1586,6 +1635,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
@Override
public void modify(final BaseRevision was, final BaseRevision become) {
myService.get().submit(new Runnable() {
@Override
public void run() {
final AbstractVcs vcs = getVcs(was);
if (vcs != null) {
@@ -1597,8 +1647,10 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
});
}
@Override
public void plus(final BaseRevision baseRevision) {
myService.get().submit(new Runnable() {
@Override
public void run() {
final AbstractVcs vcs = getVcs(baseRevision);
if (vcs != null) {
@@ -1609,8 +1661,10 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
});
}
@Override
public void minus(final BaseRevision baseRevision) {
myService.get().submit(new Runnable() {
@Override
public void run() {
final AbstractVcs vcs = getVcs(baseRevision);
if (vcs != null) {
@@ -1642,6 +1696,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
@Override
public boolean isFreezedWithNotification(String modalTitle) {
final String freezeReason = isFreezed();
if (freezeReason != null) {