From a6582b08fa8778b81999935af4c15914fa01db95 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 19 Jan 2012 17:11:41 +0100 Subject: [PATCH 1/6] Fixed exception. --- .../src/com/intellij/openapi/roots/ModuleRootManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-api/src/com/intellij/openapi/roots/ModuleRootManager.java b/platform/lang-api/src/com/intellij/openapi/roots/ModuleRootManager.java index 3c649555f2ad..6acc55da8169 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/ModuleRootManager.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/ModuleRootManager.java @@ -31,7 +31,7 @@ public abstract class ModuleRootManager implements ModuleRootModel { * @param module the module for which the root manager is requested. * @return the root manager instance. */ - public static ModuleRootManager getInstance(Module module) { + public static ModuleRootManager getInstance(@NotNull Module module) { return module.getComponent(ModuleRootManager.class); } From bc145f9516f3be095b96821720e777436366cd0b Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 19 Jan 2012 16:23:04 +0100 Subject: [PATCH 2/6] run configurations for default project exceptions : IDEA-80092 --- .../junit2/configuration/JUnitConfigurationModel.java | 3 ++- .../testng/model/TestNGConfigurationModel.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java index 8e2a57a1eed5..fa23dd183736 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurationModel.java @@ -25,6 +25,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiClass; import javax.swing.text.BadLocationException; @@ -101,7 +102,7 @@ public class JUnitConfigurationModel { testObject != JUnitConfiguration.TEST_DIRECTORY) { try { data.METHOD_NAME = getJUnitTextValue(METHOD); - final PsiClass testClass = JUnitUtil.findPsiClass(className, module, myProject); + final PsiClass testClass = !myProject.isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, myProject) : null; if (testClass != null && testClass.isValid()) { data.setMainClass(testClass); } diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestNGConfigurationModel.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestNGConfigurationModel.java index 6291fbfd6e46..e891db65cb8a 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/model/TestNGConfigurationModel.java +++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestNGConfigurationModel.java @@ -118,7 +118,7 @@ public class TestNGConfigurationModel if (TestType.METHOD == type) data.METHOD_NAME = getText(TestType.METHOD); - PsiClass psiClass = JUnitUtil.findPsiClass(className, module, getProject()); + PsiClass psiClass = !getProject().isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, getProject()) : null; if (psiClass != null && psiClass.isValid()) data.setMainClass(psiClass); else From 62af7e5461fc6f916c65c540d513eaa766480227 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 19 Jan 2012 16:51:54 +0100 Subject: [PATCH 3/6] collect tests: catch exceptions to prevent vm hanging --- .../junit/src/com/intellij/execution/junit/TestPackage.java | 3 +++ .../testng/configuration/SearchingForTestsTask.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 3c75043754eb..b71752c8177e 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -345,6 +345,9 @@ public class TestPackage extends TestObject { catch (IOException e) { LOG.info(e); } + catch (Throwable e) { + LOG.error(e); + } } @Override diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java index a4869e91ec19..5f85cf25d57c 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java @@ -96,6 +96,9 @@ public class SearchingForTestsTask extends Task.Backgroundable { catch (IOException e) { LOG.info(e); } + catch (Throwable e) { + LOG.error(e); + } } @Override From b8c404890b780a2cb77ede55495bbe3484b3c214 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 19 Jan 2012 17:45:52 +0100 Subject: [PATCH 4/6] [peter] for multiple words search optimization: find all ids in the intersection and only then find corresponding vFiles and check scopes, etc isCheapEnough should not check vFiles at all IDEA-77297 --- .../psi/impl/search/PsiSearchHelperImpl.java | 204 +++++++++--------- .../util/indexing/FileBasedIndex.java | 133 +++++++++--- .../vfs/newvfs/persistent/PersistentFS.java | 8 +- .../properties/UnusedPropertyInspection.java | 20 +- .../binding/FormReferencesSearcher.java | 2 +- 5 files changed, 239 insertions(+), 128 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java index 2979a78099c6..676d3b81ba69 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/search/PsiSearchHelperImpl.java @@ -28,9 +28,7 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.roots.FileIndexFacade; -import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; @@ -46,10 +44,11 @@ import com.intellij.util.CommonProcessors; import com.intellij.util.Processor; import com.intellij.util.SmartList; import com.intellij.util.containers.CollectionFactory; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.text.StringSearcher; -import gnu.trove.THashSet; +import gnu.trove.TIntHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -352,8 +351,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { searchContext, caseSensitively, text, - new CommonProcessors.CollectProcessor(result), - progress + new CommonProcessors.CollectProcessor(result) ); LOG.assertTrue(success); return result; @@ -364,81 +362,34 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { } public boolean processFilesWithText(@NotNull final GlobalSearchScope scope, - final short searchContext, - final boolean caseSensitively, - @NotNull String text, - @NotNull final Processor processor, - @Nullable ProgressIndicator progress) { - List words = StringUtil.getWordsIn(text); - if (words.isEmpty()) return true; - Collections.sort(words, new Comparator() { + final short searchContext, + final boolean caseSensitively, + @NotNull String text, + @NotNull final Processor processor) { + final ArrayList entries = getWordEntries(text, caseSensitively); + if (entries.isEmpty()) return true; + + final Collection fileSet = ApplicationManager.getApplication().runReadAction(new Computable>() { @Override - public int compare(String o1, String o2) { - return o2.length() - o1.length(); + public Collection compute() { + final CommonProcessors.CollectProcessor collectProcessor = new CommonProcessors.CollectProcessor(); + FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, entries, scope, new Condition() { + @Override + public boolean value(Integer integer) { + return (integer.intValue() & searchContext) != 0; + } + }, collectProcessor); + return collectProcessor.getResults(); } }); - final Set fileSet; - CacheManager cacheManager = CacheManager.SERVICE.getInstance(myManager.getProject()); - if (words.size() > 1) { - fileSet = new THashSet(); - Set copy = new THashSet(); - for (int i = 0; i < words.size() - 1; i++) { - if (progress != null) { - progress.checkCanceled(); - } - else { - ProgressManager.checkCanceled(); - } - final String word = words.get(i); - final int finalI = i; - cacheManager.collectVirtualFilesWithWord(new CommonProcessors.CollectProcessor(i != 0 ? copy:fileSet) { - @Override - protected boolean accept(VirtualFile virtualFile) { - return finalI == 0 || fileSet.contains(virtualFile); - } - }, word, searchContext, scope, caseSensitively); - if (i != 0) { - fileSet.retainAll(copy); - } - copy.clear(); - if (fileSet.isEmpty()) break; + final FileIndexFacade index = FileIndexFacade.getInstance(myManager.getProject()); + return ContainerUtil.process(fileSet, new ReadActionProcessor() { + @Override + public boolean processInReadAction(VirtualFile virtualFile) { + return !IndexCacheManagerImpl.shouldBeFound(scope, virtualFile, index) || processor.process(virtualFile); } - if (fileSet.isEmpty()) return true; - } - else { - fileSet = null; - } - - final String lastWord = words.get(words.size() - 1); - if (processor instanceof CommonProcessors.CollectProcessor) { - final CommonProcessors.CollectProcessor collectProcessor = (CommonProcessors.CollectProcessor)processor; - return cacheManager.collectVirtualFilesWithWord(new CommonProcessors.CollectProcessor(collectProcessor.getResults()) { - @Override - public boolean process(VirtualFile virtualFile) { - if (fileSet == null || fileSet.contains(virtualFile)) return collectProcessor.process(virtualFile); - return true; - } - }, lastWord, searchContext, scope, caseSensitively); - } else { - THashSet files = new THashSet(); - cacheManager.collectVirtualFilesWithWord(new CommonProcessors.CollectProcessor(files) { - @Override - protected boolean accept(VirtualFile virtualFile) { - return fileSet == null || fileSet.contains(virtualFile); - } - }, lastWord, searchContext, scope, caseSensitively); - ReadActionProcessor readActionProcessor = new ReadActionProcessor() { - @Override - public boolean processInReadAction(VirtualFile virtualFile) { - return processor.process(virtualFile); - } - }; - for(VirtualFile file:files) { - if (!readActionProcessor.process(file)) return false; - } - return true; - } + }); } @Override @@ -725,31 +676,57 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { ProgressIndicator progress) { final FileIndexFacade index = FileIndexFacade.getInstance(myManager.getProject()); final MultiMap result = createMultiMap(); - for (Set key : singles.keySet()) { + for (final Set key : singles.keySet()) { if (key.isEmpty()) { continue; } + final Collection data = singles.get(key); - GlobalSearchScope commonScope = uniteScopes(data); + final GlobalSearchScope commonScope = uniteScopes(data); - MultiMap intersection = null; + if (key.size() == 1) { + result.putAllValues(findFilesWithIndexEntry(key.iterator().next(), index, data, commonScope, progress)); + continue; + } - boolean first = true; - for (IdIndexEntry entry : key) { - final MultiMap local = findFilesWithIndexEntry(entry, index, data, commonScope, progress); - if (first) { - intersection = local; - first = false; + final Collection fileSet = ApplicationManager.getApplication().runReadAction(new Computable>() { + @Override + public Collection compute() { + final CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor(); + FileBasedIndex.getInstance().processFilesContainingAllKeys(IdIndex.NAME, key, commonScope, null, processor); + return processor.getResults(); } - else { - intersection.keySet().retainAll(local.keySet()); - for (VirtualFile file : intersection.keySet()) { - intersection.get(file).retainAll(local.get(file)); - } + }); + + for (final VirtualFile file : fileSet) { + if (progress != null) { + progress.checkCanceled(); + } + for (final IdIndexEntry entry : key) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + FileBasedIndex.getInstance().processValues(IdIndex.NAME, entry, file, new FileBasedIndex.ValueProcessor() { + @Override + public boolean process(VirtualFile file, Integer value) { + if (IndexCacheManagerImpl.shouldBeFound(commonScope, file, index)) { + int mask = value.intValue(); + for (RequestWithProcessor single : data) { + final PsiSearchRequest request = single.request; + if ((mask & request.searchContext) != 0 && ((GlobalSearchScope)request.searchScope).contains(file)) { + result.putValue(file, single); + } + } + } + return true; + } + }, commonScope); + + } + }); } } - result.putAllValues(intersection); } return result; } @@ -853,24 +830,59 @@ public class PsiSearchHelperImpl implements PsiSearchHelper { @Override public SearchCostResult isCheapEnoughToSearch(@NotNull String name, - @NotNull GlobalSearchScope scope, + @NotNull final GlobalSearchScope scope, @Nullable final PsiFile fileToIgnoreOccurencesIn, @Nullable ProgressIndicator progress) { + + final ArrayList keys = getWordEntries(name, true); + if (keys.isEmpty()) return SearchCostResult.ZERO_OCCURRENCES; + + final TIntHashSet set = ApplicationManager.getApplication().runReadAction(new NullableComputable() { + @Override + public TIntHashSet compute() { + return FileBasedIndex.getInstance().collectFileIdsContainingAllKeys(IdIndex.NAME, keys, scope, null); + } + }); + + if (set == null || set.size() > 1000) { + return SearchCostResult.TOO_MANY_OCCURRENCES; + } + final AtomicInteger count = new AtomicInteger(); - if (!processFilesWithText(scope, UsageSearchContext.ANY, true, name, new CommonProcessors.CollectProcessor (Collections.emptyList()) { + + final FileIndexFacade index = FileIndexFacade.getInstance(myManager.getProject()); + final Processor processor = new Processor() { private final VirtualFile fileToIgnoreOccurencesInVirtualFile = - fileToIgnoreOccurencesIn != null ? fileToIgnoreOccurencesIn.getVirtualFile():null; + fileToIgnoreOccurencesIn != null ? fileToIgnoreOccurencesIn.getVirtualFile() : null; @Override public boolean process(VirtualFile file) { if (file == fileToIgnoreOccurencesInVirtualFile) return true; - int value = count.incrementAndGet(); + if (!IndexCacheManagerImpl.shouldBeFound(scope, file, index)) return true; + final int value = count.incrementAndGet(); return value < 10; } - }, progress)) { + }; + final boolean cheap = ApplicationManager.getApplication().runReadAction(new NullableComputable() { + @Override + public Boolean compute() { + return FileBasedIndex.processVirtualFiles(set, scope, processor); + } + }); + + if (!cheap) { return SearchCostResult.TOO_MANY_OCCURRENCES; } return count.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES; } + + private static ArrayList getWordEntries(String name, boolean caseSensitively) { + List words = StringUtil.getWordsIn(name); + final ArrayList keys = new ArrayList(); + for (String word : words) { + keys.add(new IdIndexEntry(word, caseSensitively)); + } + return keys; + } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 9b39245a44a6..ced92a753e96 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -58,10 +58,7 @@ import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.search.EverythingGlobalScope; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.stubs.SerializationManager; -import com.intellij.util.ArrayUtil; -import com.intellij.util.CommonProcessors; -import com.intellij.util.Processor; -import com.intellij.util.SmartList; +import com.intellij.util.*; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.containers.ConcurrentHashSet; import com.intellij.util.containers.ContainerUtil; @@ -73,6 +70,7 @@ import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; import gnu.trove.TIntHashSet; import gnu.trove.TIntIterator; +import gnu.trove.TIntProcedure; import gnu.trove.TObjectIntHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -854,14 +852,16 @@ public class FileBasedIndex implements ApplicationComponent { } - - private boolean processValuesImpl(final ID indexId, final K dataKey, boolean ensureValueProcessedOnce, - @Nullable final VirtualFile restrictToFile, ValueProcessor processor, - final GlobalSearchScope filter) { + + + private R processExceptions(final ID indexId, + @Nullable final VirtualFile restrictToFile, + final GlobalSearchScope filter, + ThrowableConvertor, R, StorageException> computable) { try { final UpdatableIndex index = getIndex(indexId); if (index == null) { - return true; + return null; } final Project project = filter.getProject(); //assert project != null : "GlobalSearchScope#getProject() should be not-null for all index queries"; @@ -869,6 +869,33 @@ public class FileBasedIndex implements ApplicationComponent { try { index.getReadLock().lock(); + return computable.convert(index); + } + finally { + index.getReadLock().unlock(); + } + } + catch (StorageException e) { + scheduleRebuild(indexId, e); + } + catch (RuntimeException e) { + final Throwable cause = getCauseToRebuildIndex(e); + if (cause != null) { + scheduleRebuild(indexId, cause); + } + else { + throw e; + } + } + return null; + } + + private boolean processValuesImpl(final ID indexId, final K dataKey, final boolean ensureValueProcessedOnce, + @Nullable final VirtualFile restrictToFile, final ValueProcessor processor, + final GlobalSearchScope filter) { + ThrowableConvertor, Boolean, StorageException> keyProcessor = new ThrowableConvertor, Boolean, StorageException>() { + @Override + public Boolean convert(UpdatableIndex index) throws StorageException { final ValueContainer container = index.getData(dataKey); boolean shouldContinue = true; @@ -876,7 +903,7 @@ public class FileBasedIndex implements ApplicationComponent { if (restrictToFile != null) { if (restrictToFile instanceof VirtualFileWithId) { final int restrictedFileId = getFileId(restrictToFile); - for (final Iterator valueIt = container.getValueIterator(); valueIt.hasNext();) { + for (final Iterator valueIt = container.getValueIterator(); valueIt.hasNext(); ) { final V value = valueIt.next(); if (container.isAssociated(value, restrictedFileId)) { shouldContinue = processor.process(restrictToFile, value); @@ -908,23 +935,79 @@ public class FileBasedIndex implements ApplicationComponent { } return shouldContinue; } - finally { - index.getReadLock().unlock(); - } + }; + final Boolean result = processExceptions(indexId, restrictToFile, filter, keyProcessor); + return result == null || result.booleanValue(); + } + + public void processFilesContainingAllKeys(final ID indexId, + final Collection dataKeys, + final GlobalSearchScope filter, + @Nullable Condition valueChecker, + final Processor processor) { + final TIntHashSet set = collectFileIdsContainingAllKeys(indexId, dataKeys, filter, valueChecker); + if (set != null) { + processVirtualFiles(set, filter, processor); } - catch (StorageException e) { - scheduleRebuild(indexId, e); - } - catch (RuntimeException e) { - final Throwable cause = getCauseToRebuildIndex(e); - if (cause != null) { - scheduleRebuild(indexId, cause); + } + + @Nullable + public TIntHashSet collectFileIdsContainingAllKeys(final ID indexId, + final Collection dataKeys, + final GlobalSearchScope filter, + @Nullable final Condition valueChecker) { + final ThrowableConvertor, TIntHashSet, StorageException> convertor = + new ThrowableConvertor, TIntHashSet, StorageException>() { + @Nullable + @Override + public TIntHashSet convert(UpdatableIndex index) throws StorageException { + TIntHashSet mainIntersection = null; + + for (K dataKey : dataKeys) { + ProgressManager.checkCanceled(); + TIntHashSet copy = new TIntHashSet(); + final ValueContainer container = index.getData(dataKey); + + for (final Iterator valueIt = container.getValueIterator(); valueIt.hasNext(); ) { + final V value = valueIt.next(); + if (valueChecker != null && !valueChecker.value(value)) { + continue; + } + for (final ValueContainer.IntIterator inputIdsIterator = container.getInputIdsIterator(value); inputIdsIterator.hasNext(); ) { + final int id = inputIdsIterator.next(); + if (mainIntersection == null || mainIntersection.contains(id)) { + copy.add(id); + } + } + } + + mainIntersection = copy; + if (mainIntersection.isEmpty()) { + return new TIntHashSet(); + } + } + + return mainIntersection; + } + }; + + + return processExceptions(indexId, null, filter, convertor); + } + + public static boolean processVirtualFiles(TIntHashSet ids, final GlobalSearchScope filter, final Processor processor) { + final PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); + return ids.forEach(new TIntProcedure() { + @Override + public boolean execute(int id) { + ProgressManager.checkCanceled(); + VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id); + if (file != null && filter.accept(file)) { + return processor.process(file); + } + return true; } - else { - throw e; - } - } - return true; + }); } public static @Nullable Throwable getCauseToRebuildIndex(RuntimeException e) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java index 5ff8142dff13..e6f3a2ab49e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS.java @@ -70,6 +70,7 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { private final MessageBus myEventsBus; private final Map myRoots = new HashMap(); + private final Map myRootsById = new HashMap(); private VirtualFileSystemEntry myFakeRoot; private final Object INPUT_LOCK = new Object(); @@ -770,6 +771,7 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { if (basePath.length() > 0) { myRoots.put(rootUrl, root); + myRootsById.put(root.getId(), root); } else { myFakeRoot = root; @@ -861,10 +863,7 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { final int parentId = getParent(id); if (parentId == 0) { synchronized (LOCK) { - for (NewVirtualFile root : myRoots.values()) { - if (root.getId() == id) return root; - } - return null; + return myRootsById.get(id); } } else { @@ -992,6 +991,7 @@ public class PersistentFS extends ManagingFS implements ApplicationComponent { else { synchronized (LOCK) { myRoots.remove(file.getUrl()); + myRootsById.remove(id); try { FSRecords.deleteRootRecord(id); } diff --git a/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java b/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java index dca886a3727a..2d2a48c23244 100644 --- a/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java +++ b/plugins/properties/src/com/intellij/lang/properties/UnusedPropertyInspection.java @@ -24,12 +24,18 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.psi.*; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiReference; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.searches.ReferencesSearch; import org.jetbrains.annotations.NotNull; +import java.util.List; + /** * @author cdr */ @@ -69,7 +75,17 @@ public class UnusedPropertyInspection extends PropertySuppressableInspectionBase String name = property.getName(); if (name == null) return; - PsiSearchHelper.SearchCostResult cheapEnough = searchHelper.isCheapEnoughToSearch(name, searchScope, file, original); + + final List words = StringUtil.getWordsIn(name); + if (words.isEmpty()) { + return; + } + + final String lastWord = words.get(words.size() - 1); + PsiSearchHelper.SearchCostResult cheapEnough = searchHelper.isCheapEnoughToSearch(lastWord, searchScope, file, original); + if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return; + + cheapEnough = searchHelper.isCheapEnoughToSearch(name, searchScope, file, original); if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return; final PsiReference usage = cheapEnough == PsiSearchHelper.SearchCostResult.ZERO_OCCURRENCES ? null : diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferencesSearcher.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferencesSearcher.java index 07a7359e4cb2..179f47d57a47 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferencesSearcher.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormReferencesSearcher.java @@ -252,7 +252,7 @@ public class FormReferencesSearcher implements QueryExecutor Date: Wed, 18 Jan 2012 20:29:08 +0100 Subject: [PATCH 5/6] test killability, take 2 --- .../util/indexing/FileBasedIndex.java | 7 ++++++- .../application/impl/ApplicationImpl.java | 2 +- .../testFramework/LightPlatformTestCase.java | 2 +- .../openapi/util/ShutDownTracker.java | 21 ++++++++++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index ced92a753e96..a8262f35ff6c 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -316,7 +316,12 @@ public class FileBasedIndex implements ApplicationComponent { ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { @Override public void run() { - performShutdown(); + ShutDownTracker.invokeAndWait(ApplicationManager.getApplication().isUnitTestMode(), false, new Runnable() { + @Override + public void run() { + performShutdown(); + } + }); } }); //FileUtil.createIfDoesntExist(workInProgressFile); diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 0743dafcb11e..feeabc285a35 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -285,7 +285,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application if (isDisposed() || isDisposeInProgress()) { return; } - ShutDownTracker.invokeAndWait(isUnitTestMode(), new Runnable() { + ShutDownTracker.invokeAndWait(isUnitTestMode(), true, new Runnable() { public void run() { if (ApplicationManager.getApplication() != ApplicationImpl.this) return; try { diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 90d5833dd09d..3165c27634dc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -735,7 +735,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { @Override public void run() { - ShutDownTracker.invokeAndWait(true, new Runnable() { + ShutDownTracker.invokeAndWait(true, true, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { diff --git a/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java b/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java index b4b50d0e4cf4..8cee75fb6bc2 100644 --- a/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java +++ b/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java @@ -133,7 +133,26 @@ public class ShutDownTracker implements Runnable { return list.isEmpty()? null : list.removeLast(); } - public static void invokeAndWait(boolean timed, final Runnable runnable) { + public static void invokeAndWait(boolean timed, boolean edt, final Runnable runnable) { + if (!edt) { + if (!timed) { + runnable.run(); + } + + final Semaphore semaphore = new Semaphore(); + semaphore.down(); + new Thread(new Runnable() { + @Override + public void run() { + runnable.run(); + semaphore.up(); + } + }).start(); + semaphore.waitFor(1000); + + return; + } + if (timed) { final Semaphore semaphore = new Semaphore(); semaphore.down(); From b2d1f65b56ffb07cdb45c44259a07638177fd365 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 19 Jan 2012 18:09:26 +0100 Subject: [PATCH 6/6] enable some useful groovy inspections by default --- .../bugs/GroovyConstructorNamedArgumentsInspection.java | 5 +++++ .../GroovyConditionalWithIdenticalBranchesInspection.java | 4 ++++ .../GroovyIfStatementWithIdenticalBranchesInspection.java | 4 ++++ .../exception/GroovyUnusedCatchParameterInspection.java | 4 ++++ .../GroovyAccessToStaticFieldLockedOnInstanceInspection.java | 4 ++++ .../GroovySynchronizationOnNonFinalFieldInspection.java | 4 ++++ ...ronizationOnVariableInitializedWithLiteralInspection.java | 4 ++++ ...chronizedMethodOverridesSynchronizedMethodInspection.java | 5 +++++ .../validity/GroovyDuplicateSwitchBranchInspection.java | 4 ++++ 9 files changed, 38 insertions(+) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyConstructorNamedArgumentsInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyConstructorNamedArgumentsInspection.java index 45725393274c..4950e316c5c8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyConstructorNamedArgumentsInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/bugs/GroovyConstructorNamedArgumentsInspection.java @@ -45,6 +45,11 @@ import java.util.List; */ public class GroovyConstructorNamedArgumentsInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } + @Override protected BaseInspectionVisitor buildVisitor() { return new MyVisitor(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConditionalWithIdenticalBranchesInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConditionalWithIdenticalBranchesInspection.java index 27ce86a987db..7d2c625cc395 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConditionalWithIdenticalBranchesInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyConditionalWithIdenticalBranchesInspection.java @@ -28,6 +28,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCondit import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; public class GroovyConditionalWithIdenticalBranchesInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @NotNull public String getDisplayName() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyIfStatementWithIdenticalBranchesInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyIfStatementWithIdenticalBranchesInspection.java index b4149c88c3b5..ecc473a23c4d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyIfStatementWithIdenticalBranchesInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/control/GroovyIfStatementWithIdenticalBranchesInspection.java @@ -28,6 +28,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; public class GroovyIfStatementWithIdenticalBranchesInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @NotNull public String getDisplayName() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/exception/GroovyUnusedCatchParameterInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/exception/GroovyUnusedCatchParameterInspection.java index 8a2e10b158db..7c6165eaeeab 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/exception/GroovyUnusedCatchParameterInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/exception/GroovyUnusedCatchParameterInspection.java @@ -25,6 +25,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; public class GroovyUnusedCatchParameterInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @Nls @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyAccessToStaticFieldLockedOnInstanceInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyAccessToStaticFieldLockedOnInstanceInspection.java index 2ece624af6dd..e39a99a645ab 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyAccessToStaticFieldLockedOnInstanceInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyAccessToStaticFieldLockedOnInstanceInspection.java @@ -32,6 +32,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe public class GroovyAccessToStaticFieldLockedOnInstanceInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @Nls @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnNonFinalFieldInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnNonFinalFieldInspection.java index ba5942e83714..ca35d8b08d0c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnNonFinalFieldInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnNonFinalFieldInspection.java @@ -29,6 +29,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; public class GroovySynchronizationOnNonFinalFieldInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @Nls @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnVariableInitializedWithLiteralInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnVariableInitializedWithLiteralInspection.java index b3e1d04a21de..4a5d8cba7767 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnVariableInitializedWithLiteralInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovySynchronizationOnVariableInitializedWithLiteralInspection.java @@ -28,6 +28,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral; public class GroovySynchronizationOnVariableInitializedWithLiteralInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @Nls @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyUnsynchronizedMethodOverridesSynchronizedMethodInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyUnsynchronizedMethodOverridesSynchronizedMethodInspection.java index 8ab22c682b0a..ae311643e4c7 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyUnsynchronizedMethodOverridesSynchronizedMethodInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/threading/GroovyUnsynchronizedMethodOverridesSynchronizedMethodInspection.java @@ -26,6 +26,11 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe public class GroovyUnsynchronizedMethodOverridesSynchronizedMethodInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } + @Nls @NotNull public String getGroupDisplayName() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/validity/GroovyDuplicateSwitchBranchInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/validity/GroovyDuplicateSwitchBranchInspection.java index 1115f85f17bc..79fdc4ed3ee8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/validity/GroovyDuplicateSwitchBranchInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/validity/GroovyDuplicateSwitchBranchInspection.java @@ -31,6 +31,10 @@ import java.util.HashSet; import java.util.Set; public class GroovyDuplicateSwitchBranchInspection extends BaseInspection { + @Override + public boolean isEnabledByDefault() { + return true; + } @Nls @NotNull