mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
process() method in SubIndex
This commit is contained in:
+26
-21
@@ -43,6 +43,7 @@ import com.intellij.ui.popup.list.ListPopupImpl;
|
||||
import com.intellij.ui.popup.list.PopupListElementRenderer;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -96,34 +97,38 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
@NotNull
|
||||
private List<PsiMethod> getMethodsToImport() {
|
||||
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myMethodCall.getProject());
|
||||
PsiMethodCallExpression element = myMethodCall.getElement();
|
||||
final PsiMethodCallExpression element = myMethodCall.getElement();
|
||||
PsiReferenceExpression reference = element.getMethodExpression();
|
||||
PsiExpressionList argumentList = element.getArgumentList();
|
||||
final PsiExpressionList argumentList = element.getArgumentList();
|
||||
String name = reference.getReferenceName();
|
||||
List<PsiMethod> list = new ArrayList<PsiMethod>();
|
||||
final List<PsiMethod> list = new ArrayList<PsiMethod>();
|
||||
if (name == null) return list;
|
||||
GlobalSearchScope scope = element.getResolveScope();
|
||||
PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, 20);
|
||||
List<PsiMethod> applicableList = new ArrayList<PsiMethod>();
|
||||
|
||||
final List<PsiMethod> applicableList = new ArrayList<PsiMethod>();
|
||||
final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(element.getProject()).getResolveHelper();
|
||||
for (PsiMethod method : methods) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (JavaCompletionUtil.isInExcludedPackage(method, false)) continue;
|
||||
if (!method.hasModifierProperty(PsiModifier.STATIC)) continue;
|
||||
PsiFile file = method.getContainingFile();
|
||||
if (file instanceof PsiJavaFile
|
||||
//do not show methods from default package
|
||||
&& ((PsiJavaFile)file).getPackageName().length() != 0
|
||||
&& PsiUtil.isAccessible(method, element, method.getContainingClass())) {
|
||||
list.add(method);
|
||||
PsiSubstitutor substitutorForMethod = resolveHelper
|
||||
.inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(), argumentList.getExpressions(),
|
||||
PsiSubstitutor.EMPTY, element.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
|
||||
applicableList.add(method);
|
||||
cache.processMethodsWithName(name, scope, new Processor<PsiMethod>() {
|
||||
@Override
|
||||
public boolean process(PsiMethod method) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (JavaCompletionUtil.isInExcludedPackage(method, false)
|
||||
|| !method.hasModifierProperty(PsiModifier.STATIC)) return true;
|
||||
PsiFile file = method.getContainingFile();
|
||||
if (file instanceof PsiJavaFile
|
||||
//do not show methods from default package
|
||||
&& !((PsiJavaFile)file).getPackageName().isEmpty()
|
||||
&& PsiUtil.isAccessible(method, element, method.getContainingClass())) {
|
||||
list.add(method);
|
||||
PsiSubstitutor substitutorForMethod = resolveHelper
|
||||
.inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(), argumentList.getExpressions(),
|
||||
PsiSubstitutor.EMPTY, element.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
|
||||
applicableList.add(method);
|
||||
}
|
||||
}
|
||||
return (applicableList.isEmpty() ? list : applicableList).size() < 50;
|
||||
}
|
||||
}
|
||||
});
|
||||
List<PsiMethod> result = applicableList.isEmpty() ? list : applicableList;
|
||||
for (int i = result.size() - 1; i >= 0; i--) {
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -122,7 +123,7 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
|
||||
}
|
||||
}
|
||||
PsiMethod[] result = merger == null ? null : merger.getResult();
|
||||
return result != null ? result : PsiMethod.EMPTY_ARRAY;
|
||||
return result == null ? PsiMethod.EMPTY_ARRAY : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,14 +131,25 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
|
||||
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) {
|
||||
Merger<PsiMethod> merger = null;
|
||||
for (PsiShortNamesCache cache : myCacheArray) {
|
||||
PsiMethod[] classes = cache.getMethodsByNameIfNotMoreThan(name, scope, maxCount);
|
||||
if (classes.length != 0) {
|
||||
PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, maxCount);
|
||||
if (methods.length == maxCount) return methods;
|
||||
if (methods.length != 0) {
|
||||
if (merger == null) merger = new Merger<PsiMethod>();
|
||||
merger.add(classes);
|
||||
merger.add(methods);
|
||||
}
|
||||
}
|
||||
PsiMethod[] result = merger == null ? null : merger.getResult();
|
||||
return result != null ? result : PsiMethod.EMPTY_ARRAY;
|
||||
return result == null ? PsiMethod.EMPTY_ARRAY : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processMethodsWithName(@NonNls @NotNull String name,
|
||||
@NotNull GlobalSearchScope scope,
|
||||
@NotNull Processor<PsiMethod> processor) {
|
||||
for (PsiShortNamesCache cache : myCacheArray) {
|
||||
if (!cache.processMethodsWithName(name, scope, processor)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -195,8 +207,8 @@ public class CompositeShortNamesCache extends PsiShortNamesCache {
|
||||
private T[] mySingleItem = null;
|
||||
private Set<T> myAllItems = null;
|
||||
|
||||
public void add(T[] items) {
|
||||
if (items == null || items.length == 0) return;
|
||||
public void add(@NotNull T[] items) {
|
||||
if (items.length == 0) return;
|
||||
if (mySingleItem == null) {
|
||||
mySingleItem = items;
|
||||
return;
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class EmptyShortNamesCacheImpl extends PsiShortNamesCache {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] getClassesByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getAllClassNames() {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllClassNames(@NotNull HashSet<String> dest) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiMethod[] getMethodsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
|
||||
return PsiMethod.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) {
|
||||
return PsiMethod.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getAllMethodNames() {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllMethodNames(@NotNull HashSet<String> set) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiField[] getFieldsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
|
||||
return PsiField.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getAllFieldNames() {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllFieldNames(@NotNull HashSet<String> set) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,9 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.psi.stubs.StubIndex;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
@@ -109,8 +112,7 @@ class PsiShortNamesCacheImpl extends PsiShortNamesCache {
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiMethod[] getMethodsByName(@NotNull String name, @NotNull final GlobalSearchScope scope) {
|
||||
final Collection<PsiMethod> methods =
|
||||
StubIndex.getInstance().get(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope);
|
||||
Collection<PsiMethod> methods = StubIndex.getInstance().get(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope);
|
||||
if (methods.isEmpty()) return PsiMethod.EMPTY_ARRAY;
|
||||
|
||||
List<PsiMethod> list = filterMembers(methods, scope);
|
||||
@@ -121,7 +123,24 @@ class PsiShortNamesCacheImpl extends PsiShortNamesCache {
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) {
|
||||
return getMethodsByName(name, scope); // TODO!!!
|
||||
final List<PsiMethod> methods = new SmartList<PsiMethod>();
|
||||
StubIndex.getInstance().process(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, new CommonProcessors.CollectProcessor<PsiMethod>(methods){
|
||||
@Override
|
||||
public boolean process(PsiMethod method) {
|
||||
return methods.size() != maxCount && super.process(method);
|
||||
}
|
||||
});
|
||||
if (methods.isEmpty()) return PsiMethod.EMPTY_ARRAY;
|
||||
|
||||
List<PsiMethod> list = filterMembers(methods, scope);
|
||||
return list.toArray(new PsiMethod[list.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processMethodsWithName(@NonNls @NotNull String name,
|
||||
@NotNull GlobalSearchScope scope,
|
||||
@NotNull Processor<PsiMethod> processor) {
|
||||
return StubIndex.getInstance().process(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, processor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,7 +179,7 @@ class PsiShortNamesCacheImpl extends PsiShortNamesCache {
|
||||
}
|
||||
|
||||
private <T extends PsiMember> List<T> filterMembers(Collection<T> members, final GlobalSearchScope scope) {
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> result = new ArrayList<T>(members.size());
|
||||
Set<PsiMember> set = new THashSet<PsiMember>(members.size(), new TObjectHashingStrategy<PsiMember>() {
|
||||
@Override
|
||||
public int computeHashCode(PsiMember member) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -28,7 +29,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Allows to retrieve files and Java classes, methods and fields in a project by
|
||||
* non-qualified names.
|
||||
*
|
||||
* @see JavaPsiFacade#getShortNamesCache()
|
||||
*/
|
||||
public abstract class PsiShortNamesCache {
|
||||
/**
|
||||
@@ -105,6 +105,8 @@ public abstract class PsiShortNamesCache {
|
||||
@NotNull
|
||||
public abstract PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope, int maxCount);
|
||||
|
||||
public abstract boolean processMethodsWithName(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope, @NotNull Processor<PsiMethod> processor);
|
||||
|
||||
/**
|
||||
* Returns the list of names of all methods in the project and
|
||||
* (optionally) libraries.
|
||||
|
||||
@@ -23,12 +23,12 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class StubIndex {
|
||||
|
||||
private static class StubIndexHolder {
|
||||
private static final StubIndex ourInstance = ApplicationManager.getApplication().getComponent(StubIndex.class);
|
||||
}
|
||||
@@ -39,8 +39,15 @@ public abstract class StubIndex {
|
||||
|
||||
public abstract <Key, Psi extends PsiElement> Collection<Psi> get(@NotNull StubIndexKey<Key, Psi> indexKey,
|
||||
@NotNull Key key,
|
||||
final Project project,
|
||||
@NotNull Project project,
|
||||
final GlobalSearchScope scope);
|
||||
|
||||
public abstract <Key> Collection<Key> getAllKeys(StubIndexKey<Key, ?> indexKey, @NotNull Project project);
|
||||
public abstract <Key, Psi extends PsiElement> boolean process(@NotNull StubIndexKey<Key, Psi> indexKey,
|
||||
@NotNull Key key,
|
||||
@NotNull Project project,
|
||||
GlobalSearchScope scope,
|
||||
@NotNull Processor<? super Psi> processor);
|
||||
|
||||
@NotNull
|
||||
public abstract <Key> Collection<Key> getAllKeys(@NotNull StubIndexKey<Key, ?> indexKey, @NotNull Project project);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.IStubFileElementType;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.indexing.*;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
@@ -104,7 +106,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
return (StubIndexImpl)getInstance();
|
||||
}
|
||||
|
||||
private <K> boolean registerIndexer(final StubIndexExtension<K, ?> extension, final boolean forceClean) throws IOException {
|
||||
private <K> boolean registerIndexer(@NotNull StubIndexExtension<K, ?> extension, final boolean forceClean) throws IOException {
|
||||
final StubIndexKey<K, ?> indexKey = extension.getKey();
|
||||
final int version = extension.getVersion();
|
||||
myIndexIdToVersionMap.put(indexKey, version);
|
||||
@@ -142,7 +144,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
|
||||
private static class StubIdExternalizer implements DataExternalizer<TIntArrayList> {
|
||||
@Override
|
||||
public void save(final DataOutput out, final TIntArrayList value) throws IOException {
|
||||
public void save(final DataOutput out, @NotNull final TIntArrayList value) throws IOException {
|
||||
int size = value.size();
|
||||
if (size == 0) {
|
||||
DataInputOutputUtil.writeSINT(out, Integer.MAX_VALUE);
|
||||
@@ -158,6 +160,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TIntArrayList read(final DataInput in) throws IOException {
|
||||
int size = DataInputOutputUtil.readSINT(in);
|
||||
@@ -179,17 +182,28 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <Key, Psi extends PsiElement> Collection<Psi> get(@NotNull final StubIndexKey<Key, Psi> indexKey,
|
||||
@NotNull final Key key,
|
||||
@NotNull final Project project,
|
||||
final GlobalSearchScope scope) {
|
||||
final List<Psi> result = new SmartList<Psi>();
|
||||
process(indexKey, key, project, scope, new CommonProcessors.CollectProcessor<Psi>(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Key, Psi extends PsiElement> boolean process(@NotNull final StubIndexKey<Key, Psi> indexKey,
|
||||
@NotNull final Key key,
|
||||
@NotNull final Project project,
|
||||
@Nullable final GlobalSearchScope scope,
|
||||
@NotNull final Processor<? super Psi> processor) {
|
||||
FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, scope);
|
||||
|
||||
final PersistentFS fs = (PersistentFS)ManagingFS.getInstance();
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
|
||||
final List<Psi> result = new SmartList<Psi>();
|
||||
final MyIndex<Key> index = (MyIndex<Key>)myIndices.get(indexKey);
|
||||
|
||||
try {
|
||||
@@ -201,14 +215,14 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
|
||||
final FileBasedIndex.ProjectIndexableFilesFilter projectFilesFilter = FileBasedIndex.getInstance().projectIndexableFiles(project);
|
||||
|
||||
container.forEach(new ValueContainer.ContainerAction<TIntArrayList>() {
|
||||
return container.forEach(new ValueContainer.ContainerAction<TIntArrayList>() {
|
||||
@Override
|
||||
public void perform(final int id, final TIntArrayList value) {
|
||||
public boolean perform(final int id, @NotNull final TIntArrayList value) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (projectFilesFilter != null && !projectFilesFilter.contains(id)) return;
|
||||
if (projectFilesFilter != null && !projectFilesFilter.contains(id)) return true;
|
||||
final VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id);
|
||||
if (file == null || scope != null && !scope.contains(file)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
StubTree stubTree = null;
|
||||
|
||||
@@ -226,12 +240,12 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
|
||||
if (stubTree == null && psiFile == null) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if (stubTree == null) {
|
||||
stubTree = StubTreeLoader.getInstance().readFromVFile(project, file);
|
||||
if (stubTree == null) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
final List<StubElement<?>> plained = stubTree.getPlainList();
|
||||
for (int i = 0; i < value.size(); i++) {
|
||||
@@ -240,7 +254,8 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
|
||||
if (tree != null) {
|
||||
if (tree.getElementType() == stubType(stub)) {
|
||||
result.add((Psi)tree.getPsi());
|
||||
Psi psi = (Psi)tree.getPsi();
|
||||
if (!processor.process(psi)) return false;
|
||||
}
|
||||
else {
|
||||
String persistedStubTree = ((PsiFileStubImpl)stubTree.getRoot()).printTree();
|
||||
@@ -275,9 +290,11 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
else {
|
||||
final List<StubElement<?>> plained = stubTree.getPlainList();
|
||||
for (int i = 0; i < value.size(); i++) {
|
||||
result.add((Psi)plained.get(value.get(i)).getPsi());
|
||||
Psi psi = (Psi)plained.get(value.get(i)).getPsi();
|
||||
if (!processor.process(psi)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -299,10 +316,10 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IElementType stubType(final StubElement<?> stub) {
|
||||
private static IElementType stubType(@NotNull final StubElement<?> stub) {
|
||||
if (stub instanceof PsiFileStub) {
|
||||
return ((PsiFileStub)stub).getType();
|
||||
}
|
||||
@@ -310,7 +327,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
return stub.getStubType();
|
||||
}
|
||||
|
||||
private static void forceRebuild(Throwable e) {
|
||||
private static void forceRebuild(@NotNull Throwable e) {
|
||||
LOG.info(e);
|
||||
requestRebuild();
|
||||
FileBasedIndex.getInstance().scheduleRebuild(StubUpdatingIndex.INDEX_ID, e);
|
||||
@@ -321,7 +338,8 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> Collection<K> getAllKeys(final StubIndexKey<K, ?> indexKey, @NotNull Project project) {
|
||||
@NotNull
|
||||
public <K> Collection<K> getAllKeys(@NotNull StubIndexKey<K, ?> indexKey, @NotNull Project project) {
|
||||
FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, GlobalSearchScope.allScope(project));
|
||||
|
||||
final MyIndex<K> index = (MyIndex<K>)myIndices.get(indexKey);
|
||||
@@ -408,6 +426,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexState getState() {
|
||||
return new StubIndexState(myIndices.keySet());
|
||||
@@ -431,7 +450,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
index.flush();
|
||||
}
|
||||
|
||||
public <K> void updateIndex(StubIndexKey key, int fileId, final Map<K, TIntArrayList> oldValues, Map<K, TIntArrayList> newValues) {
|
||||
public <K> void updateIndex(@NotNull StubIndexKey key, int fileId, @NotNull final Map<K, TIntArrayList> oldValues, @NotNull Map<K, TIntArrayList> newValues) {
|
||||
try {
|
||||
final MyIndex<K> index = (MyIndex<K>)myIndices.get(key);
|
||||
index.updateWithMap(fileId, newValues, new Callable<Collection<K>>() {
|
||||
@@ -453,16 +472,16 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWithMap(final int inputId, final Map<K, TIntArrayList> newData, Callable<Collection<K>> oldKeysGetter) throws StorageException {
|
||||
public void updateWithMap(final int inputId, @NotNull final Map<K, TIntArrayList> newData, @NotNull Callable<Collection<K>> oldKeysGetter) throws StorageException {
|
||||
super.updateWithMap(inputId, newData, oldKeysGetter);
|
||||
}
|
||||
}
|
||||
|
||||
public static <Key, Psi extends PsiElement> Collection<Psi> safeGet(@NotNull StubIndexKey<Key, Psi> indexKey,
|
||||
@NotNull Key key,
|
||||
final Project project,
|
||||
@NotNull final Project project,
|
||||
final GlobalSearchScope scope,
|
||||
Class<Psi> requiredClass) {
|
||||
@NotNull Class<Psi> requiredClass) {
|
||||
Collection<Psi> collection = getInstance().get(indexKey, key, project, scope);
|
||||
for (Iterator<Psi> iterator = collection.iterator(); iterator.hasNext(); ) {
|
||||
Psi psi = iterator.next();
|
||||
|
||||
@@ -152,15 +152,17 @@ class ChangeTrackingValueContainer<Value> extends UpdatableValueContainer<Value>
|
||||
});
|
||||
myRemoved.forEach(new ContainerAction<Value>() {
|
||||
@Override
|
||||
public void perform(final int id, final Value value) {
|
||||
public boolean perform(final int id, final Value value) {
|
||||
newMerged.removeValue(id, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
myAdded.forEach(new ContainerAction<Value>() {
|
||||
@Override
|
||||
public void perform(final int id, final Value value) {
|
||||
public boolean perform(final int id, final Value value) {
|
||||
newMerged.removeAssociatedValue(id); // enforcing "one-value-per-file for particular key" invariant
|
||||
newMerged.addValue(id, value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
setNeedsCompacting(fromDisk.needsCompacting());
|
||||
@@ -171,7 +173,7 @@ class ChangeTrackingValueContainer<Value> extends UpdatableValueContainer<Value>
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return myAdded.size() > 0 || myRemoved.size() > 0 || myInvalidated.size() > 0 || needsCompacting();
|
||||
return myAdded.size() > 0 || myRemoved.size() > 0 || !myInvalidated.isEmpty() || needsCompacting();
|
||||
}
|
||||
|
||||
public ValueContainer<Value> getAddedDelta() {
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class ValueContainer<Value> {
|
||||
int size();
|
||||
}
|
||||
|
||||
static abstract class IntPredicate {
|
||||
abstract static class IntPredicate {
|
||||
abstract boolean contains(int id);
|
||||
}
|
||||
|
||||
@@ -50,16 +50,17 @@ public abstract class ValueContainer<Value> {
|
||||
|
||||
|
||||
public interface ContainerAction<T> {
|
||||
void perform(int id, T value);
|
||||
boolean perform(int id, T value);
|
||||
}
|
||||
|
||||
public final void forEach(final ContainerAction<Value> action) {
|
||||
public final boolean forEach(final ContainerAction<Value> action) {
|
||||
for (final Iterator<Value> valueIterator = getValueIterator(); valueIterator.hasNext();) {
|
||||
final Value value = valueIterator.next();
|
||||
for (final IntIterator intIterator = getInputIdsIterator(value); intIterator.hasNext();) {
|
||||
action.perform(intIterator.next(), value);
|
||||
if (!action.perform(intIterator.next(), value)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private volatile boolean myNeedsCompacting = false;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.psi.stubs.StubIndex;
|
||||
import com.intellij.psi.stubs.StubIndexImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
@@ -55,6 +56,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
|
||||
return ObjectUtils.assertNotNull(ContainerUtil.findInstance(project.getExtensions(PsiShortNamesCache.EP_NAME), GroovyShortNamesCache.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] getClassesByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
|
||||
Collection<PsiClass> allClasses = getAllScriptClasses(name, scope);
|
||||
@@ -114,16 +116,19 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getAllClassNames() {
|
||||
return ArrayUtil.toStringArray(StubIndex.getInstance().getAllKeys(GrScriptClassNameIndex.KEY, myProject));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getAllClassNames(@NotNull HashSet<String> dest) {
|
||||
dest.addAll(StubIndex.getInstance().getAllKeys(GrScriptClassNameIndex.KEY, myProject));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiMethod[] getMethodsByName(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope) {
|
||||
final Collection<? extends PsiMethod> methods = StubIndex.getInstance().get(GrMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
|
||||
@@ -132,11 +137,22 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
|
||||
return ArrayUtil.mergeCollections(annMethods, methods, PsiMethod.ARRAY_FACTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processMethodsWithName(@NonNls @NotNull String name,
|
||||
@NotNull GlobalSearchScope scope,
|
||||
@NotNull Processor<PsiMethod> processor) {
|
||||
GrSourceFilterScope filterScope = new GrSourceFilterScope(scope);
|
||||
return StubIndex.getInstance().process(GrMethodNameIndex.KEY, name, myProject, filterScope, processor) &&
|
||||
StubIndex.getInstance().process(GrAnnotationMethodNameIndex.KEY, name, myProject, filterScope, processor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope, int maxCount) {
|
||||
return getMethodsByName(name, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getAllMethodNames() {
|
||||
Collection<String> keys = StubIndex.getInstance().getAllKeys(GrMethodNameIndex.KEY, myProject);
|
||||
@@ -144,10 +160,12 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
|
||||
return ArrayUtil.toStringArray(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllMethodNames(@NotNull HashSet<String> set) {
|
||||
set.addAll(StubIndex.getInstance().getAllKeys(GrMethodNameIndex.KEY, myProject));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiField[] getFieldsByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
|
||||
final Collection<? extends PsiField> fields = StubIndex.getInstance().get(GrFieldNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
|
||||
@@ -155,12 +173,14 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
|
||||
return fields.toArray(new PsiField[fields.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getAllFieldNames() {
|
||||
Collection<String> fields = StubIndex.getInstance().getAllKeys(GrFieldNameIndex.KEY, myProject);
|
||||
return ArrayUtil.toStringArray(fields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllFieldNames(@NotNull HashSet<String> set) {
|
||||
set.addAll(StubIndex.getInstance().getAllKeys(GrFieldNameIndex.KEY, myProject));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user