diff --git a/platform/core-api/src/com/intellij/ui/LayeredIcon.java b/platform/core-api/src/com/intellij/ui/LayeredIcon.java index 6c5a6a590a93..a7eb1ff54efe 100644 --- a/platform/core-api/src/com/intellij/ui/LayeredIcon.java +++ b/platform/core-api/src/com/intellij/ui/LayeredIcon.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -231,4 +231,9 @@ public class LayeredIcon implements Icon { layeredIcon.setIcon(foregroundIcon, 1); return layeredIcon; } + + @Override + public String toString() { + return "Layered icon. myIcons=" + Arrays.asList(myIcons); + } } diff --git a/platform/core-api/src/com/intellij/ui/RowIcon.java b/platform/core-api/src/com/intellij/ui/RowIcon.java index a9714624b209..6449700a550d 100644 --- a/platform/core-api/src/com/intellij/ui/RowIcon.java +++ b/platform/core-api/src/com/intellij/ui/RowIcon.java @@ -109,4 +109,9 @@ public class RowIcon implements Icon { myWidth = width; myHeight = height; } + + @Override + public String toString() { + return "Row icon. myIcons=" + Arrays.asList(myIcons); + } } diff --git a/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java b/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java index 81bf3fbec597..c5917ecceabc 100644 --- a/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java @@ -21,7 +21,6 @@ package com.intellij.ui; import com.intellij.ide.PowerSaveMode; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.util.ProgressIndicatorUtils; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.util.Comparing; @@ -238,9 +237,6 @@ public class DeferredIconImpl implements DeferredIcon { try { result = nonNull(myEvaluator.fun(myParam)); } - catch (ProcessCanceledException e) { - result = EMPTY_ICON; - } catch (IndexNotReadyException e) { result = EMPTY_ICON; } @@ -357,4 +353,9 @@ public class DeferredIconImpl implements DeferredIcon { Comparing.equal(myParam, ((DeferredIconImpl)icon).myParam) && equalIcons(myDelegateIcon, ((DeferredIconImpl)icon).myDelegateIcon); } + + @Override + public String toString() { + return "Deferred. Base=" + myDelegateIcon; + } } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java index 14c188927d76..391f719a7805 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,6 @@ import com.intellij.ui.tabs.impl.table.TableLayout; import com.intellij.util.PairConsumer; import com.intellij.util.ui.Centerizer; import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; diff --git a/platform/platform-tests/testSrc/com/intellij/util/lang/UrlClassLoaderTest.java b/platform/platform-tests/testSrc/com/intellij/util/lang/UrlClassLoaderTest.java index 407d930e35d6..aa545c678cd2 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/lang/UrlClassLoaderTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/lang/UrlClassLoaderTest.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Random; import java.util.concurrent.Future; import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -119,60 +120,65 @@ public class UrlClassLoaderTest extends TestCase { final int resourceCount = 20; ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(threadCount, ConcurrencyUtil.newNamedThreadFactory("conc loading")); - final Random random = new Random(); - UrlClassLoader.CachePool pool = UrlClassLoader.createCachePool(); - for (int attempt = 0; attempt < attemptCount; attempt++) { - final UrlClassLoader loader = UrlClassLoader.build().urls(urls).parent(null). - useCache(pool, new UrlClassLoader.CachingCondition() { - @Override - public boolean shouldCacheData(@NotNull URL url) { - return true; // fails also without cache pool (but with cache enabled), but takes much longer - } - }).get(); - //if (attempt % 10 == 0) System.out.println("Attempt " + attempt); + try { + final Random random = new Random(); + UrlClassLoader.CachePool pool = UrlClassLoader.createCachePool(); + for (int attempt = 0; attempt < attemptCount; attempt++) { + final UrlClassLoader loader = UrlClassLoader.build().urls(urls).parent(null). + useCache(pool, new UrlClassLoader.CachingCondition() { + @Override + public boolean shouldCacheData(@NotNull URL url) { + return true; // fails also without cache pool (but with cache enabled), but takes much longer + } + }).get(); + //if (attempt % 10 == 0) System.out.println("Attempt " + attempt); - final List namesToLoad = ContainerUtil.newArrayList(); - for (int j = 0; j < resourceCount; j++) { - namesToLoad.add(resourceNames.get(random.nextInt(resourceNames.size()))); - } + final List namesToLoad = ContainerUtil.newArrayList(); + for (int j = 0; j < resourceCount; j++) { + namesToLoad.add(resourceNames.get(random.nextInt(resourceNames.size()))); + } - List futures = ContainerUtil.newArrayList(); - for (int i = 0; i < threadCount; i++) { - futures.add(executor.submit(new Runnable() { - @Override - public void run() { - for (String name : namesToLoad) { - try { - assertNotNull(findResource(name)); - } - catch (Throwable e) { - System.out.println("Failed loading " + name); - throw new RuntimeException(e); + List futures = ContainerUtil.newArrayList(); + for (int i = 0; i < threadCount; i++) { + futures.add(executor.submit(new Runnable() { + @Override + public void run() { + for (String name : namesToLoad) { + try { + assertNotNull(findResource(name)); + } + catch (Throwable e) { + System.out.println("Failed loading " + name); + throw new RuntimeException(e); + } } } - } - private final Random findResourceOrFindResourcesChooser = new Random(); - private URL findResource(String name) { - if (findResourceOrFindResourcesChooser.nextBoolean()) { - try { - Enumeration resources = loader.getResources(name); - assertTrue(resources.hasMoreElements()); - return resources.nextElement(); - } - catch (IOException e) { - throw new RuntimeException(e); + private final Random findResourceOrFindResourcesChooser = new Random(); + private URL findResource(String name) { + if (findResourceOrFindResourcesChooser.nextBoolean()) { + try { + Enumeration resources = loader.getResources(name); + assertTrue(resources.hasMoreElements()); + return resources.nextElement(); + } + catch (IOException e) { + throw new RuntimeException(e); + } } + return loader.findResource(name); } - return loader.findResource(name); - } - })); - } + })); + } - for (Future future : futures) { - future.get(); + for (Future future : futures) { + future.get(); + } } } - + finally { + executor.shutdownNow(); + executor.awaitTermination(1000, TimeUnit.SECONDS); + } } } diff --git a/platform/util/src/com/intellij/util/concurrency/Semaphore.java b/platform/util/src/com/intellij/util/concurrency/Semaphore.java index 5579020af7ed..e0f390fa39f3 100644 --- a/platform/util/src/com/intellij/util/concurrency/Semaphore.java +++ b/platform/util/src/com/intellij/util/concurrency/Semaphore.java @@ -80,7 +80,8 @@ public class Semaphore { sync.acquireSharedInterruptibly(1); } - public boolean waitFor(final long msTimeout) { + // true if semaphore became free + public boolean waitFor(final long msTimeout) { try { return waitForUnsafe(msTimeout); } @@ -89,6 +90,7 @@ public class Semaphore { } } + // true if semaphore became free public boolean waitForUnsafe(long msTimeout) throws InterruptedException { if (sync.tryAcquireShared(1) >= 0) return true; return sync.tryAcquireSharedNanos(1, TimeUnit.MILLISECONDS.toNanos(msTimeout)); diff --git a/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java b/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java index 71f268928625..2c696b50fde6 100644 --- a/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java +++ b/platform/util/testSrc/com/intellij/util/io/BaseOutputReaderTest.java @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -71,6 +72,12 @@ public class BaseOutputReaderTest { @AfterClass public static void tearDown() { ourExecutor.shutdown(); + try { + ourExecutor.awaitTermination(1000, TimeUnit.SECONDS); + } + catch (InterruptedException e) { + throw new RuntimeException(e); + } ourExecutor = null; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index c3574e4d61a2..a147536c2b8e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -65,7 +65,6 @@ import javax.swing.*; import java.io.File; import java.util.*; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.atomic.AtomicReference; /** @@ -86,7 +85,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec ourUpdateAlarm.set(createChangeListExecutor()); } - private static ScheduledThreadPoolExecutor createChangeListExecutor() { + private static ScheduledExecutorService createChangeListExecutor() { return VcsUtil.createExecutor("Change List Updater"); } @@ -95,7 +94,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec private FileHolderComposite myComposite; private ChangeListWorker myWorker; - private VcsException myUpdateException = null; + private VcsException myUpdateException; private Factory myAdditionalInfo; private final EventDispatcher myListeners = EventDispatcher.create(ChangeListListener.class); @@ -466,7 +465,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec final Iterator filesIterator = modifier.getDirtyFilesIterator(); while (filesIterator.hasNext()) { final FilePath dirtyFile = filesIterator.next(); - if ((dirtyFile.getVirtualFile() != null) && isIgnoredFile(dirtyFile.getVirtualFile())) { + if (dirtyFile.getVirtualFile() != null && isIgnoredFile(dirtyFile.getVirtualFile())) { filesIterator.remove(); fileHolder.addFile(dirtyFile.getVirtualFile()); refreshFiles.add(dirtyFile.getVirtualFile()); @@ -477,7 +476,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec final Iterator dirIterator = modifier.getDirtyDirectoriesIterator(root); while (dirIterator.hasNext()) { final FilePath dir = dirIterator.next(); - if ((dir.getVirtualFile() != null) && isIgnoredFile(dir.getVirtualFile())) { + if (dir.getVirtualFile() != null && isIgnoredFile(dir.getVirtualFile())) { dirIterator.remove(); fileHolder.addFile(dir.getVirtualFile()); refreshFiles.add(dir.getVirtualFile()); @@ -531,7 +530,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec myAdditionalInfo = null; } } - final String scopeInString = (!LOG.isDebugEnabled()) ? "" : StringUtil.join(scopes, new Function() { + final String scopeInString = !LOG.isDebugEnabled() ? "" : StringUtil.join(scopes, new Function() { @Override public String fun(VcsDirtyScope scope) { return scope.toString(); @@ -545,7 +544,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec iterateScopes(dataHolder, scopes, wasEverythingDirty); - final boolean takeChanges = (myUpdateException == null); + final boolean takeChanges = myUpdateException == null; if (takeChanges) { // update IDEA-level ignored files updateIgnoredFiles(dataHolder.getComposite()); @@ -696,8 +695,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec private class DataHolder { private final boolean myWasEverythingDirty; - final FileHolderComposite myComposite; - final ChangeListWorker myChangeListWorker; + private final FileHolderComposite myComposite; + private final ChangeListWorker myChangeListWorker; private DataHolder(FileHolderComposite composite, ChangeListWorker changeListWorker, boolean wasEverythingDirty) { myComposite = composite; @@ -705,14 +704,14 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec myWasEverythingDirty = wasEverythingDirty; } - public void notifyStart() { + private void notifyStart() { if (myWasEverythingDirty) { myComposite.cleanAll(); myChangeListWorker.notifyStartProcessingChanges(null); } } - public void notifyStartProcessingChanges(@NotNull final VcsModifiableDirtyScope scope) { + private void notifyStartProcessingChanges(@NotNull final VcsModifiableDirtyScope scope) { if (!myWasEverythingDirty) { myComposite.cleanAndAdjustScope(scope); myChangeListWorker.notifyStartProcessingChanges(scope); @@ -722,13 +721,13 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec myChangeListWorker.notifyVcsStarted(scope.getVcs()); } - public void notifyDoneProcessingChanges() { + private void notifyDoneProcessingChanges() { if (!myWasEverythingDirty) { myChangeListWorker.notifyDoneProcessingChanges(myDelayedNotificator.getProxyDispatcher()); } } - public void notifyEnd() { + void notifyEnd() { if (myWasEverythingDirty) { myChangeListWorker.notifyDoneProcessingChanges(myDelayedNotificator.getProxyDispatcher()); } @@ -738,7 +737,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec return myComposite; } - public ChangeListWorker getChangeListWorker() { + ChangeListWorker getChangeListWorker() { return myChangeListWorker; } } @@ -927,7 +926,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec } } - public Factory getAdditionalUpdateInfo() { + Factory getAdditionalUpdateInfo() { synchronized (myDataLock) { return myAdditionalInfo; } @@ -1258,7 +1257,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec } }); - if (exceptions.size() > 0) { + if (!exceptions.isEmpty()) { StringBuilder message = new StringBuilder(VcsBundle.message("error.adding.files.prompt")); for (VcsException ex : exceptions) { message.append("\n").append(ex.getMessage()); @@ -1292,7 +1291,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec } } - if (changesToMove.size() > 0) { + if (!changesToMove.isEmpty()) { moveChangesTo(list, changesToMove.toArray(new Change[changesToMove.size()])); } } @@ -1389,13 +1388,13 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec } @Override - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public void readExternal(Element element) throws InvalidDataException { if (!myProject.isDefault()) { synchronized (myDataLock) { myIgnoredIdeaLevel.clear(); new ChangeListManagerSerialization(myIgnoredIdeaLevel, myWorker).readExternal(element); - if ((!myWorker.isEmpty()) && getDefaultChangeList() == null) { + if (!myWorker.isEmpty() && getDefaultChangeList() == null) { setDefaultChangeList(myWorker.getListsCopy().get(0)); } } @@ -1442,8 +1441,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec private static class MyDirtyFilesScheduler { private static final int ourPiecesLimit = 100; - final List myFiles = new ArrayList(); - final List myDirs = new ArrayList(); + private final List myFiles = new ArrayList(); + private final List myDirs = new ArrayList(); private boolean myEveryThing; private int myCnt; private final Project myProject;