Cleanup (formatting)

This commit is contained in:
Roman Shevchenko
2017-06-06 16:02:54 +03:00
parent acc2b2160f
commit c7d9371ec4
3 changed files with 81 additions and 95 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -33,7 +33,6 @@ import com.intellij.util.indexing.IdFilter;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -60,11 +59,11 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
@NotNull
public PsiClass[] getClassesByName(@NotNull String name, @NotNull final GlobalSearchScope scope) {
final Collection<PsiClass> classes = JavaShortClassNameIndex.getInstance().get(name, myManager.getProject(), scope);
public PsiClass[] getClassesByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Collection<PsiClass> classes = JavaShortClassNameIndex.getInstance().get(name, myManager.getProject(), scope);
if (classes.isEmpty()) return PsiClass.EMPTY_ARRAY;
ArrayList<PsiClass> list = new ArrayList<>(classes.size());
List<PsiClass> result = new ArrayList<>(classes.size());
Map<String, List<PsiClass>> uniqueQName2Classes = new THashMap<>(classes.size());
Set<PsiClass> hiddenClassesToRemove = null;
@@ -76,12 +75,10 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
String qName = aClass.getQualifiedName();
if (qName != null) {
List<PsiClass> previousQNamedClasses = uniqueQName2Classes.get(qName);
List<PsiClass> qNamedClasses;
List<PsiClass> qNamedClasses = new SmartList<>();
if (previousQNamedClasses != null) {
qNamedClasses = new SmartList<>();
for(PsiClass previousClass:previousQNamedClasses) {
for (PsiClass previousClass : previousQNamedClasses) {
VirtualFile previousClassVFile = previousClass.getContainingFile().getVirtualFile();
int res = scope.compare(previousClassVFile, vFile);
if (res > 0) {
@@ -92,21 +89,25 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
if (hiddenClassesToRemove == null) hiddenClassesToRemove = new THashSet<>();
hiddenClassesToRemove.add(previousClass);
qNamedClasses.add(aClass);
} else {
}
else {
qNamedClasses.add(aClass);
}
}
} else {
qNamedClasses = new SmartList<>(aClass);
}
else {
qNamedClasses.add(aClass);
}
uniqueQName2Classes.put(qName, qNamedClasses);
}
list.add(aClass);
result.add(aClass);
}
if (hiddenClassesToRemove != null) list.removeAll(hiddenClassesToRemove);
if (hiddenClassesToRemove != null) result.removeAll(hiddenClassesToRemove);
return list.toArray(new PsiClass[list.size()]);
return result.toArray(new PsiClass[result.size()]);
}
@Override
@@ -117,8 +118,7 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
public void getAllClassNames(@NotNull HashSet<String> set) {
Processor<String> processor = Processors.cancelableCollectProcessor(set);
processAllClassNames(processor);
processAllClassNames(Processors.cancelableCollectProcessor(set));
}
@Override
@@ -143,37 +143,28 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
@NotNull
public PsiMethod[] getMethodsByName(@NotNull String name, @NotNull final GlobalSearchScope scope) {
Collection<PsiMethod> methods = StubIndex.getElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(),
new JavaSourceFilterScope(scope), PsiMethod.class);
if (methods.isEmpty()) return PsiMethod.EMPTY_ARRAY;
List<PsiMethod> list = filterMembers(methods, scope);
return list.toArray(new PsiMethod[list.size()]);
public PsiMethod[] getMethodsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Collection<PsiMethod> methods = StubIndex.getElements(
JavaStubIndexKeys.METHODS, name, myManager.getProject(), new JavaSourceFilterScope(scope), PsiMethod.class);
return filterMembers(methods, scope, PsiMethod.EMPTY_ARRAY);
}
@Override
@NotNull
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NonNls @NotNull final String name, @NotNull final GlobalSearchScope scope, final int maxCount) {
final List<PsiMethod> methods = new SmartList<>();
StubIndex.getInstance().processElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, PsiMethod.class, new
CommonProcessors.CollectProcessor < PsiMethod > (methods){
@Override
public PsiMethod[] getMethodsByNameIfNotMoreThan(@NotNull String name, @NotNull GlobalSearchScope scope, int maxCount) {
List<PsiMethod> methods = new SmartList<>();
Processor<PsiMethod> processor = 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()]);
};
StubIndex.getInstance().processElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, PsiMethod.class, processor);
return filterMembers(methods, scope, PsiMethod.EMPTY_ARRAY);
}
@Override
public boolean processMethodsWithName(@NonNls @NotNull String name,
@NotNull GlobalSearchScope scope,
@NotNull Processor<PsiMethod> processor) {
public boolean processMethodsWithName(@NotNull String name, @NotNull GlobalSearchScope scope, @NotNull Processor<PsiMethod> processor) {
return StubIndex.getInstance().processElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(), scope, PsiMethod.class, processor);
}
@@ -190,30 +181,23 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
@NotNull
public PsiField[] getFieldsByNameIfNotMoreThan(@NotNull String name, @NotNull final GlobalSearchScope scope, final int maxCount) {
final List<PsiField> methods = new SmartList<>();
StubIndex.getInstance().processElements(JavaStubIndexKeys.FIELDS, name, myManager.getProject(), scope, PsiField.class, new
CommonProcessors.CollectProcessor < PsiField > (methods){
@Override
public PsiField[] getFieldsByNameIfNotMoreThan(@NotNull String name, @NotNull GlobalSearchScope scope, int maxCount) {
List<PsiField> fields = new SmartList<>();
Processor<PsiField> processor = new CommonProcessors.CollectProcessor<PsiField>(fields) {
@Override
public boolean process(PsiField method) {
return methods.size() != maxCount && super.process(method);
return fields.size() != maxCount && super.process(method);
}
});
if (methods.isEmpty()) return PsiField.EMPTY_ARRAY;
List<PsiField> list = filterMembers(methods, scope);
return list.toArray(new PsiField[list.size()]);
};
StubIndex.getInstance().processElements(JavaStubIndexKeys.FIELDS, name, myManager.getProject(), scope, PsiField.class, processor);
return filterMembers(fields, scope, PsiField.EMPTY_ARRAY);
}
@NotNull
@Override
public PsiField[] getFieldsByName(@NotNull String name, @NotNull final GlobalSearchScope scope) {
final Collection<PsiField> fields = JavaFieldNameIndex.getInstance().get(name, myManager.getProject(), scope);
if (fields.isEmpty()) return PsiField.EMPTY_ARRAY;
List<PsiField> list = filterMembers(fields, scope);
return list.toArray(new PsiField[list.size()]);
public PsiField[] getFieldsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Collection<PsiField> fields = JavaFieldNameIndex.getInstance().get(name, myManager.getProject(), scope);
return filterMembers(fields, scope, PsiField.EMPTY_ARRAY);
}
@Override
@@ -224,8 +208,7 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
public void getAllFieldNames(@NotNull HashSet<String> set) {
Processor<String> processor = Processors.cancelableCollectProcessor(set);
JavaFieldNameIndex.getInstance().processAllKeys(myManager.getProject(), processor);
JavaFieldNameIndex.getInstance().processAllKeys(myManager.getProject(), Processors.cancelableCollectProcessor(set));
}
@Override
@@ -233,17 +216,17 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@NotNull Processor<? super PsiField> processor,
@NotNull GlobalSearchScope scope,
@Nullable IdFilter filter) {
return StubIndex.getInstance().processElements(JavaStubIndexKeys.FIELDS, name, myManager.getProject(), new JavaSourceFilterScope(scope),
filter, PsiField.class, processor);
return StubIndex.getInstance().processElements(
JavaStubIndexKeys.FIELDS, name, myManager.getProject(), new JavaSourceFilterScope(scope), filter, PsiField.class, processor);
}
@Override
public boolean processMethodsWithName(@NonNls @NotNull String name,
public boolean processMethodsWithName(@NotNull String name,
@NotNull Processor<? super PsiMethod> processor,
@NotNull GlobalSearchScope scope,
@Nullable IdFilter filter) {
return StubIndex.getInstance().processElements(JavaStubIndexKeys.METHODS, name, myManager.getProject(),
new JavaSourceFilterScope(scope), filter, PsiMethod.class, processor);
return StubIndex.getInstance().processElements(
JavaStubIndexKeys.METHODS, name, myManager.getProject(), new JavaSourceFilterScope(scope), filter, PsiMethod.class, processor);
}
@Override
@@ -251,12 +234,15 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@NotNull Processor<? super PsiClass> processor,
@NotNull GlobalSearchScope scope,
@Nullable IdFilter filter) {
return StubIndex.getInstance().processElements(JavaStubIndexKeys.CLASS_SHORT_NAMES, name, myManager.getProject(),
new JavaSourceFilterScope(scope), filter, PsiClass.class, processor);
return StubIndex.getInstance().processElements(
JavaStubIndexKeys.CLASS_SHORT_NAMES, name, myManager.getProject(), new JavaSourceFilterScope(scope), filter, PsiClass.class, processor);
}
private <T extends PsiMember> List<T> filterMembers(Collection<T> members, final GlobalSearchScope scope) {
List<T> result = new ArrayList<>(members.size());
private <T extends PsiMember> T[] filterMembers(Collection<T> members, GlobalSearchScope scope, T[] emptyArray) {
if (members.isEmpty()) {
return emptyArray;
}
Set<PsiMember> set = new THashSet<>(members.size(), new TObjectHashingStrategy<PsiMember>() {
@Override
public int computeHashCode(PsiMember member) {
@@ -284,14 +270,13 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
}
});
List<T> result = new ArrayList<>(members.size());
for (T member : members) {
ProgressIndicatorProvider.checkCanceled();
if (!scope.contains(member.getContainingFile().getVirtualFile())) continue;
if (!set.add(member)) continue;
result.add(member);
if (scope.contains(member.getContainingFile().getVirtualFile()) && set.add(member)) {
result.add(member);
}
}
return result;
return result.toArray(emptyArray);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author max
*/
package com.intellij.psi.impl.search;
import com.intellij.ide.highlighter.JavaClassFileType;
@@ -29,9 +25,11 @@ import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author max
*/
public class JavaSourceFilterScope extends DelegatingGlobalSearchScope {
@Nullable
private final ProjectFileIndex myIndex;
private final @Nullable ProjectFileIndex myIndex;
public JavaSourceFilterScope(@NotNull final GlobalSearchScope delegate) {
super(delegate);
@@ -57,5 +55,4 @@ public class JavaSourceFilterScope extends DelegatingGlobalSearchScope {
return myIndex.isInSourceContent(file) ||
myBaseScope.isForceSearchingInLibrarySources() && myIndex.isInLibrarySource(file);
}
}