mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 12:00:04 +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>
|
<P>Shows all locations that reference the given symbol.</P>
|
||||||
</BLOCKQUOTE>
|
</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>
|
<H2><A name="Create_Class"></A>Create a Class</H2>
|
||||||
|
|
||||||
<BLOCKQUOTE>
|
<BLOCKQUOTE>
|
||||||
|
|
|
@ -16,11 +16,16 @@ import ghidra.util.exception.InvalidInputException;
|
||||||
import docking.action.MenuData;
|
import docking.action.MenuData;
|
||||||
import docking.widgets.tree.GTreeNode;
|
import docking.widgets.tree.GTreeNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symbol tree action for converting a namespace to a class
|
||||||
|
*/
|
||||||
public class ConvertToClassAction extends SymbolTreeContextAction {
|
public class ConvertToClassAction extends SymbolTreeContextAction {
|
||||||
|
|
||||||
|
private static final String NAME = "Convert To Class";
|
||||||
|
|
||||||
public ConvertToClassAction(SymbolTreePlugin plugin) {
|
public ConvertToClassAction(SymbolTreePlugin plugin) {
|
||||||
super("Convert To Class", plugin.getName());
|
super(NAME, plugin.getName());
|
||||||
setPopupMenuData(new MenuData(new String[] { "Convert To Class" }, "0Create"));
|
setPopupMenuData(new MenuData(new String[] { NAME }, "1Convert"));
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,25 +52,24 @@ public class ConvertToClassAction extends SymbolTreeContextAction {
|
||||||
Program program = context.getProgram();
|
Program program = context.getProgram();
|
||||||
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
|
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
|
||||||
|
|
||||||
if (node instanceof SymbolNode) {
|
Symbol symbol = ((SymbolNode) node).getSymbol();
|
||||||
Symbol symbol = ((SymbolNode) node).getSymbol();
|
Namespace parent = (Namespace) symbol.getObject();
|
||||||
Namespace parent = (Namespace) symbol.getObject();
|
if (parent != null) {
|
||||||
if (parent != null) {
|
convertToClass(program, parent);
|
||||||
convertToClass(program, parent);
|
program.flushEvents();
|
||||||
program.flushEvents();
|
context.getSymbolTree().startEditing(node, parent.getName());
|
||||||
context.getSymbolTree().startEditing(node, parent.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void convertToClass(Program program, Namespace ns) {
|
private static void convertToClass(Program program, Namespace ns) {
|
||||||
int id = program.startTransaction("Convert To Class");
|
int id = program.startTransaction(NAME);
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
NamespaceUtils.convertNamespaceToClass(ns);
|
NamespaceUtils.convertNamespaceToClass(ns);
|
||||||
success = true;
|
success = true;
|
||||||
} catch (InvalidInputException e) {
|
} 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);
|
throw new AssertException(e);
|
||||||
} finally {
|
} finally {
|
||||||
program.endTransaction(id, success);
|
program.endTransaction(id, success);
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||||
private DockingActionIf selectionAction;
|
private DockingActionIf selectionAction;
|
||||||
private DockingActionIf createNamespaceAction;
|
private DockingActionIf createNamespaceAction;
|
||||||
private DockingActionIf createClassAction;
|
private DockingActionIf createClassAction;
|
||||||
|
private DockingActionIf convertToClassAction;
|
||||||
private ToggleDockingAction goToToggleAction;
|
private ToggleDockingAction goToToggleAction;
|
||||||
private SymbolTreeTestUtils util;
|
private SymbolTreeTestUtils util;
|
||||||
private SymbolGTree tree;
|
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) {
|
private void performTreeAction(DockingActionIf action, ActionContext context) {
|
||||||
assertTrue(action.isEnabledForContext(context));
|
assertTrue(action.isEnabledForContext(context));
|
||||||
performAction(action, context, true);
|
performAction(action, context, true);
|
||||||
|
@ -421,6 +438,8 @@ public class SymbolTreePlugin2Test extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertNotNull(createClassAction);
|
assertNotNull(createClassAction);
|
||||||
createNamespaceAction = getAction(plugin, "Create Namespace");
|
createNamespaceAction = getAction(plugin, "Create Namespace");
|
||||||
assertNotNull(createNamespaceAction);
|
assertNotNull(createNamespaceAction);
|
||||||
|
convertToClassAction = getAction(plugin, "Convert To Class");
|
||||||
|
assertNotNull(convertToClassAction);
|
||||||
|
|
||||||
goToToggleAction = (ToggleDockingAction) getAction(plugin, "Navigation");
|
goToToggleAction = (ToggleDockingAction) getAction(plugin, "Navigation");
|
||||||
assertNotNull(goToToggleAction);
|
assertNotNull(goToToggleAction);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue