From a8aff01cb59bb40cb1d56695fb0cbe802d23106f Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Thu, 3 Sep 2020 17:35:06 -0400 Subject: [PATCH] GT-3 - Removed deprecated methods MarkerManager; added method from debugger branch to access markers by program --- .../app/plugin/core/marker/MarkerManager.java | 198 ++++-------------- .../app/plugin/core/marker/MarkerSetImpl.java | 5 +- .../ghidra/app/services/MarkerService.java | 65 +----- .../java/ghidra/app/services/MarkerSet.java | 83 +++++--- 4 files changed, 99 insertions(+), 252 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java index a84f8c5c4e..1a156521ce 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java @@ -24,6 +24,8 @@ import java.util.Map.Entry; import javax.swing.*; import javax.swing.event.ChangeListener; +import org.apache.commons.collections4.map.LazyMap; + import docking.ActionContext; import docking.action.*; import docking.widgets.PopupWindow; @@ -70,18 +72,12 @@ public class MarkerManager implements MarkerService { private Map> groupToProgramMarkerMap; private List currentMarkerSets; - /** - * @deprecated If the deprecated methods of this class are removed, then this list can - * also be removed. - */ - @Deprecated - private List deprecatedMarkerSets; - /** * A cache of programs to marker sets so that clients can install marker sets on a - * program-by-program basis. + * program-by-program basis */ - private Map> markerSetCache; + private Map> markerSetCache = + LazyMap.lazyMap(new HashMap<>(), () -> new ArrayList<>()); private SwingUpdateManager updateMgr; private GoToService goToService; @@ -93,7 +89,9 @@ public class MarkerManager implements MarkerService { private PluginTool tool; private String owner; // owner of the actions private Program currentProgram; - private AddressColorCache addressColorCache = new AddressColorCache(); + + private Map colorCache = + LazyMap.lazyMap(new HashMap<>(), () -> new AddressColorCache()); private PopupWindow popupWindow; @@ -108,8 +106,6 @@ public class MarkerManager implements MarkerService { this.tool = tool; currentMarkerSets = Collections.emptyList(); - deprecatedMarkerSets = new ArrayList<>(); - markerSetCache = new HashMap<>(); updateMgr = new SwingUpdateManager(100, 60000, () -> { markPanel.repaint(); @@ -165,16 +161,6 @@ public class MarkerManager implements MarkerService { return mgr; } - @Override - @Deprecated - public MarkerSet createAreaMarker(String name, String markerDescription, int priority, - boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color) { - MarkerSet areaMarker = new AreaMarkerSet(this, name, markerDescription, priority, - showMarkers, showNavigation, colorBackground, color, getProgram()); - insertManager((MarkerSetImpl) areaMarker); - return areaMarker; - } - @Override public MarkerSet createPointMarker(String name, String markerDescription, Program program, int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground, @@ -195,29 +181,6 @@ public class MarkerManager implements MarkerService { return mgr; } - @Override - @Deprecated - public MarkerSet createPointMarker(String name, String markerDescription, int priority, - boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color, - ImageIcon icon) { - MarkerSet pointMarker = new PointMarkerSet(this, name, markerDescription, priority, - showMarkers, showNavigation, colorBackground, color, icon); - insertManager((MarkerSetImpl) pointMarker); - return pointMarker; - } - - @Override - @Deprecated - public MarkerSet getMarkerSet(String name) { - for (MarkerSetImpl set : deprecatedMarkerSets) { - if (name.equals(set.getName())) { - return set; - } - } - - return null; - } - @Override public MarkerSet getMarkerSet(String name, Program program) { if (name == null) { @@ -228,29 +191,15 @@ public class MarkerManager implements MarkerService { throw new NullPointerException("Program cannot be null."); } - List programMarkerList = markerSetCache.get(program); - if (programMarkerList != null) { - for (MarkerSetImpl set : programMarkerList) { - if (name.equals(set.getName())) { - return set; - } + List list = markerSetCache.get(program); + for (MarkerSetImpl set : list) { + if (name.equals(set.getName())) { + return set; } } return null; } - @Override - @Deprecated - public void removeMarker(MarkerSet markerManager) { - if (markerManager == null) { - return; - } - - deprecatedMarkerSets.remove(markerManager); - actionList.refresh(); - update(); - } - @Override public void removeMarker(MarkerSet markerManager, Program program) { if (program == null) { @@ -262,18 +211,14 @@ public class MarkerManager implements MarkerService { update(); } - private void doRemoveMarker(MarkerSet markerManager, Program program) { - if (markerManager == null || program == null) { + private void doRemoveMarker(MarkerSet markerSet, Program program) { + if (markerSet == null || program == null) { return; } // per-program list List list = markerSetCache.get(program); - if (list == null) { - return; // can happen during the disposal process - } - - list.remove(markerManager); + list.remove(markerSet); // per-group list // We need to find the marker by searching through the map of maps (when used in a @@ -281,7 +226,7 @@ public class MarkerManager implements MarkerService { Collection> values = groupToProgramMarkerMap.values(); for (Map map : values) { MarkerSetImpl markerSetImpl = map.get(program); - if (markerSetImpl == markerManager) { + if (markerSetImpl == markerSet) { map.clear(); break; } @@ -303,13 +248,13 @@ public class MarkerManager implements MarkerService { */ public void setProgram(Program program) { this.currentProgram = program; - addressColorCache.clear(); if (program == null) { currentMarkerSets = Collections.emptyList(); updateMgr.update(); return; } + colorCache.get(program).clear(); setCurrentMarkerSets(program); actionList.refresh(); @@ -317,14 +262,11 @@ public class MarkerManager implements MarkerService { } public void dispose() { - if (updateMgr != null) { - updateMgr.dispose(); - } - + updateMgr.dispose(); actionList.dispose(); - deprecatedMarkerSets.clear(); currentMarkerSets.clear(); markerSetCache.clear(); + colorCache.clear(); } void navigateTo(int x, int y) { @@ -369,9 +311,7 @@ public class MarkerManager implements MarkerService { /** * Method getTooltip for object under cursor - * - * @param x location of cursor - * @param y location of cursor + * @param event the event containing the cursor coordinates * @return tool tip string for object under cursor */ String getTooltip(MouseEvent event) { @@ -459,22 +399,9 @@ public class MarkerManager implements MarkerService { } void update() { + AddressColorCache addressColorCache = colorCache.get(currentProgram); addressColorCache.clear(); - if (updateMgr != null) { - updateMgr.update(); - } - } - - @Deprecated - // remove this when the deprecated methods on the interface are removed - private void insertManager(MarkerSetImpl mgr) { - int index = Collections.binarySearch(deprecatedMarkerSets, mgr); - if (index < 0) { - index = -(index + 1); - } - - deprecatedMarkerSets.add(index, mgr); - actionList.refresh(); + updateMgr.update(); } private void insertManager(MarkerSetImpl mgr, Program program) { @@ -482,7 +409,7 @@ public class MarkerManager implements MarkerService { throw new AssertException("Program cannot be null"); } - List markerSetList = getMarkerSetListForProgram(program); + List markerSetList = markerSetCache.get(program); if (markerSetList == null) { return; // no list means deprecated usage } @@ -497,7 +424,7 @@ public class MarkerManager implements MarkerService { } private void setCurrentMarkerSets(Program program) { - List markerSetList = getMarkerSetListForProgram(program); + List markerSetList = markerSetCache.get(program); // determine if we are switching lists boolean switchingLists = (markerSetList != currentMarkerSets); @@ -506,33 +433,9 @@ public class MarkerManager implements MarkerService { } currentMarkerSets = markerSetList; - - // Unusual Code Alert: make sure we don't add the deprecated members twice - currentMarkerSets.removeAll(deprecatedMarkerSets); - currentMarkerSets.addAll(deprecatedMarkerSets); Collections.sort(currentMarkerSets); } - /** - * Gets only the markers for the given program. - */ - private List getMarkerSetListForProgram(Program program) { - if (program == null) { - return null; // deprecated usage; not program-based - } - - List markerSetList = markerSetCache.get(program); - if (markerSetList != null) { - return markerSetList; - } - - // need to initialize - markerSetList = new ArrayList<>(); - markerSetCache.put(program, markerSetList); - - return markerSetList; - } - private Address getAddress(int y) { if (pixmap == null) { return null; @@ -548,13 +451,12 @@ public class MarkerManager implements MarkerService { MarkerSetImpl marker = iter.next(); marker.updateView(updateMarkers, updateNavigation); } - if (updateMgr != null) { - if (updateNow) { - updateMgr.updateNow(); - } - else { - updateMgr.update(); - } + + if (updateNow) { + updateMgr.updateNow(); + } + else { + updateMgr.update(); } } @@ -626,17 +528,29 @@ public class MarkerManager implements MarkerService { @Override public Color getBackgroundColor(Address address) { + return getBackgroundColor(currentProgram, currentMarkerSets, address); + } + + public Color getBackgroundColor(Program program, Address address) { + return getBackgroundColor(program, markerSetCache.get(program), address); + } + + private Color getBackgroundColor(Program program, List markerSets, + Address address) { + AddressColorCache addressColorCache = colorCache.get(currentProgram); if (addressColorCache.containsKey(address)) { return addressColorCache.get(address); } + Color color = null; - for (int index = currentMarkerSets.size() - 1; index >= 0; index--) { - MarkerSet marker = currentMarkerSets.get(index); + for (int index = markerSets.size() - 1; index >= 0; index--) { + MarkerSet marker = markerSets.get(index); if (marker.isActive() && marker.isColoringBackground() && marker.contains(address)) { color = marker.getMarkerColor(); break; } } + if (color != null) { addressColorCache.put(address, color); } @@ -832,9 +746,6 @@ public class MarkerManager implements MarkerService { } - /* - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ @Override public void actionPerformed(ActionContext context) { options.setBoolean(mgr.getName(), isSelected()); @@ -901,9 +812,6 @@ public class MarkerManager implements MarkerService { } - /* - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ @Override public void actionPerformed(ActionContext context) { options.setBoolean(getName(), isSelected()); @@ -912,17 +820,11 @@ public class MarkerManager implements MarkerService { } private class MyMarginProvider implements MarginProvider { - /* (non-Javadoc) - * @see ghidra.app.util.viewer.panel.MarginProvider#getComponent() - */ @Override public JComponent getComponent() { return markPanel; } - /* (non-Javadoc) - * @see ghidra.app.util.viewer.panel.MarginProvider#getMarkerLocation(int, int) - */ @Override public MarkerLocation getMarkerLocation(int x, int y) { Address addr = getAddress(y); @@ -933,17 +835,11 @@ public class MarkerManager implements MarkerService { return new MarkerLocation(marker, addr, x, y); } - /* (non-Javadoc) - * @see ghidra.app.util.viewer.panel.MarginProvider#isResizeable() - */ @Override public boolean isResizeable() { return false; } - /* (non-Javadoc) - * @see ghidra.app.util.viewer.panel.MarginProvider#setPixelMap(ghidra.util.bean.field.VerticalPixelLayoutMap) - */ @Override public void setPixelMap(VerticalPixelAddressMap pixmap) { MarkerManager.this.pixmap = pixmap; @@ -953,17 +849,11 @@ public class MarkerManager implements MarkerService { private class MyOverviewProvider implements OverviewProvider { - /* (non-Javadoc) - * @see ghidra.app.util.viewer.panel.OverviewProvider#getComponent() - */ @Override public JComponent getComponent() { return navigationPanel; } - /* (non-Javadoc) - * @see ghidra.app.util.viewer.panel.OverviewProvider#setAddressIndexMap(ghidra.app.plugin.codebrowser.AddressIndexMap) - */ @Override public void setAddressIndexMap(AddressIndexMap map) { MarkerManager.this.addrMap = map; diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java index 164ab1549a..72ce0c914b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java @@ -308,7 +308,7 @@ abstract class MarkerSetImpl implements MarkerSet { Address end = pixmap.getLayoutEndAddress(i); if (markers.intersects(addr, end)) { - newLayouts.add(new Integer(i)); + newLayouts.add(i); } } @@ -382,9 +382,8 @@ abstract class MarkerSetImpl implements MarkerSet { } /** - * Get the tooltip for the marker at the specified index and address. + * Get the tooltip for the marker at the specified index and address * - * @param index index of item to navigate to * @param addr address of item to navigate to * @param x x location of cursor * @param y y location of cursor diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java index 00b13d691a..3b0191e39b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java @@ -27,7 +27,7 @@ import ghidra.program.model.listing.Program; /** *

Service to manage navigation markers displayed around a scrollable window - * like the codebrowser. The navigation bar displays the general location of + * like the Listing. The navigation bar displays the general location of * markers for the entire view. The marker bar displays a marker at each marked * address visible within the view.

*

@@ -86,7 +86,7 @@ public interface MarkerService { */ public final static int BREAKPOINT_PRIORITY = 50; /** - * Display priority for bookmarked locations. + * Display priority for bookmark locations. */ public final static int BOOKMARK_PRIORITY = 0; /** @@ -144,23 +144,6 @@ public interface MarkerService { int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color, boolean isPreferred); - /** - * This version of createAreaMarker() does not take a program and has thus been - * deprecated. See the recommended usage for more information. - * - * @deprecated Instead use {@link #createAreaMarker(String, String, Program, int, boolean, boolean, boolean, Color)} - * @param name name of the navigation markers - * @param markerDescription description of the navigation markers - * @param priority to sort out what displays on top, higher is more likely to be on top - * @param showMarkers true indicates to show area markers (on the left side of the browser.) - * @param showNavigation true indicates to show area navigation markers (on the right side of the browser.) - * @param colorBackground if true, then the browser's background color will reflect the marker. - * @param color the color of marked areas. - */ - @Deprecated - public MarkerSet createAreaMarker(String name, String markerDescription, int priority, - boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color); - /** * Create a Marker display which shows point type markers. * @@ -198,27 +181,6 @@ public interface MarkerService { int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color, ImageIcon icon, boolean isPreferred); - /** - * This version of createPointMarker() does not take a program and has thus been - * deprecated. See the recommended usage for more information. - * - * @deprecated Instead use {@link #createPointMarker(String, String, Program, int, boolean, boolean, boolean, Color, ImageIcon)} - * @param name name of the navigation markers - * @param markerDescription description of the navigation markers - * @param priority to sort out what displays on top, higher is more likely to be on top - * @param showMarkers true indicates to show area markers (on the left side of the browser.) - * @param showNavigation true indicates to show area navigation markers (on the right side of the browser.) - * @param colorBackground if true, then the browser's background color will reflect the marker. - * @param color the color of marked areas in navigation bar - * If navigation color is null, no results are displayed in the navigation bar - * @param icon icon to display in marker bar - * @return set of navigation markers - */ - @Deprecated - public MarkerSet createPointMarker(String name, String markerDescription, int priority, - boolean showMarkers, boolean showNavigation, boolean colorBackground, Color color, - ImageIcon icon); - /** * Remove the marker manager * @@ -227,16 +189,6 @@ public interface MarkerService { */ public void removeMarker(MarkerSet markerManager, Program program); - /** - * Remove the marker manager. This method is deprecated, - * see the recommended usage for more information. - * - * @deprecated use {@link #removeMarker(MarkerSet,Program)} - * @param markerManager marker manager to be removed from navigation bars. - */ - @Deprecated - public void removeMarker(MarkerSet markerManager); - /** * Return the markerset with the given name; * @@ -246,17 +198,6 @@ public interface MarkerService { */ public MarkerSet getMarkerSet(String name, Program program); - /** - * Return the markerset with the given name. This method is deprecated, - * see the recommended usage for more information. - * - * @deprecated use {@link #getMarkerSet(String, Program)} - * @param name The name of the marker set for which to search - * @return the markerset with the given name; - */ - @Deprecated - public MarkerSet getMarkerSet(String name); - /** * Sets a marker set for a given group name. Any previous marker set associated with the * given group name will be removed from this marker service. This method is used to ensure @@ -297,7 +238,7 @@ public interface MarkerService { /** * Removes the given change listener from the list of listeners to be notified of changes. - * @param listener + * @param listener the listener */ public void removeChangeListener(ChangeListener listener); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java index 3fc9812ad5..3a30b44072 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java @@ -15,123 +15,137 @@ */ package ghidra.app.services; -import ghidra.program.model.address.*; - import java.awt.Color; +import ghidra.program.model.address.*; + /** - * Defines methods for working with a set of addresses that correspond to - * markers. + * Defines methods for working with a set of addresses that correspond to markers. * @see MarkerService - * */ public interface MarkerSet extends Comparable { /** - * Add a marker at the address. + * Add a marker at the address + * @param addr the address */ public void add(Address addr); /** - * Add the range given the start and end of the range. + * Add the range given the start and end of the range + * @param start the start address + * @param end the end address */ public void add(Address start, Address end); /** - * Add a marker across the address range. + * Add a marker across the address range + * @param range the addresses */ public void add(AddressRange range); /** - * Sets the AddressSetCollection to be used for this this marker set. + * Sets the AddressSetCollection to be used for this this marker set. + * *

Warning! * Using this method will cause this MarkerSet to directly use the given AddressSetCollection. * If the given AddressSetCollection is not an instance of ModifiableAddressSetCollection, * then the markerSet methods that add and remove addresses will thrown an * IllegalArgumentException. + * * @param set the addressSetCollection to use as this markerSet's addressSetCollection. */ public void setAddressSetCollection(AddressSetCollection set); /** * Clears the current set off addresses in this markerSet and adds in the addresses - * from the given AddressSet. - * @param set the set of addresses to use in this marker set. + * from the given AddressSet + * @param set the set of addresses to use in this marker set */ public void setAddressSet(AddressSetView set); /** - * Add a marker at each address in the given address set. + * Add a marker at each address in the given address set + * @param addrSet the addresses */ public void add(AddressSetView addrSet); /** - * Determine if this marker set contains the specified address. + * Determine if this marker set contains the specified address * @param addr address - * @return true if marker set contains addr. + * @return true if marker set contains addr */ public boolean contains(Address addr); /** - * Return the address set for this marker set. + * Return the address set for this marker set + * @return the addresses */ public AddressSet getAddressSet(); /** - * Clear any marker at the address. + * Clear any marker at the address + * @param addr the address */ public void clear(Address addr); /** - * Clear any marker across the address range. + * Clear any marker across the address range + * @param range the addresses */ public void clear(AddressRange range); /** - * Remove the given range from the marker set. - * @param start the start of the range to remove. - * @param end the end of the range to remove. + * Remove the given range from the marker set + * @param start the start of the range to remove + * @param end the end of the range to remove */ public void clear(Address start, Address end); /** - * Clear any marker at each address in the address set. + * Clear any marker at each address in the address set + * @param addrSet the addresses */ public void clear(AddressSetView addrSet); /** - * Return the name of this MarkerSet. + * Return the name of this MarkerSet + * @return the name */ public String getName(); /** - * Clear all defined markers. + * Clear all defined markers */ public void clearAll(); /** - * Get display priority. + * Get display priority + * @return the priority */ public int getPriority(); /** * Gets whether this marker is in the preferred group when determining display priority. * Typically point markers are in the preferred group and area markers are not. + * @return true if preferred */ public boolean isPreferred(); /** - * Return true if this marker set is active. + * Return true if this marker set is active + * @param state the state */ public void setActive(boolean state); /** - * Get the color for the marker. + * Get the color for the marker + * @return the color */ public Color getMarkerColor(); /** - * Set the color for the marker. + * Set the color for the marker * @param color marker color */ public void setMarkerColor(Color color); @@ -139,30 +153,33 @@ public interface MarkerSet extends Comparable { /** * Set the marker manager listener to use for user interaction * with markers owned by this manager. + * @param listener the listener */ public void setNavigationListener(MarkerListener listener); /** - * @return true if this marker manager displays in the right - * hand navigation bar. + * True if this marker manager displays in the right hand navigation bar + * @return true if this marker manager displays in the right hand navigation bar */ public boolean isDisplayedInNavigationBar(); /** - * @return true if this marker manager displays in the left - * hand marker bar. + * True if this marker manager displays in the left hand marker bar + * @return true if this marker manager displays in the left hand marker bar */ public boolean displayInMarkerBar(); /** * Returns true if this MarkerSet is coloring the background in the listing for locations - * contained in this MarkerSet. + * contained in this MarkerSet + * @return true if coloring background */ public boolean isColoringBackground(); /** * Returns true if this MarkerSet is active. Being "active" means that it is displayed - * in the listing. + * in the listing + * @return true if active */ public boolean isActive();