This commit is contained in:
Alexey Kudravtsev
2013-08-07 13:07:00 +04:00
parent db2723b429
commit f4c1d4aa3f
5 changed files with 33 additions and 19 deletions
@@ -140,9 +140,10 @@ public class AllClassesGetter {
}
};
public static void processJavaClasses(final CompletionParameters parameters,
final PrefixMatcher prefixMatcher, final boolean filterByScope,
final Consumer<PsiClass> consumer) {
public static void processJavaClasses(@NotNull final CompletionParameters parameters,
@NotNull final PrefixMatcher prefixMatcher,
final boolean filterByScope,
@NotNull final Consumer<PsiClass> consumer) {
final PsiElement context = parameters.getPosition();
final Project project = context.getProject();
final GlobalSearchScope scope = filterByScope ? context.getContainingFile().getResolveScope() : GlobalSearchScope.allScope(project);
@@ -167,10 +168,10 @@ public class AllClassesGetter {
processJavaClasses(prefixMatcher, project, scope, processor);
}
public static void processJavaClasses(final PrefixMatcher prefixMatcher,
Project project,
GlobalSearchScope scope,
Processor<PsiClass> processor) {
public static void processJavaClasses(@NotNull final PrefixMatcher prefixMatcher,
@NotNull Project project,
@NotNull GlobalSearchScope scope,
@NotNull Processor<PsiClass> processor) {
AllClassesSearch.search(scope, project, new Condition<String>() {
@Override
public boolean value(String s) {
@@ -79,7 +79,7 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
return false;
}
public static void addAllClasses(CompletionParameters parameters,
public static void addAllClasses(@NotNull CompletionParameters parameters,
final boolean filterByScope,
@NotNull final PrefixMatcher matcher,
@NotNull final Consumer<LookupElement> consumer) {
@@ -22,10 +22,12 @@ package com.intellij.psi.search.searches;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Conditions;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.SearchScope;
import com.intellij.util.Query;
import com.intellij.util.QueryExecutor;
import org.jetbrains.annotations.NotNull;
public class AllClassesSearch extends ExtensibleQueryFactory<PsiClass, AllClassesSearch.SearchParameters> {
public static ExtensionPointName<QueryExecutor> EP_NAME = ExtensionPointName.create("com.intellij.allClassesSearch");
@@ -36,20 +38,22 @@ public class AllClassesSearch extends ExtensibleQueryFactory<PsiClass, AllClasse
private final Project myProject;
private final Condition<String> myShortNameCondition;
public SearchParameters(final SearchScope scope, final Project project) {
this(scope, project, Condition.TRUE);
public SearchParameters(@NotNull SearchScope scope, @NotNull Project project) {
this(scope, project, Conditions.<String>alwaysTrue());
}
public SearchParameters(final SearchScope scope, final Project project, final Condition<String> shortNameCondition) {
public SearchParameters(@NotNull SearchScope scope, @NotNull Project project, @NotNull Condition<String> shortNameCondition) {
myScope = scope;
myProject = project;
myShortNameCondition = shortNameCondition;
}
@NotNull
public SearchScope getScope() {
return myScope;
}
@NotNull
public Project getProject() {
return myProject;
}
@@ -59,11 +63,13 @@ public class AllClassesSearch extends ExtensibleQueryFactory<PsiClass, AllClasse
}
}
public static Query<PsiClass> search(SearchScope scope, Project project) {
@NotNull
public static Query<PsiClass> search(@NotNull SearchScope scope, @NotNull Project project) {
return INSTANCE.createQuery(new SearchParameters(scope, project));
}
public static Query<PsiClass> search(SearchScope scope, Project project, Condition<String> shortNameCondition) {
@NotNull
public static Query<PsiClass> search(@NotNull SearchScope scope, @NotNull Project project, @NotNull Condition<String> shortNameCondition) {
return INSTANCE.createQuery(new SearchParameters(scope, project, shortNameCondition));
}
}
@@ -50,7 +50,7 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
SearchScope scope = queryParameters.getScope();
if (scope instanceof GlobalSearchScope) {
return processAllClassesInGlobalScope((GlobalSearchScope)scope, consumer, queryParameters);
return processAllClassesInGlobalScope((GlobalSearchScope)scope, queryParameters, consumer);
}
PsiElement[] scopeRoots = ((LocalSearchScope)scope).getScope();
@@ -59,8 +59,9 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
}
return true;
}
private static String[] getAllClassNames(final Project project) {
@NotNull
private static String[] getAllClassNames(@NotNull final Project project) {
return ApplicationManager.getApplication().runReadAction(new Computable<String[]>() {
@Override
public String[] compute() {
@@ -81,7 +82,9 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
});
}
private static boolean processAllClassesInGlobalScope(final GlobalSearchScope scope, final Processor<PsiClass> processor, final AllClassesSearch.SearchParameters parameters) {
private static boolean processAllClassesInGlobalScope(@NotNull final GlobalSearchScope scope,
@NotNull AllClassesSearch.SearchParameters parameters,
@NotNull Processor<PsiClass> processor) {
String[] names = getAllClassNames(parameters.getProject());
final ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
if (indicator != null) {
@@ -129,7 +132,7 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
return true;
}
private static boolean processScopeRootForAllClasses(@NotNull PsiElement scopeRoot, final Processor<PsiClass> processor) {
private static boolean processScopeRootForAllClasses(@NotNull PsiElement scopeRoot, @NotNull final Processor<PsiClass> processor) {
final boolean[] stopped = {false};
JavaElementVisitor visitor = scopeRoot instanceof PsiCompiledElement ? new JavaRecursiveElementVisitor() {
@@ -15,6 +15,8 @@
*/
package com.intellij.util;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
@@ -23,7 +25,7 @@ import java.util.Collection;
public class CollectConsumer<T> implements Consumer<T> {
private final Collection<T> myResult;
public CollectConsumer(Collection<T> result) {
public CollectConsumer(@NotNull Collection<T> result) {
myResult = result;
}
@@ -31,10 +33,12 @@ public class CollectConsumer<T> implements Consumer<T> {
this(new SmartList<T>());
}
@Override
public void consume(T t) {
myResult.add(t);
}
@NotNull
public Collection<T> getResult() {
return myResult;
}