Skip to content

Commit d39caa5

Browse files
committed
Merge remote-tracking branch
'origin/GP-3683-dragonmacher-function-tags-nav-2' into patch (Closes NationalSecurityAgency#5613)
2 parents 5fe28ee + 0e307f0 commit d39caa5

File tree

3 files changed

+45
-77
lines changed

3 files changed

+45
-77
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/EditFunctionTagsAction.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
import ghidra.util.HelpLocation;
2727

2828
/**
29-
* Presents the user with a {@link ComponentProvider} showing all function tags available,
30-
* along with all those currently assigned to the selected function.
29+
* Presents the user with a {@link ComponentProvider} showing all function tags available,along with
30+
* all those currently assigned to the selected function.
31+
* <p>
3132
* Users may select, deselect, edit or delete tags.
3233
*/
3334
public class EditFunctionTagsAction extends ListingContextAction {
3435

3536
private FunctionTagPlugin plugin;
3637

37-
// Menu option that will show up when right-clicking on a function in
38-
// the listing.
38+
// Menu option that will show up when right-clicking on a function in the listing
3939
private final String MENU_LABEL = "Edit Tags...";
4040

4141
/**
4242
* Constructor.
43-
*
43+
*
4444
* @param name the name for this action.
4545
* @param plugin the plugin this action is associated with.
4646
*/
@@ -57,10 +57,6 @@ public EditFunctionTagsAction(String name, FunctionTagPlugin plugin) {
5757
setEnabled(true);
5858
}
5959

60-
/******************************************************************************
61-
* PUBLIC METHODS
62-
******************************************************************************/
63-
6460
@Override
6561
public void actionPerformed(ListingActionContext context) {
6662

@@ -74,25 +70,22 @@ public void actionPerformed(ListingActionContext context) {
7470
showProvider(context);
7571
}
7672

77-
/******************************************************************************
78-
* PROTECTED METHODS
79-
******************************************************************************/
80-
8173
/**
8274
* Overridden to only allow this menu option when clicking in a function.
8375
* Note that we do not allow external functions to have tags.
84-
*
76+
*
8577
* @param context the listing context
86-
* @return
78+
* @return true if enabled
8779
*/
8880
@Override
8981
protected boolean isEnabledForContext(ListingActionContext context) {
9082

91-
if (context.hasSelection() || context.getAddress() == null) {
83+
Address address = context.getAddress();
84+
if (context.hasSelection() || address == null) {
9285
return false;
9386
}
9487

95-
if (context.getLocation().getAddress().isExternalAddress()) {
88+
if (address.isExternalAddress()) {
9689
return false;
9790
}
9891

@@ -104,12 +97,9 @@ protected boolean isEnabledForContext(ListingActionContext context) {
10497
return !funcAddress.isExternalAddress();
10598
}
10699

107-
/******************************************************************************
108-
* PRIVATE METHODS
109-
******************************************************************************/
110100
/**
111101
* Retrieves the address of the function associated with the given program location.
112-
*
102+
*
113103
* @param loc the program location
114104
* @return the entry point of the function, or null if not valid
115105
*/
@@ -126,7 +116,7 @@ private Address getFunctionAddress(ProgramLocation loc) {
126116

127117
/**
128118
* Displays the provider.
129-
*
119+
*
130120
* @param context the listing context
131121
*/
132122
private void showProvider(ListingActionContext context) {

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagPlugin.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
/**
2828
* Plugin for managing function tags. This works with the associated
29-
* {@link FunctionTagProvider} to allow users to view and
29+
* {@link FunctionTagProvider} to allow users to view and
3030
* edit function tags both globally and for individual functions.
31-
*
31+
*
3232
*/
3333
//@formatter:off
3434
@PluginInfo(
@@ -51,17 +51,11 @@ public class FunctionTagPlugin extends ProgramPlugin {
5151

5252
public FunctionTagPlugin(PluginTool tool) {
5353
super(tool);
54-
provider = new FunctionTagProvider(this, getCurrentProgram());
55-
createActions();
5654
}
5755

58-
/******************************************************************************
59-
* PUBLIC METHODS
60-
******************************************************************************/
61-
6256
/**
6357
* Returns the component provider for this plugin
64-
*
58+
*
6559
* @return the component provider
6660
*/
6761
public FunctionTagProvider getProvider() {
@@ -71,11 +65,10 @@ public FunctionTagProvider getProvider() {
7165
@Override
7266
public void init() {
7367
super.init();
74-
}
7568

76-
/******************************************************************************
77-
* PROTECTED METHODS
78-
******************************************************************************/
69+
provider = new FunctionTagProvider(this, getCurrentProgram());
70+
createActions();
71+
}
7972

8073
@Override
8174
protected void programDeactivated(Program program) {
@@ -92,10 +85,6 @@ protected void locationChanged(ProgramLocation loc) {
9285
provider.locationChanged(loc);
9386
}
9487

95-
/******************************************************************************
96-
* PRIVATE METHODS
97-
******************************************************************************/
98-
9988
private void createActions() {
10089
editFunctionTagsAction = new EditFunctionTagsAction("Edit Function Tags", this);
10190
tool.addAction(editFunctionTagsAction);

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagProvider.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@
5050
* <LI>Edit tags (both name and comment)</LI>
5151
* <LI>Delete tags</LI>
5252
* <LI>Assign tags to the currently selected function</LI>
53-
* <LI>Remove tags from the currently selected function</LI>
53+
* <LI>Remove tags from the currently selected function</LI>
5454
* </UL>
55-
* This provider can be shown by right-clicking on a function and selecting the
55+
* This provider can be shown by right-clicking on a function and selecting the
5656
* "Edit Tags" option, or by selecting the "Edit Function Tags" option from the
5757
* "Window" menu.
5858
*/
59-
public class FunctionTagProvider extends ComponentProviderAdapter
60-
implements DomainObjectListener {
59+
public class FunctionTagProvider extends ComponentProviderAdapter implements DomainObjectListener {
6160

6261
private SourceTagsPanel sourcePanel;
6362
private TargetTagsPanel targetPanel;
@@ -75,37 +74,37 @@ public class FunctionTagProvider extends ComponentProviderAdapter
7574

7675
private SwingUpdateManager updater = new SwingUpdateManager(this::doUpdate);
7776

78-
// The current program location selected in the listing.
77+
// The current program location selected in the listing.
7978
private ProgramLocation currentLocation = null;
8079

8180
// Character used as a separator when entering multiple tags in
8281
// the create tag entry field.
8382
private static final String INPUT_DELIMITER = ",";
8483

85-
/**
86-
* Optional! If there is a file with this name which can be found by the
87-
* {@link ResourceManager}, and it contains a valid list of tag names,
84+
/**
85+
* Optional! If there is a file with this name which can be found by the
86+
* {@link ResourceManager}, and it contains a valid list of tag names,
8887
* they will be loaded. The file must be XML with the following
8988
* structure:
90-
*
89+
*
9190
* <tags>
9291
* <tag>
9392
* <name>TAG1</name>
9493
* <comment>tag comment</comment>
9594
* </tag>
96-
* </tags>
97-
*
95+
* </tags>
96+
*
9897
*/
9998
private static String TAG_FILE = "functionTags.xml";
10099

101-
// Keeps a list of the original tags as loaded from file. This is necessary when switching
102-
// between programs where we need to know the original state of the disabled tags. Without
100+
// Keeps a list of the original tags as loaded from file. This is necessary when switching
101+
// between programs where we need to know the original state of the disabled tags. Without
103102
// this we would need to reload from file on each new program activation.
104103
private Set<FunctionTag> tagsFromFile;
105104

106105
/**
107106
* Constructor
108-
*
107+
*
109108
* @param plugin the function tag plugin
110109
* @param program the current program
111110
*/
@@ -118,10 +117,6 @@ public FunctionTagProvider(FunctionTagPlugin plugin, Program program) {
118117
addToTool();
119118
}
120119

121-
/******************************************************************************
122-
* PUBLIC METHODS
123-
******************************************************************************/
124-
125120
@Override
126121
public void componentShown() {
127122
updateView();
@@ -133,10 +128,10 @@ public JComponent getComponent() {
133128
}
134129

135130
/**
136-
* Invoked when a new location has been detected in the listing. When
131+
* Invoked when a new location has been detected in the listing. When
137132
* this happens we need to update the tag list to show what tags are assigned
138133
* at the current location.
139-
*
134+
*
140135
* @param loc the address selected in the listing
141136
*/
142137
public void locationChanged(ProgramLocation loc) {
@@ -158,12 +153,6 @@ public void programDeactivated(Program deactivatedProgram) {
158153
this.program = null;
159154
}
160155

161-
/**
162-
* This class needs to listen for changes to the domain object (tag create, delete, etc...)
163-
* so it can update the display accordingly.
164-
*
165-
* @param ev the change event
166-
*/
167156
@Override
168157
public void domainObjectChanged(DomainObjectChangedEvent ev) {
169158

@@ -244,8 +233,8 @@ private JPanel createWorkPanel() {
244233
allFunctionsPanel.setBorder(BorderFactory.createLineBorder(Colors.BORDER));
245234

246235
// If we don't set this, then the splitter won't be able to shrink the
247-
// target panels below the size required by its header, which can be large
248-
// because of the amount of text displayed. Keep the minimum size setting on
236+
// target panels below the size required by its header, which can be large
237+
// because of the amount of text displayed. Keep the minimum size setting on
249238
// the source panel, however. That is generally small.
250239
targetPanel.setMinimumSize(new Dimension(0, 0));
251240

@@ -270,7 +259,7 @@ private JPanel createWorkPanel() {
270259
* Updates the button panel depending on the selection state of the
271260
* tag lists. Also updates the {@link AllFunctionsPanel} so it can update
272261
* its list.
273-
*
262+
*
274263
* @param panel the panel that generated the selection event
275264
*/
276265
public void selectionChanged(TagListPanel panel) {
@@ -330,7 +319,7 @@ Set<FunctionTag> backgroundLoadTags() {
330319

331320
/**
332321
* Loads tags from the external file specified.
333-
*
322+
*
334323
* @return the loaded tags
335324
*/
336325
private Set<FunctionTag> getFileTags() {
@@ -342,7 +331,7 @@ private Set<FunctionTag> getFileTags() {
342331

343332
/**
344333
* Returns an array of all tags stored in the database.
345-
*
334+
*
346335
* @return list of tags
347336
*/
348337
private List<? extends FunctionTag> getAllTagsFromDatabase() {
@@ -355,7 +344,7 @@ private List<? extends FunctionTag> getAllTagsFromDatabase() {
355344

356345
/**
357346
* Returns the {@link Function} for the given program location
358-
*
347+
*
359348
* @param loc the program location
360349
* @return function containing the location, or null if not applicable
361350
*/
@@ -371,7 +360,7 @@ private Function getFunction(ProgramLocation loc) {
371360

372361
/**
373362
* Retrieves the address of the function associated with the given program location.
374-
*
363+
*
375364
* @param loc the program location
376365
* @return the entry point of the function, or null if not valid
377366
*/
@@ -408,7 +397,7 @@ private void updateTagViews() {
408397
targetPanel.setProgram(program);
409398
allFunctionsPanel.setProgram(program);
410399

411-
// Get the currently selected tags and use them to update the all functions panel. If
400+
// Get the currently selected tags and use them to update the all functions panel. If
412401
// there is no current selection, leave the table as-is.
413402
Set<FunctionTag> sTags = sourcePanel.getSelectedTags();
414403
Set<FunctionTag> tTags = targetPanel.getSelectedTags();
@@ -423,7 +412,7 @@ private void updateTagViews() {
423412
}
424413

425414
/**
426-
* Parses all items in the text input field and adds them as new tags.
415+
* Parses all items in the text input field and adds them as new tags.
427416
*/
428417
private void processCreates() {
429418

@@ -462,15 +451,15 @@ private void processCreates() {
462451
/**
463452
* Returns a list of tag names the user has entered in the input` field.
464453
* Note: This assumes that multiple entries are comma-delimited.
465-
*
454+
*
466455
* @return the list of tag names to create
467456
*/
468457
private List<String> getInputNames() {
469458

470459
// first split the string on the delimiter to get all the entries
471460
String[] names = tagInputField.getText().split(INPUT_DELIMITER);
472461

473-
// trim each item to remove any leading/trailing whitespace and add to the return list
462+
// trim each item to remove any leading/trailing whitespace and add to the return list
474463
List<String> nameList = new ArrayList<>();
475464
for (String name : names) {
476465
if (!StringUtils.isBlank(name)) {
@@ -483,7 +472,7 @@ private List<String> getInputNames() {
483472

484473
/**
485474
* Creates the text-entry panel for adding new tag names.
486-
*
475+
*
487476
* @return the new text input panel
488477
*/
489478
private JPanel createInputPanel() {

0 commit comments

Comments
 (0)