GT-3434 - Refactored Namespace.NAMESPACE_DELIMITER to be shorter;

deprecated the old name
This commit is contained in:
dragonmacher 2020-01-15 14:07:44 -05:00
parent 7ad8505dcf
commit d96ee82856
25 changed files with 58 additions and 45 deletions

View file

@ -31,7 +31,7 @@ import ghidra.util.exception.InvalidInputException;
* <a id="examples"></a>
* Example strings:
* <ul>
* <li>global{@link Namespace#NAMESPACE_DELIMITER ::}child1{@link Namespace#NAMESPACE_DELIMITER ::}child2
* <li>global{@link Namespace#DELIMITER ::}child1{@link Namespace#DELIMITER ::}child2
* <li>child1
* </ul>
* <p>

View file

@ -394,7 +394,7 @@ public class GoToHelper {
StringBuilder buf = new StringBuilder();
while (!nameStack.isEmpty()) {
buf.append(nameStack.pop());
buf.append(Namespace.NAMESPACE_DELIMITER);
buf.append(Namespace.DELIMITER);
}
buf.append(externalLoc.getLabel());
return buf.toString();

View file

@ -192,7 +192,7 @@ public class NamespacePath implements Comparable<NamespacePath> {
public String asNamespaceString() {
StringBuilder sb = new StringBuilder();
doInOrderTraversal(
nsp -> sb.append(sb.length() != 0 ? Namespace.NAMESPACE_DELIMITER : "").append(
nsp -> sb.append(sb.length() != 0 ? Namespace.DELIMITER : "").append(
nsp.isRoot() ? "ROOT" : nsp.name));
return sb.toString();
}
@ -207,7 +207,7 @@ public class NamespacePath implements Comparable<NamespacePath> {
doInOrderTraversal(nsp -> {
if (!nsp.isRoot()) {
sb.append(sb.length() != 0 ? Namespace.NAMESPACE_DELIMITER : "").append(nsp.name);
sb.append(sb.length() != 0 ? Namespace.DELIMITER : "").append(nsp.name);
}
});
@ -219,7 +219,7 @@ public class NamespacePath implements Comparable<NamespacePath> {
public String toString() {
StringBuilder sb = new StringBuilder();
doInOrderTraversal(
nsp -> sb.append(sb.length() != 0 ? Namespace.NAMESPACE_DELIMITER : "").append(
nsp -> sb.append(sb.length() != 0 ? Namespace.DELIMITER : "").append(
nsp.isRoot() ? "ROOT" : nsp.name).append(
"(" + (nsp.getType() != null ? nsp.getType() : "unknown type") + ")"));
return sb.toString();

View file

@ -39,7 +39,7 @@ public abstract class DemangledObject {
protected static final String SPACE = " ";
protected static final Pattern SPACE_PATTERN = Pattern.compile(SPACE);
protected static final String NAMESPACE_SEPARATOR = Namespace.NAMESPACE_DELIMITER;
protected static final String NAMESPACE_SEPARATOR = Namespace.DELIMITER;
protected static final String EMPTY_STRING = "";
protected String originalMangled;

View file

@ -193,7 +193,7 @@ public class DemangledType {
return "";
}
buffer.append(Namespace.NAMESPACE_DELIMITER);
buffer.append(Namespace.DELIMITER);
return buffer.toString();
}

View file

@ -1057,7 +1057,7 @@ public class ProgramBuilder {
ExternalManager extMgr = program.getExternalManager();
Namespace namespace = extMgr.addExternalLibraryName(libraryName, sourceType);
if (externalLabel != null && externalLabel.indexOf(Namespace.NAMESPACE_DELIMITER) > 0) {
if (externalLabel != null && externalLabel.indexOf(Namespace.DELIMITER) > 0) {
// External manager API does not yet support creation of namespaces within
// library so we handle that here
SymbolPath symPath = new SymbolPath(externalLabel);

View file

@ -1293,8 +1293,8 @@ public class CodeUnitFormat {
namespaceName = parentNamespace.getName(true);
}
}
if (namespaceName.length() != 0 && !namespaceName.endsWith(Namespace.NAMESPACE_DELIMITER)) {
namespaceName += Namespace.NAMESPACE_DELIMITER;
if (namespaceName.length() != 0 && !namespaceName.endsWith(Namespace.DELIMITER)) {
namespaceName += Namespace.DELIMITER;
}
return namespaceName + name;
}

View file

@ -615,7 +615,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {
Address inBodyAddress = entry.getAddress().add(1);
addLabel(inBodyAddress);
String newName = "label_1";
setText("entry" + Namespace.NAMESPACE_DELIMITER + newName);
setText("entry" + Namespace.DELIMITER + newName);
pressOk();
assertFalse("Encountered a problem adding a label to the Global namespace",
dialog.isVisible());
@ -639,7 +639,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {
Address inBodyAddress = entry.getAddress().add(1);
addLabel(inBodyAddress);
String newName = "label_1";
setText(namespaceName + Namespace.NAMESPACE_DELIMITER + newName);
setText(namespaceName + Namespace.DELIMITER + newName);
pressOk();
assertFalse("Encountered a problem adding a label to the Global namespace",
dialog.isVisible());
@ -659,7 +659,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {
Address inBodyAddress = entry.getAddress().add(1);
addLabel(inBodyAddress);
String newName = "label_1";
setText(namespaceName + Namespace.NAMESPACE_DELIMITER + newName);
setText(namespaceName + Namespace.DELIMITER + newName);
pressOk();
assertFalse("Encountered a problem adding a label to the Global namespace",
dialog.isVisible());
@ -680,7 +680,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {
Address inBodyAddress = otherEntryAddress.add(1);
addLabel(inBodyAddress);
String newName = "label_1";
setText("entry" + Namespace.NAMESPACE_DELIMITER + newName);
setText("entry" + Namespace.DELIMITER + newName);
pressOk();
assertFalse("Encountered a problem adding a label to the Global namespace",
dialog.isVisible());
@ -707,7 +707,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {
editLabel(function);
String nsName = functionName;
setText(nsName + Namespace.NAMESPACE_DELIMITER + functionName);
setText(nsName + Namespace.DELIMITER + functionName);
pressOk();
assertFalse("Rename unsuccesful", dialog.isShowing());

View file

@ -651,7 +651,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
String newNamespace = "bob";
String prefix = "MY";
String newNameWithoutNamespace = prefix + s.getName();
String newName = newNamespace + Namespace.NAMESPACE_DELIMITER + newNameWithoutNamespace;
String newName = newNamespace + Namespace.DELIMITER + newNameWithoutNamespace;
util.rename(advapi32Node, newName);
util.waitForTree();
assertEquals(newNameWithoutNamespace, s.getName());
@ -681,7 +681,7 @@ public class SymbolTreePlugin1Test extends AbstractGhidraHeadedIntegrationTest {
GTreeNode nsNode = newNsNode;
String newNamespace = "OuterNamespace";
String newName = "MyNamespace";
String newFullName = newNamespace + Namespace.NAMESPACE_DELIMITER + newName;
String newFullName = newNamespace + Namespace.DELIMITER + newName;
setEditorText(path, nsNode, newFullName);
namespacesNode = rootNode.getChild("Namespaces");

View file

@ -308,7 +308,7 @@ public class CreateNamespacesCmdTest extends AbstractGenericTest {
for (int i = 0; i < namespaceNames.length; i++) {
buffer.append(namespaceNames[i]);
if (i + 1 < namespaceNames.length) {
buffer.append(Namespace.NAMESPACE_DELIMITER);
buffer.append(Namespace.DELIMITER);
}
}

View file

@ -107,7 +107,7 @@ public class CreateRtti1BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.NAMESPACE_DELIMITER,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
RTTI_1_NAME, suffix, address, applyOptions);
monitor.checkCanceled();

View file

@ -117,7 +117,7 @@ public class CreateRtti2BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.NAMESPACE_DELIMITER,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
RTTI_2_NAME, null, address, applyOptions);
monitor.checkCanceled();

View file

@ -104,7 +104,7 @@ public class CreateRtti3BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.NAMESPACE_DELIMITER,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
RTTI_3_NAME, null, address, applyOptions);
monitor.checkCanceled();

View file

@ -179,7 +179,7 @@ public class CreateRtti4BackgroundCmd extends AbstractCreateDataBackgroundCmd<Rt
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(program, RttiUtil.CONST_PREFIX +
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.NAMESPACE_DELIMITER,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
RTTI_4_NAME, null, address, applyOptions);
monitor.checkCanceled();

View file

@ -118,7 +118,7 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
monitor.checkCanceled();
String demangledTypeDescriptor = rtti0Model.getDemangledTypeDescriptor();
String prefixString = ((demangledTypeDescriptor != null)
? (demangledTypeDescriptor + Namespace.NAMESPACE_DELIMITER)
? (demangledTypeDescriptor + Namespace.DELIMITER)
: "");
data.setComment(CodeUnit.EOL_COMMENT,
"terminator for " + prefixString + VF_TABLE_LABEL);
@ -174,7 +174,7 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(program,
RttiUtil.CONST_PREFIX + RttiUtil.getDescriptorTypeNamespace(rtti0Model) +
Namespace.NAMESPACE_DELIMITER,
Namespace.DELIMITER,
VF_TABLE_LABEL, null, vfTableAddress, applyOptions);
monitor.checkCanceled();
@ -215,7 +215,7 @@ public class CreateVfTableBackgroundCmd extends AbstractCreateDataBackgroundCmd<
// Plate Comment
EHDataTypeUtilities.createPlateCommentIfNeeded(
program, META_LABEL + " pointer for " +
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.NAMESPACE_DELIMITER,
RttiUtil.getDescriptorTypeNamespace(rtti0Model) + Namespace.DELIMITER,
VF_TABLE_LABEL, null, metaAddress, applyOptions);
monitor.checkCanceled();

View file

@ -101,7 +101,7 @@ class ApplySymbols {
}
// Place compiler generated symbols (e.g., $LN9) within containing function when possible
if (name.startsWith("$") && !name.contains(Namespace.NAMESPACE_DELIMITER)) {
if (name.startsWith("$") && !name.contains(Namespace.DELIMITER)) {
Function f = functionManager.getFunctionContaining(address);
if (f != null && !f.getName().equals(name)) {
name = NamespaceUtils.getNamespaceQualifiedName(f, name, true);

View file

@ -479,7 +479,7 @@ public class PdbParser {
}
catch (Exception e) {
log.appendMsg("Unable to create class namespace: " + parentNamespace.getName(true) +
Namespace.NAMESPACE_DELIMITER + name);
Namespace.DELIMITER + name);
}
}
@ -983,11 +983,11 @@ public class PdbParser {
* @return name without namespace prefix
*/
String stripNamespace(String name) {
int index = name.lastIndexOf(Namespace.NAMESPACE_DELIMITER);
int index = name.lastIndexOf(Namespace.DELIMITER);
if (index <= 0) {
return name;
}
return name.substring(index + Namespace.NAMESPACE_DELIMITER.length());
return name.substring(index + Namespace.DELIMITER.length());
}
/**
@ -997,7 +997,7 @@ public class PdbParser {
* @return the category path
*/
CategoryPath getCategory(String namespaceQualifiedDataTypeName, boolean addPdbRoot) {
String[] names = namespaceQualifiedDataTypeName.split(Namespace.NAMESPACE_DELIMITER);
String[] names = namespaceQualifiedDataTypeName.split(Namespace.DELIMITER);
CategoryPath category = addPdbRoot ? pdbCategory : CategoryPath.ROOT;
if (names.length > 1) {
String[] categoryNames = new String[names.length - 1];

View file

@ -29,7 +29,7 @@ import ghidra.util.exception.*;
* <a id="examples"></a>
* Example string format:
* <ul>
* <li>global{@link Namespace#NAMESPACE_DELIMITER ::}child1{@link Namespace#NAMESPACE_DELIMITER ::}child2
* <li>global{@link Namespace#DELIMITER ::}child1{@link Namespace#DELIMITER ::}child2
* <li>child1
* </ul>
* <a id="assumptions"></a>
@ -69,7 +69,7 @@ public class NamespaceUtils {
String str = new String();
while (namespace != null && !(namespace instanceof GlobalNamespace) &&
!(namespace instanceof Library)) {
str = namespace.getName() + Namespace.NAMESPACE_DELIMITER + str;
str = namespace.getName() + Namespace.DELIMITER + str;
namespace = namespace.getParentNamespace();
}
return str;
@ -90,7 +90,7 @@ public class NamespaceUtils {
str = getNamespacePathWithoutLibrary(namespace);
}
else if (namespace != null && !(namespace instanceof GlobalNamespace)) {
str = namespace.getName(true) + Namespace.NAMESPACE_DELIMITER;
str = namespace.getName(true) + Namespace.DELIMITER;
}
str += symbolName;
return str;
@ -107,7 +107,7 @@ public class NamespaceUtils {
*/
@Deprecated
public static List<String> splitNamespacePath(String path) {
return Arrays.asList(path.trim().split(Namespace.NAMESPACE_DELIMITER));
return Arrays.asList(path.trim().split(Namespace.DELIMITER));
}
/**

View file

@ -172,7 +172,7 @@ public class SymbolPath implements Comparable<SymbolPath> {
*/
public String getPath() {
if (parentPath != null) {
return parentPath.getPath() + Namespace.NAMESPACE_DELIMITER + symbolName;
return parentPath.getPath() + Namespace.DELIMITER + symbolName;
}
return symbolName;
}

View file

@ -45,7 +45,7 @@ public class SymbolPathParser {
throw new IllegalArgumentException(
"Symbol list must contain at least one symbol name!");
}
if (name.indexOf(Namespace.NAMESPACE_DELIMITER) == -1) {
if (name.indexOf(Namespace.DELIMITER) == -1) {
List<String> list = new ArrayList<>();
list.add(name);
return list;

View file

@ -383,7 +383,7 @@ public class DataTypeUtilities {
public static DataType findNamespaceQualifiedDataType(DataTypeManager dataTypeManager,
String dtNameWithNamespace, Class<? extends DataType> classConstraint) {
String[] splitName = dtNameWithNamespace.split(Namespace.NAMESPACE_DELIMITER);
String[] splitName = dtNameWithNamespace.split(Namespace.DELIMITER);
String dtName = splitName[splitName.length - 1];
return findDataType(dataTypeManager, dtName, classConstraint,

View file

@ -193,7 +193,7 @@ public class ExternalLocationDB implements ExternalLocation {
if (label == null) {
setName(getLibrary(), null, SourceType.DEFAULT);
}
else if (label.indexOf(Namespace.NAMESPACE_DELIMITER) < 0) {
else if (label.indexOf(Namespace.DELIMITER) < 0) {
// if label does not include namespace keep current namespace
setName(symbol.getParentNamespace(), label, source);
}

View file

@ -213,7 +213,7 @@ public abstract class SymbolDB extends DatabaseObject implements Symbol {
Namespace ns = getParentNamespace();
if (!(ns instanceof GlobalNamespace)) {
String nsPath = ns.getName(true);
symName = nsPath + Namespace.NAMESPACE_DELIMITER + symName;
symName = nsPath + Namespace.DELIMITER + symName;
}
}
return symName;

View file

@ -193,7 +193,7 @@ public class PointerDataType extends BuiltIn implements Pointer {
String symName = symbol.getName();
symName = SymbolUtilities.getCleanSymbolName(symName, ref.getToAddress());
symName = symName.replace(Namespace.NAMESPACE_DELIMITER, "_");
symName = symName.replace(Namespace.DELIMITER, "_");
return POINTER_LABEL_PREFIX + "_" + symName;
}

View file

@ -21,39 +21,51 @@ import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
/**
* The Namespace interface.
* The Namespace interface
*/
public interface Namespace {
static final long GLOBAL_NAMESPACE_ID = 0;
/**
* The delimiter that is used to separate namespace nodes in a namespace
* string. For example, "Global::child1::symbolName"
*/
public static final String DELIMITER = "::";
/**
* Replaced by {@link #DELIMITER}
* @deprecated use {@link #DELIMITER}
*/
@Deprecated
public static final String NAMESPACE_DELIMITER = "::";
/**
* Get the symbol for this namespace; Note: The global namespace will return null
* @return the symbol for this namespace; Note: The global namespace will return null
*/
public Symbol getSymbol();
/**
* Returns true if this namespace is external (i.e., associated with a Library)
* @return true if this namespace is external (i.e., associated with a Library)
*/
public boolean isExternal();
/**
* Get the name of the symbol for this scope.
* Get the name of the symbol for this scope
* @return the name of the symbol for this scope
*/
public String getName();
/**
* Returns the fully qualified name.
* Returns the fully qualified name
* @param includeNamespacePath true to include the namespace in the returned name
* @return the fully qualified name
*/
public String getName(boolean includeNamespacePath);
/**
* Return the namespace id;
* Return the namespace id
* @return the namespace id
*/
public long getID();
@ -66,6 +78,7 @@ public interface Namespace {
/**
* Get the address set for this namespace. Note: The body of a namespace (currently
* only used by the function namespace) is restricted it Integer.MAX_VALUE.
* @return the address set for this namespace
*/
public AddressSetView getBody();