use of com.intellij.psi.util.proximity.PsiProximityComparator in project intellij-community by JetBrains.
the class GroovyStaticImportMethodFix method getMethodsToImport.
@NotNull
private List<PsiMethod> getMethodsToImport() {
PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myMethodCall.getProject());
GrMethodCall element = myMethodCall.getElement();
LOG.assertTrue(element != null);
GrReferenceExpression reference = getMethodExpression(element);
LOG.assertTrue(reference != null);
GrArgumentList argumentList = element.getArgumentList();
String name = reference.getReferenceName();
ArrayList<PsiMethod> list = new ArrayList<>();
if (name == null)
return list;
GlobalSearchScope scope = element.getResolveScope();
PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, 20);
List<PsiMethod> applicableList = new ArrayList<>();
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 PsiClassOwner && //do not show methods from default package
!((PsiClassOwner) file).getPackageName().isEmpty() && PsiUtil.isAccessible(element, method)) {
list.add(method);
if (PsiUtil.isApplicable(PsiUtil.getArgumentTypes(element, true), method, PsiSubstitutor.EMPTY, element, false)) {
applicableList.add(method);
}
}
}
List<PsiMethod> result = applicableList.isEmpty() ? list : applicableList;
Collections.sort(result, new PsiProximityComparator(argumentList));
return result;
}
Aggregations