Merge remote-tracking branch

'origin/GP-1122_dev747368_PR-2043_astrelsky_dwarfNamespacePath' (Closes
#2014, Closes #2043)
This commit is contained in:
Ryan Kurtz 2021-10-27 13:28:41 -04:00
commit a8fc117501
13 changed files with 354 additions and 103 deletions

View file

@ -537,4 +537,22 @@ public class NamespaceUtils {
SymbolTable symbolTable = namespaceSymbol.getProgram().getSymbolTable();
return symbolTable.convertNamespaceToClass(namespace);
}
/**
* Returns a list of namespaces, where each element is a component of the original specified
* namespace, excluding the global root namespace.
* <p>
* Namespace "ns1::ns2::ns3" returns [ "ns1", "ns1::ns2", "ns1::ns2::ns3" ]
*
* @param namespace namespace to process
* @return list of namespaces
*/
public static List<Namespace> getNameSpaceParts(Namespace namespace) {
List<Namespace> result = new ArrayList<>();
while (!namespace.isGlobal()) {
result.add(0, namespace);
namespace = namespace.getParentNamespace();
}
return result;
}
}

View file

@ -18,6 +18,7 @@ package ghidra.program.database.data;
import java.util.*;
import java.util.regex.Pattern;
import ghidra.app.util.NamespaceUtils;
import ghidra.docking.settings.Settings;
import ghidra.program.model.address.GlobalNamespace;
import ghidra.program.model.data.*;
@ -341,23 +342,15 @@ public class DataTypeUtilities {
*/
public static CategoryPath getDataTypeCategoryPath(CategoryPath baseCategory,
Namespace namespace) {
Namespace ns = namespace;
String path = "";
while (!ns.isGlobal() && !(ns instanceof Library)) {
if (path.length() != 0) {
path = "/" + path;
List<String> categoryPathParts = new ArrayList<>();
for (Namespace ns : NamespaceUtils.getNameSpaceParts(namespace)) {
if (!(ns instanceof Library)) {
categoryPathParts.add(ns.getName());
}
path = ns.getName() + path;
ns = ns.getParentNamespace();
}
if (path.length() == 0) {
return baseCategory;
}
String categoryPath = CategoryPath.DELIMITER_CHAR + path;
if (!baseCategory.equals(CategoryPath.ROOT)) {
categoryPath = baseCategory.getPath() + categoryPath;
}
return new CategoryPath(categoryPath);
return categoryPathParts.isEmpty()
? baseCategory
: new CategoryPath(baseCategory, categoryPathParts);
}
/**

View file

@ -364,7 +364,7 @@ public class SymbolUtilities {
return null;
}
int len = str.length();
StringBuffer buf = new StringBuffer(len);
StringBuilder buf = new StringBuilder(len);
for (int i = 0; i < len; ++i) {
char c = str.charAt(i);
if (isInvalidChar(c)) {