diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java index 1be1f4e83413..7dc21a333c96 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java @@ -194,6 +194,7 @@ public abstract class AbstractLayoutCodeProcessor { final Runnable[] resultRunnable = new Runnable[1]; Runnable readAction = new Runnable() { + @Override public void run() { if (!checkFileWritable(file)) return; try{ @@ -205,6 +206,7 @@ public abstract class AbstractLayoutCodeProcessor { } }; Runnable writeAction = new Runnable() { + @Override public void run() { if (resultRunnable[0] != null) { resultRunnable[0].run(); @@ -261,6 +263,7 @@ public abstract class AbstractLayoutCodeProcessor { } return new Runnable() { + @Override public void run() { SequentialModalProgressTask progressTask = new SequentialModalProgressTask(myProject, myCommandName); ReformatFilesTask reformatFilesTask = new ReformatFilesTask(tasks); @@ -277,11 +280,13 @@ public abstract class AbstractLayoutCodeProcessor { final Runnable[] resultRunnable = new Runnable[1]; runLayoutCodeProcess( new Runnable() { + @Override public void run() { resultRunnable[0] = preprocessFiles(new ArrayList(Arrays.asList(files))); } }, new Runnable() { + @Override public void run() { if (resultRunnable[0] != null){ resultRunnable[0].run(); @@ -352,10 +357,12 @@ public abstract class AbstractLayoutCodeProcessor { final Runnable[] resultRunnable = new Runnable[1]; runLayoutCodeProcess(new Runnable() { + @Override public void run() { resultRunnable[0] = preprocessFiles(array); } }, new Runnable() { + @Override public void run() { if (resultRunnable[0] != null) { resultRunnable[0].run(); @@ -450,12 +457,14 @@ public abstract class AbstractLayoutCodeProcessor { final ModalityState modalityState = ModalityState.current(); final Runnable process = new Runnable() { + @Override public void run() { ApplicationManager.getApplication().runReadAction(readAction); } }; Runnable runnable = new Runnable() { + @Override public void run() { try { //DaemonCodeAnalyzer.getInstance(myProject).setUpdateByTimerEnabled(false); @@ -474,8 +483,10 @@ public abstract class AbstractLayoutCodeProcessor { */ final Runnable writeRunnable = new Runnable() { + @Override public void run() { CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { + @Override public void run() { if (globalAction) CommandProcessor.getInstance().markCurrentCommandAsGlobal(myProject); try { diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java index 9400ee24d539..aac90e5ebad1 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java @@ -23,6 +23,7 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public abstract class RefreshQueue { @@ -34,22 +35,23 @@ public abstract class RefreshQueue { return createSession(async, recursive, finishRunnable, getDefaultModalityState()); } - public abstract RefreshSession createSession(boolean async, boolean recursive, @Nullable Runnable finishRunnable, ModalityState state); + public abstract RefreshSession createSession(boolean async, boolean recursive, @Nullable Runnable finishRunnable, @NotNull ModalityState state); - public final void refresh(boolean async, boolean recursive, @Nullable Runnable finishRunnable, ModalityState state, VirtualFile... files) { + public final void refresh(boolean async, boolean recursive, @Nullable Runnable finishRunnable, @NotNull ModalityState state, @NotNull VirtualFile... files) { RefreshSession session = createSession(async, recursive, finishRunnable, state); session.addAllFiles(files); session.launch(); } - public abstract void refreshLocalRoots(boolean async, @Nullable Runnable postAction, ModalityState modalityState); + public abstract void refreshLocalRoots(boolean async, @Nullable Runnable postAction, @NotNull ModalityState modalityState); - public final void refresh(boolean async, boolean recursive, @Nullable Runnable finishRunnable, VirtualFile... files) { + public final void refresh(boolean async, boolean recursive, @Nullable Runnable finishRunnable, @NotNull VirtualFile... files) { refresh(async, recursive, finishRunnable, getDefaultModalityState(), files); } public abstract void processSingleEvent(VFileEvent event); + @NotNull protected ModalityState getDefaultModalityState() { return ModalityState.NON_MODAL; } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshSession.java b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshSession.java index af0d5b847f47..b0b35be25f3f 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshSession.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshSession.java @@ -31,7 +31,7 @@ public abstract class RefreshSession { public abstract void addFile(@NotNull VirtualFile file); public abstract void addAllFiles(Collection files); - public void addAllFiles(VirtualFile[] files) { + public void addAllFiles(@NotNull VirtualFile[] files) { addAllFiles(Arrays.asList(files)); } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java index 85a6d7dbd304..682475183590 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java @@ -32,7 +32,7 @@ public class ModalityStateEx extends ModalityState { this(EMPTY_REFS_ARRAY); } - public ModalityStateEx(Object[] modalEntities) { + public ModalityStateEx(@NotNull Object[] modalEntities) { if (modalEntities.length > 0) { myModalEntities = new WeakReference[modalEntities.length]; for (int i = 0; i < modalEntities.length; i++) { @@ -71,6 +71,7 @@ public class ModalityStateEx extends ModalityState { return false; } + @Override public boolean dominates(@NotNull ModalityState anotherState){ if (anotherState == ModalityState.any()) return false; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java index 39a9fc576a3d..d48ccf44b887 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java @@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VfsBundle; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.io.storage.HeavyProcessLatch; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; @@ -41,22 +42,22 @@ public class RefreshQueueImpl extends RefreshQueue { private final ExecutorService myQueue = ConcurrencyUtil.newSingleThreadExecutor("FS Synchronizer"); private final ProgressIndicator myRefreshIndicator = new RefreshProgress(VfsBundle.message("file.synchronize.progress")); - public void execute(final RefreshSessionImpl session) { + public void execute(@NotNull RefreshSessionImpl session) { if (session.isAsynchronous()) { ModalityState state = session.getModalityState(); - queueSession(session, state != null ? state : ModalityState.NON_MODAL); + queueSession(session, state); } else { - final Application app = ApplicationManager.getApplication(); - boolean isEDT = app.isDispatchThread(); - final boolean hasWriteAction = app.isWriteAccessAllowed(); - if (isEDT || hasWriteAction) { + final Application application = ApplicationManager.getApplication(); + boolean isEDT = application.isDispatchThread(); + if (isEDT) { session.scan(); + final boolean hasWriteAction = application.isWriteAccessAllowed(); session.fireEvents(hasWriteAction); } else { - if (((ApplicationEx)app).holdsReadLock()) { - LOG.error("Do not call synchronous refresh from inside read action except for event dispatch thread. This will eventually cause deadlock if there are events to fire"); + if (((ApplicationEx)application).holdsReadLock()) { + LOG.error( "Do not call synchronous refresh from inside read action except for event dispatch thread. This will eventually cause deadlock if there are events to fire"); return; } @@ -66,7 +67,7 @@ public class RefreshQueueImpl extends RefreshQueue { } } - private void queueSession(final RefreshSessionImpl session, final ModalityState modality) { + private void queueSession(@NotNull final RefreshSessionImpl session, @NotNull final ModalityState modality) { myQueue.submit(new Runnable() { @Override public void run() { @@ -96,12 +97,12 @@ public class RefreshQueueImpl extends RefreshQueue { } @Override - public RefreshSession createSession(final boolean async, boolean recursively, @Nullable final Runnable finishRunnable, ModalityState state) { + public RefreshSession createSession(final boolean async, boolean recursively, @Nullable final Runnable finishRunnable, @NotNull ModalityState state) { return new RefreshSessionImpl(async, recursively, finishRunnable, state); } @Override - public void refreshLocalRoots(boolean async, Runnable postAction, ModalityState modalityState) { + public void refreshLocalRoots(boolean async, @Nullable Runnable postAction, @NotNull ModalityState modalityState) { RefreshQueue.getInstance().refresh(async, true, postAction, modalityState, ManagingFS.getInstance().getLocalRoots()); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java index 5ba74f96360b..37f98293e00d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java @@ -47,7 +47,7 @@ public class RefreshSessionImpl extends RefreshSession { private final Semaphore mySemaphore = new Semaphore(); private volatile boolean iHaveEventsToFire; - private ModalityState myModalityState; + private final ModalityState myModalityState; public RefreshSessionImpl(final boolean isAsync, final boolean recursively, final Runnable finishRunnable) { this(isAsync, recursively, finishRunnable, ModalityState.NON_MODAL); @@ -65,6 +65,7 @@ public class RefreshSessionImpl extends RefreshSession { myIsRecursive = false; myFinishRunnable = null; myEvents = new ArrayList(events); + myModalityState = ModalityState.NON_MODAL; } @Override @@ -167,6 +168,7 @@ public class RefreshSessionImpl extends RefreshSession { return events; } + @NotNull public ModalityState getModalityState() { return myModalityState; } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java index 3a4ea2075bee..63aef3a1008d 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java @@ -86,7 +86,7 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase { @Override protected void runBareRunnable(Runnable r) throws Throwable { if (getName().equals("testRefreshingAsynchronously")) { - // this methods waits for another thread to finish, that leds + // this method waits for another thread to finish, that leads // to deadlock in swing-thread. Therefore we have to run this test // outside of swing-thread r.run();