mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
Added ConvertToClassAction help documentation and tests
This commit is contained in:
parent
bdf19b5691
commit
239f400fe1
3 changed files with 42 additions and 12 deletions
|
@ -184,6 +184,13 @@
|
|||
<P>Shows all locations that reference the given symbol.</P>
|
||||
</BLOCKQUOTE>
|
||||
|
||||
<H2><A name="Convert_To_Class"></A>Convert Namespace to Class</H2>
|
||||
|
||||
<BLOCKQUOTE>
|
||||
<P>You can convert a <I>Namespace</I> to a <I>Class</I>.
|
||||
Right mouse click on a namespace and choose the <B>Convert To Class</B> option.</P>
|
||||
</BLOCKQUOTE>
|
||||
|
||||
<H2><A name="Create_Class"></A>Create a Class</H2>
|
||||
|
||||
<BLOCKQUOTE>
|
||||
|
|
|
@ -16,11 +16,16 @@ import ghidra.util.exception.InvalidInputException;
|
|||
import docking.action.MenuData;
|
||||
import docking.widgets.tree.GTreeNode;
|
||||
|
||||
/**
|
||||
* Symbol tree action for converting a namespace to a class
|
||||
*/
|
||||
public class ConvertToClassAction extends SymbolTreeContextAction {
|
||||
|
||||
private static final String NAME = "Convert To Class";
|
||||
|
||||
public ConvertToClassAction(SymbolTreePlugin plugin) {
|
||||
super("Convert To Class", plugin.getName());
|
||||
setPopupMenuData(new MenuData(new String[] { "Convert To Class" }, "0Create"));
|
||||
super(NAME, plugin.getName());
|
||||
setPopupMenuData(new MenuData(new String[] { NAME }, "1Convert"));
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
|
@ -47,25 +52,24 @@ public class ConvertToClassAction extends SymbolTreeContextAction {
|
|||
Program program = context.getProgram();
|
||||
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
|
||||
|
||||
if (node instanceof SymbolNode) {
|
||||
Symbol symbol = ((SymbolNode) node).getSymbol();
|
||||
Namespace parent = (Namespace) symbol.getObject();
|
||||
if (parent != null) {
|
||||
convertToClass(program, parent);
|
||||
program.flushEvents();
|
||||
context.getSymbolTree().startEditing(node, parent.getName());
|
||||
}
|
||||
Symbol symbol = ((SymbolNode) node).getSymbol();
|
||||
Namespace parent = (Namespace) symbol.getObject();
|
||||
if (parent != null) {
|
||||
convertToClass(program, parent);
|
||||
program.flushEvents();
|
||||
context.getSymbolTree().startEditing(node, parent.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static void convertToClass(Program program, Namespace ns) {
|
||||
int id = program.startTransaction("Convert To Class");
|
||||
int id = program.startTransaction(NAME);
|
||||
boolean success = false;
|
||||
try {
|
||||
NamespaceUtils.convertNamespaceToClass(ns);
|
||||
success = true;
|
||||
} catch (InvalidInputException e) {
|
||||
// can't occur, checked in isEnabledForContext
|
||||
// This is thrown when the provided namespace is a function
|
||||
// It was checked in isEnabledForContext and thus cannot occur
|
||||
throw new AssertException(e);
|
||||
} finally {
|
||||
program.endTransaction(id, success);
|
||||
|
|
|
@ -62,6 +62,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
|||
private DockingActionIf selectionAction;
|
||||
private DockingActionIf createNamespaceAction;
|
||||
private DockingActionIf createClassAction;
|
||||
private DockingActionIf convertToClassAction;
|
||||
private ToggleDockingAction goToToggleAction;
|
||||
private SymbolTreeTestUtils util;
|
||||
private SymbolGTree tree;
|
||||
|
@ -295,6 +296,22 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToClass() throws Exception {
|
||||
String classNodeName = "MyClass";
|
||||
GTreeNode nsParentNode = rootNode.getChild(5);
|
||||
GTreeNode classNode = util.createObject(
|
||||
nsParentNode, classNodeName, createNamespaceAction);
|
||||
|
||||
util.selectNode(classNode);
|
||||
ActionContext context = util.getSymbolTreeContext();
|
||||
performTreeAction(convertToClassAction, context);
|
||||
|
||||
nsParentNode = rootNode.getChild(4);
|
||||
classNode = nsParentNode.getChild(classNodeName);
|
||||
assertNotNull(classNode);
|
||||
}
|
||||
|
||||
private void performTreeAction(DockingActionIf action, ActionContext context) {
|
||||
assertTrue(action.isEnabledForContext(context));
|
||||
performAction(action, context, true);
|
||||
|
@ -421,6 +438,8 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
|||
assertNotNull(createClassAction);
|
||||
createNamespaceAction = getAction(plugin, "Create Namespace");
|
||||
assertNotNull(createNamespaceAction);
|
||||
convertToClassAction = getAction(plugin, "Convert To Class");
|
||||
assertNotNull(convertToClassAction);
|
||||
|
||||
goToToggleAction = (ToggleDockingAction) getAction(plugin, "Navigation");
|
||||
assertNotNull(goToToggleAction);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue