suggest start match members first

This commit is contained in:
peter
2012-07-05 20:49:17 +02:00
parent 530edc975b
commit 31ac833d57
@@ -17,9 +17,7 @@ import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.*;
import static com.intellij.util.containers.CollectionFactory.hashSet;
import static com.intellij.util.containers.ContainerUtil.addIfNotNull;
@@ -46,12 +44,23 @@ public abstract class StaticMemberProcessor {
addIfNotNull(myStaticImportedClasses, psiClass);
}
public void processStaticMethodsGlobally(PrefixMatcher matcher, Consumer<LookupElement> consumer) {
public void processStaticMethodsGlobally(final PrefixMatcher matcher, Consumer<LookupElement> consumer) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.GLOBAL_MEMBER_NAME);
Comparator<String> comparator = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
boolean start1 = matcher.isStartMatch(o1);
boolean start2 = matcher.isStartMatch(o1);
return start1 == start2 ? 0 : start2 ? -1 : 1;
}
};
final GlobalSearchScope scope = myPosition.getResolveScope();
final PsiShortNamesCache namesCache = PsiShortNamesCache.getInstance(myProject);
for (final String methodName : namesCache.getAllMethodNames()) {
String[] methodNames = namesCache.getAllMethodNames();
Arrays.sort(methodNames, comparator);
for (final String methodName : methodNames) {
if (matcher.prefixMatches(methodName)) {
Set<PsiClass> classes = new THashSet<PsiClass>();
for (final PsiMethod method : namesCache.getMethodsByName(methodName, scope)) {
@@ -86,7 +95,9 @@ public abstract class StaticMemberProcessor {
}
}
}
for (final String fieldName : namesCache.getAllFieldNames()) {
String[] fieldNames = namesCache.getAllFieldNames();
Arrays.sort(fieldNames, comparator);
for (final String fieldName : fieldNames) {
if (matcher.prefixMatches(fieldName)) {
for (final PsiField field : namesCache.getFieldsByName(fieldName, scope)) {
if (isStaticallyImportable(field)) {