Sorting of Python union type members is performed during latest definitions search

This commit is contained in:
Andrey Vlasovskikh
2011-08-09 18:33:09 +04:00
parent c6f3922edb
commit 577e716856
2 changed files with 21 additions and 9 deletions
@@ -160,12 +160,13 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
}
}
if (type instanceof PyUnionType) {
final List<String> typeNames = new ArrayList<String>();
for (PyType t : ((PyUnionType)type).getMembers()) {
typeNames.add(getTypeName(t, context));
}
Collections.sort(typeNames);
return String.format("one of (%s)", StringUtil.join(typeNames, ", "));
return String.format("one of (%s)", StringUtil.join(((PyUnionType)type).getMembers(),
new Function<PyType, String>() {
@Override
public String fun(PyType t) {
return getTypeName(t, context);
}
}, ", "));
}
return name;
}
@@ -15,8 +15,7 @@ import com.jetbrains.python.psi.PyTargetExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashSet;
import java.util.*;
/**
* @author Dennis.Ushakov
@@ -36,7 +35,19 @@ public class PyDefUseUtil {
final boolean[] visited = new boolean[instructions.length];
final Collection<PyElement> result = new HashSet<PyElement>();
getLatestDefs(var, instructions, instr, visited, result);
return result.toArray(new PyElement[result.size()]);
final List<PyElement> sortedResult = new ArrayList<PyElement>();
sortedResult.addAll(result);
Collections.sort(sortedResult, new Comparator<PyElement>() {
@Override
public int compare(PyElement e1, PyElement e2) {
final String n1 = e1.getName();
if (n1 != null) {
return n1.compareTo(e2.getName());
}
return 0;
}
});
return sortedResult.toArray(new PyElement[sortedResult.size()]);
}
private static void getLatestDefs(final PyElement var,