GP-0: ghidra_builtins stubs no longer hides the python set type

(Closes #7222)
This commit is contained in:
Ryan Kurtz
2024-11-26 08:30:01 -05:00
parent d30694c961
commit cc15fdf691

View File

@@ -15,20 +15,10 @@
*/
package ghidra.doclets.typestubs;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.io.*;
import java.util.*;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.element.*;
import javax.lang.model.util.Elements;
/**
@@ -143,8 +133,8 @@ class GhidraBuiltinsBuilder {
*/
private void printMethods(PrintWriter printer, Set<String> exports) {
// methods must be sorted by name for typing.overload
List<PythonTypeStubMethod> apiMethods = api.getMethods(true, true);
List<PythonTypeStubMethod> scriptMethods = script.getMethods(true, true);
List<PythonTypeStubMethod> apiMethods = filter(api.getMethods(true, true));
List<PythonTypeStubMethod> scriptMethods = filter(script.getMethods(true, true));
int length = apiMethods.size() + scriptMethods.size();
List<PythonTypeStubMethod> methods = new ArrayList<>(length);
@@ -233,4 +223,18 @@ class GhidraBuiltinsBuilder {
PackageElement pkg = (PackageElement) type.getEnclosingElement();
return new PythonTypeStubType(new PythonTypeStubPackage(doclet, pkg), type);
}
/**
* Filters out methods that should not be considered for type generation.
* <p>
* One use case of this is to prevent Ghidra methods from overriding built-in Python methods
* that have a higher precedence.
*
* @param methods The methods to filter
* @return A new {@link List} of filtered methods
*/
private List<PythonTypeStubMethod> filter(List<PythonTypeStubMethod> methods) {
final Set<String> EXCLUDES = Set.of("set");
return methods.stream().filter(m -> !EXCLUDES.contains(m.getName())).toList();
}
}