Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3292 - Decompiler - Secondary Highlights - Checkpoint 3 - Fixed clone feature to work with secondary highlights; have good test coverage; still need color choosing and persistence

dragonmacherec9a64436361
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.java
index d5b1bcd1ea..fb48b0caa3 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.java
@@ -35,6 +35,15 @@ import util.CollectionUtils;
* <p>This class does not painting directly. Rather, this class tracks the currently highlighted
* tokens and then sets the highlight color on the token when it is highlighted and clears the
* highlight color when the highlight is removed.
+ *
+ * <p>This class maintains the notion of 'primary' highlights and 'secondary' highlights.
+ * Primary highlights are considered transient and get cleared whenever the location changes.
+ * Secondary highlights will stay until they are manually cleared by a user action. Primary
+ * highlights happen when the user clicks around the Decompiler. They show state such as the
+ * current field, impact of a variable (via a slicing action), or related syntax (such as
+ * matching braces). Secondary highlights are triggered by the user to show all occurrences of
+ * a particular variable. Further, the user can apply multiple secondary highlights at the
+ * same time, with different colors for each highlight.
*/
public abstract class ClangHighlightController {
@@ -55,8 +64,6 @@ public abstract class ClangHighlightController {
private TokenHighlights primaryHighlightTokens = new TokenHighlights();
private TokenHighlights secondaryHighlightTokens = new TokenHighlights();
-
- // TODO rename 'secondary highlight color manager'
private TokenHighlightColors secondaryHighlightColors = new TokenHighlightColors();
private List<ClangHighlightListener> listeners = new ArrayList<>();
@@ -76,6 +83,10 @@ public abstract class ClangHighlightController {
return null;
}
+ public TokenHighlights getPrimaryHighlightedTokens() {
+ return primaryHighlightTokens;
+ }
+
public TokenHighlights getSecondaryHighlightedTokens() {
return secondaryHighlightTokens;
}
@@ -111,21 +122,15 @@ public abstract class ClangHighlightController {
notifyListeners();
}
- public void clearSecondaryHighlights() {
- doClearHighlights(secondaryHighlightTokens);
- notifyListeners();
- }
-
public void clearAllHighlights() {
doClearHighlights(primaryHighlightTokens);
doClearHighlights(secondaryHighlightTokens);
notifyListeners();
}
- // TODO try to reconcile 'tokenhighlights' vs 'highlighttokens' ( and highlighttoken)
- private void doClearHighlights(TokenHighlights highlightTokens) {
+ private void doClearHighlights(TokenHighlights tokenHighlights) {
- Iterator<HighlightToken> it = highlightTokens.iterator();
+ Iterator<HighlightToken> it = tokenHighlights.iterator();
while (it.hasNext()) {
HighlightToken highlight = it.next();
it.remove();
@@ -133,10 +138,33 @@ public abstract class ClangHighlightController {
token.setMatchingToken(false);
updateHighlightColor(token);
}
- highlightTokens.clear();
+ tokenHighlights.clear();
+ }
+
+ public void togglePrimaryMultiHighlight(ClangToken token, Color hlColor,
+ Supplier<List<ClangToken>> tokens) {
+
+ boolean isAllHighlighted = true;
+ for (ClangToken otherToken : tokens.get()) {
+ if (!hasPrimaryHighlight(otherToken)) {
+ isAllHighlighted = false;
+ break;
+ }
+ }
+
+ // this is a bit odd, but whenever we change the primary highlights, we always reset any
+ // previous primary highlight (see javadoc header)
+ clearPrimaryHighlights();
+
+ if (isAllHighlighted) {
+ // nothing to do; we toggled from 'all on' to 'all off'
+ return;
+ }
+
+ addPrimaryHighlights(tokens, hlColor);
}
- public void toggleSecondaryHighlight(ClangToken token,
+ public void toggleSecondaryMultiHighlight(ClangToken token,
Supplier<? extends Collection<ClangToken>> lazyTokens) {
String text = token.getText();
@@ -152,6 +180,10 @@ public abstract class ClangHighlightController {
}
}
+ public boolean hasPrimaryHighlight(ClangToken token) {
+ return primaryHighlightTokens.contains(token);
+ }
+
public boolean hasSecondaryHighlight(ClangToken token) {
return secondaryHighlightTokens.contains(token);
}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java
index 43a52b3da4..ca3f4f750c 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerController.java
@@ -123,7 +123,7 @@ public class DecompilerController {
return false;
}
- // cancel any pending decompile tasks, so that previous requests don't overwrite the latest request
+ // cancel pending decompile tasks; previous requests shouldn't overwrite the latest request
decompilerMgr.cancelAll();
setDecompileData(
new DecompileData(program, function, location, results, null, null, viewerPosition));
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
index 08b50619fd..3c875762aa 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
@@ -20,6 +20,7 @@ import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
+import java.util.Map.Entry;
import java.util.function.Supplier;
import javax.swing.JComponent;
@@ -141,16 +142,15 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
return fieldPanel;
}
- /**
- * This function replace the highlighting tokens with the new list
- * @param newTokens the new data
- */
- public void setHighlightedTokens(TokenHighlights newTokens) {
-
- // TODO pass these in or copy ourselves?
- //highlightController.setSecondaryHighlightedTokens(newTokens);
+ public void applySecondaryHighlights(Map<String, Color> highlightsByName) {
- throw new RuntimeException("Fixme");
+ Set<Entry<String, Color>> entries = highlightsByName.entrySet();
+ for (Entry<String, Color> entry : entries) {
+ String tokenName = entry.getKey();
+ Color color = entry.getValue();
+ Supplier<List<ClangToken>> lazyTokens = () -> findTokensByName(tokenName);
+ highlightController.addSecondaryHighlights(lazyTokens, color);
+ }
}
public TokenHighlights getSecondaryHighlightedTokens() {
@@ -163,7 +163,15 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
}
public void toggleSecondaryHighlight(ClangToken token, Supplier<List<ClangToken>> lazyTokens) {
- highlightController.toggleSecondaryHighlight(token, lazyTokens);
+ highlightController.toggleSecondaryMultiHighlight(token, lazyTokens);
+ }
+
+ private void togglePrimaryHighlight(FieldLocation location, Field field, Color highlightColor) {
+
+ ClangToken token = ((ClangTextField) field).getToken(location);
+ Supplier<List<ClangToken>> lazyTokens = () -> findTokensByName(token.getText());
+ highlightController.togglePrimaryMultiHighlight(token, middleMouseHighlightColor,
+ lazyTokens);
}
@Override
@@ -503,7 +511,7 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
}
if (buttonState == middleMouseHighlightButton && clickCount == 1) {
- setPrimaryHighlight(location, field, middleMouseHighlightColor);
+ togglePrimaryHighlight(location, field, middleMouseHighlightColor);
}
}
@@ -662,15 +670,6 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
}
}
- private void setPrimaryHighlight(FieldLocation location, Field field, Color highlightColor) {
- ClangToken token = ((ClangTextField) field).getToken(location);
- Supplier<List<ClangToken>> lazyTokens = () -> findTokensByName(token.getText());
-
- clearPrimaryHighlights();
- highlightController.addPrimaryHighlights(lazyTokens, highlightColor);
- repaint();
- }
-
Program getProgram() {
return decompileData.getProgram();
}
@@ -888,8 +887,7 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
private void doFindTokensByName(List<ClangToken> tokens, ClangTokenGroup group, String name) {
- // TODO is 'name' sufficient, or will that allow for conflicts
-
+ // TODO is it possible that two or more different variable tokens share the same name?
for (int i = 0; i < group.numChildren(); ++i) {
ClangNode child = group.Child(i);
if (child instanceof ClangTokenGroup) {
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlightColors.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlightColors.java
index 2535562995..7d4d002460 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlightColors.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlightColors.java
@@ -19,15 +19,14 @@ import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.collections4.map.LazyMap;
-
-// TODO docme
+/**
+ * A class to create and store colors related to token names
+ */
public class TokenHighlightColors {
private int minColorSaturation = 100;
private int defaultColorAlpha = 100;
- private Map<String, Color> colorsByName =
- LazyMap.lazyMap(new HashMap<>(), s -> generateColor());
+ private Map<String, Color> colorsByName = new HashMap<>();
private Color generateColor() {
return new Color((int) (minColorSaturation + Math.random() * (256 - minColorSaturation)),
@@ -37,6 +36,6 @@ public class TokenHighlightColors {
}
public Color getColor(String text) {
- return colorsByName.get(text);
+ return colorsByName.computeIfAbsent(text, t -> generateColor());
}
}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlights.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlights.java
index a315ee2a2d..3deca8dcd3 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlights.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/TokenHighlights.java
@@ -15,6 +15,7 @@
*/
package ghidra.app.decompiler.component;
+import java.awt.Color;
import java.util.*;
import java.util.Map.Entry;
@@ -30,10 +31,16 @@ public class TokenHighlights implements Iterable<HighlightToken> {
private Map<TokenKey, HighlightToken> highlightsByToken = new HashMap<>();
- public TokenHighlights copyHighlights() {
- TokenHighlights newHighlights = new TokenHighlights();
- newHighlights.highlightsByToken = new HashMap<>(highlightsByToken);
- return newHighlights;
+ public Map<String, Color> copyHighlightsByName() {
+ Map<String, Color> results = new HashMap<>();
+
+ Collection<HighlightToken> values = highlightsByToken.values();
+ for (HighlightToken hl : values) {
+ String name = hl.getToken().getText();
+ results.put(name, hl.getColor());
+ }
+
+ return results;
}
private TokenKey getKey(HighlightToken ht) {
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
index d6d021d010..de6f986f40 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
@@ -15,6 +15,7 @@
*/
package ghidra.app.plugin.core.decompile;
+import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.math.BigInteger;
@@ -642,23 +643,28 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
}
public void cloneWindow() {
- final DecompilerProvider newProvider = plugin.createNewDisconnectedProvider();
+ DecompilerProvider newProvider = plugin.createNewDisconnectedProvider();
+
// invoke later to give the window manage a chance to create the new window
// (its done in an invoke later)
Swing.runLater(() -> {
+
+ ViewerPosition myViewPosition = controller.getDecompilerPanel().getViewerPosition();
newProvider.doSetProgram(program);
- newProvider.controller.setDecompileData(controller.getDecompileData());
// Any change in the HighlightTokens should be delivered to the new panel
- DecompilerPanel panel = getDecompilerPanel();
- TokenHighlights highlightedTokens = panel.getSecondaryHighlightedTokens();
+ DecompilerPanel myPanel = getDecompilerPanel();
+ TokenHighlights myHighlights = myPanel.getSecondaryHighlightedTokens();
+ newProvider.setLocation(currentLocation, myPanel.getViewerPosition());
+ // transfer any state after the new decompiler is initialized
DecompilerPanel newPanel = newProvider.getDecompilerPanel();
- TokenHighlights copiedTokens = highlightedTokens.copyHighlights();
+ Map<String, Color> highlightsByName = myHighlights.copyHighlightsByName();
+ newProvider.doWheNotBusy(() -> {
- // Transfer the highlighted tokens
- newPanel.setHighlightedTokens(copiedTokens);
- newProvider.setLocation(currentLocation, panel.getViewerPosition());
+ newPanel.setViewerPosition(myViewPosition);
+ newPanel.applySecondaryHighlights(highlightsByName);
+ });
});
}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ToggleSecondaryHighlightAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ToggleSecondaryHighlightAction.java
index c2ed41a421..7e1816063e 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ToggleSecondaryHighlightAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ToggleSecondaryHighlightAction.java
@@ -15,11 +15,9 @@
*/
package ghidra.app.plugin.core.decompile.actions;
-import java.awt.event.KeyEvent;
import java.util.List;
import java.util.function.Supplier;
-import docking.action.KeyBindingData;
import docking.action.MenuData;
import ghidra.app.decompiler.ClangToken;
import ghidra.app.decompiler.component.DecompilerPanel;
@@ -37,10 +35,6 @@ public class ToggleSecondaryHighlightAction extends AbstractDecompilerAction {
setPopupMenuData(new MenuData(new String[] { "Highlight Toggle" }, "Decompile"));
- // TODO new key binding: 'h'
- // TODO how about mouse actions?
- setKeyBindingData(new KeyBindingData(KeyEvent.VK_C, 0));
-
// TODO new help
setHelpLocation(new HelpLocation(HelpTopics.SELECTION, getName()));
}
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerClangTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerClangTest.java
index 8b084811e2..b4a3ff8f4b 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerClangTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerClangTest.java
@@ -18,6 +18,7 @@ package ghidra.app.plugin.core.decompile;
import static org.junit.Assert.*;
import java.awt.Color;
+import java.awt.event.MouseEvent;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -26,8 +27,11 @@ import org.junit.Test;
import docking.action.DockingActionIf;
import docking.widgets.dialogs.InputDialog;
+import docking.widgets.fieldpanel.FieldPanel;
+import docking.widgets.fieldpanel.field.Field;
import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.app.cmd.comments.SetCommentCmd;
+import ghidra.app.decompiler.ClangLine;
import ghidra.app.decompiler.ClangToken;
import ghidra.app.decompiler.component.*;
import ghidra.app.plugin.core.decompile.actions.*;
@@ -234,6 +238,38 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
assertEquals("_printf", copiedText);
}
+ @Test
+ public void testPrimaryHighlighting_ParenthesesContents() {
+
+ /*
+
+ Decomp of '_call_structure_A':
+
+ 1|
+ 2| void _call_structure_A(A *a)
+ 3|
+ 4| {
+ 5| _printf("call_structure_A: %s\n",a->name);
+ 6| _printf("call_structure_A: %s\n",(a->b).name);
+ 7| _printf("call_structure_A: %s\n",(a->b).c.name);
+ 8| _printf("call_structure_A: %s\n",(a->b).c.d.name);
+ 9| _printf("call_structure_A: %s\n",(a->b).c.d.e.name);
+ 10| _call_structure_B(&a->b);
+ 11| return;
+ 12| }
+
+ */
+
+ decompile("100000d60"); // '_call_structure_A'
+
+ // 5:7 "_printf | ("..."
+ int line = 5;
+ int charPosition = 7;
+ setDecompilerLocation(line, charPosition);
+
+ assertPrimaryHighlights("(\"call_structure_A: %s\\n\",a->name)");
+ }
+
@Test
public void testSecondaryHighlighting() {
@@ -638,31 +674,128 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
assertAllFieldsHighlighted(secondaryHighlightText, color);
}
- // TODO how does highlight interplay with slice highlight?
- // -toggling a color highlight should not remove the other highlights
- // --test on and off
- // -test setting primary highlight does not clear secondary highlights
- // -- secondary remains after clicking away
- // --middle-mouse
- // --slicing
+ @Test
+ public void testSecondaryHighlighting_MiddleMouseDoesNotClearSecondaryHighlight() {
+
+ /*
+
+ Decomp of '_call_structure_A':
+
+ 1|
+ 2| void _call_structure_A(A *a)
+ 3|
+ 4| {
+ 5| _printf("call_structure_A: %s\n",a->name);
+ 6| _printf("call_structure_A: %s\n",(a->b).name);
+ 7| _printf("call_structure_A: %s\n",(a->b).c.name);
+ 8| _printf("call_structure_A: %s\n",(a->b).c.d.name);
+ 9| _printf("call_structure_A: %s\n",(a->b).c.d.e.name);
+ 10| _call_structure_B(&a->b);
+ 11| return;
+ 12| }
+
+ */
+
+ decompile("100000d60"); // '_call_structure_A'
+
+ // 5:2 "_printf"
+ int line = 5;
+ int charPosition = 2;
+ setDecompilerLocation(line, charPosition);
+
+ ClangToken token = getToken();
+ String tokenText = token.getText();
+ assertEquals("_printf", tokenText);
+
+ Color color = highlight();
+
+ middleMouse();
+ assertCombinedHighlightColor(token);
+
+ middleMouse();
+ assertAllFieldsHighlighted(tokenText, color);
+ }
+
+ @Test
+ public void testSecondaryHighlighting_CloneDecompiler() {
+
+ /*
+
+ Decomp of '_call_structure_A':
+
+ 1|
+ 2| void _call_structure_A(A *a)
+ 3|
+ 4| {
+ 5| _printf("call_structure_A: %s\n",a->name);
+ 6| _printf("call_structure_A: %s\n",(a->b).name);
+ 7| _printf("call_structure_A: %s\n",(a->b).c.name);
+ 8| _printf("call_structure_A: %s\n",(a->b).c.d.name);
+ 9| _printf("call_structure_A: %s\n",(a->b).c.d.e.name);
+ 10| _call_structure_B(&a->b);
+ 11| return;
+ 12| }
+
+ */
+
+ decompile("100000d60"); // '_call_structure_A'
+
+ // 5:2 "_printf"
+ int line = 5;
+ int charPosition = 2;
+ setDecompilerLocation(line, charPosition);
+ ClangToken token = getToken();
+ String secondaryHighlightText = token.getText();
+ assertEquals("_printf", secondaryHighlightText);
- // TODO test highlights passed to clone
+ Color color = highlight();
- // TODO allow for any text, not just variables?
- // TODO - follow-up test that 2 variables with the same name do not get highlighted
+ DecompilerProvider clone = cloneDecompiler();
+ assertAllFieldsHighlighted(clone, secondaryHighlightText, color);
- // TODO test color chooser
+ // ensure one field provider does not affect the other
+ clearSecondaryHighlight();
+ assertNoFieldsSecondaryHighlighted(secondaryHighlightText);
+ assertAllFieldsHighlighted(clone, secondaryHighlightText, color);
+ }
- // TODO test persistence
- // TODO Energy
- // -highlight tokens between parens
+ @Test
+ public void testSecondaryHighlighting_ChooseColors() {
+ fail();
+ }
- // TODO test clone copies highlights
+ @Test
+ public void testSecondaryHighlighting_PersistColors() {
+ fail();
+ }
//==================================================================================================
// Private Methods
//==================================================================================================
+ private DecompilerProvider cloneDecompiler() {
+
+ DockingActionIf action = getAction(decompiler, "Decompile Clone");
+ performAction(action);
+ waitForSwing();
+
+ @SuppressWarnings("unchecked")
+ List<DecompilerProvider> disconnectedProviders =
+ (List<DecompilerProvider>) getInstanceField("disconnectedProviders", decompiler);
+ assertFalse(disconnectedProviders.isEmpty());
+ return disconnectedProviders.get(0);
+ }
+
+ private void assertPrimaryHighlights(String text) {
+ List<ClangToken> tokens = getPrimaryHighlightTokens();
+ StringBuilder buffy = new StringBuilder();
+ for (ClangToken token : tokens) {
+ buffy.append(token.getText());
+ }
+
+ assertEquals(text, buffy.toString());
+ }
+
private void assertCombinedHighlightColor(ClangToken token) {
Color combinedColor = getCombinedHighlightColor(token);
@@ -701,11 +834,48 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
return highlightController.getCombinedColor(token);
}
+ private List<ClangToken> getPrimaryHighlightTokens() {
+ DecompilerController controller = provider.getController();
+ DecompilerPanel panel = controller.getDecompilerPanel();
+ ClangHighlightController highlightController = panel.getHighlightController();
+ TokenHighlights tokens = highlightController.getPrimaryHighlightedTokens();
+
+ List<ClangToken> results = new ArrayList<>();
+ for (HighlightToken hl : tokens) {
+ results.add(hl.getToken());
+ }
+
+ results.sort((t1, t2) -> indexInParent(t1) - indexInParent(t2));
+ return results;
+ }
+
+ private int indexInParent(ClangToken t) {
+ ClangLine line = t.getLineParent();
+ return line.indexOfToken(t);
+ }
+
private void backwardSlice() {
DockingActionIf action = getAction(decompiler, BackwardsSliceAction.NAME);
performAction(action);
}
+ private void middleMouse() {
+ DecompilerController controller = provider.getController();
+ DecompilerPanel panel = controller.getDecompilerPanel();
+ FieldLocation location = panel.getCursorPosition();
+ FieldPanel fp = panel.getFieldPanel();
+ Field field = fp.getCurrentField();
+
+ // x,y shouldn't matter
+ int x = 0;
+ int y = 0;
+ int clickCount = 1;
+ MouseEvent event = new MouseEvent(fp, 1, System.currentTimeMillis(), 0, x, y, clickCount,
+ false, MouseEvent.BUTTON2);
+
+ runSwing(() -> panel.buttonPressed(location, field, event));
+ }
+
private void assertPrimaryHighlight(ClangToken token) {
DecompilerController controller = provider.getController();
DecompilerPanel panel = controller.getDecompilerPanel();
@@ -713,11 +883,6 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
assertEquals(hlColor, token.getHighlight());
}
- private void assertPrimaryAndSecondaryHighlight(ClangToken token) {
- // TODO Auto-generated method stub
- fail();
- }
-
private void rename(String newName) {
DockingActionIf action = getAction(decompiler, "Rename Variable");
performAction(action, false);
@@ -757,8 +922,8 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
ClangToken token = getToken();
DockingActionIf highlightAction =
- getAction(decompiler, ToggleSecondaryHighlightAction.NAME);
- performAction(highlightAction);
+ getLocalAction(provider, ToggleSecondaryHighlightAction.NAME);
+ performAction(highlightAction, provider.getActionContext(null), true);
DecompilerController controller = provider.getController();
DecompilerPanel panel = controller.getDecompilerPanel();
@@ -772,18 +937,9 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
Color hlColor = getDefaultHighlightColor();
Color specialColor = getSpecialHighlightColor();
- DecompilerController controller = provider.getController();
- DecompilerPanel panel = controller.getDecompilerPanel();
- List<ClangToken> tokensWithName = panel.findTokensByName(name);
- assertFalse(tokensWithName.isEmpty());
- for (ClangToken otherToken : tokensWithName) {
-
- Color tokenColor = otherToken.getHighlight();
- boolean yes = hlColor.equals(tokenColor) || specialColor.equals(tokenColor);
-
- assertTrue("Token is not highlighted: '" + otherToken + "'" + "\n\texpected: " +
- toString(hlColor) + "; found: " + toString(otherToken.getHighlight()), yes);
- }
+ ColorMatcher cm = new ColorMatcher(hlColor, specialColor);
+ Predicate<ClangToken> noIgnores = t -> false;
+ assertAllFieldsHighlighted(name, cm, noIgnores);
}
private void assertAllFieldsHighlightedExceptForToken(ClangToken token, Color color) {
@@ -817,7 +973,21 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
private void assertAllFieldsHighlighted(String name, ColorMatcher colorMatcher,
Predicate<ClangToken> ignore) {
- DecompilerController controller = provider.getController();
+ assertAllFieldsHighlighted(provider, name, colorMatcher, ignore);
+ }
+
+ private void assertAllFieldsHighlighted(DecompilerProvider theProvider, String name,
+ Color color) {
+
+ ColorMatcher cm = new ColorMatcher(color);
+ Predicate<ClangToken> noIgnores = t -> false;
+ assertAllFieldsHighlighted(theProvider, name, cm, noIgnores);
+ }
+
+ private void assertAllFieldsHighlighted(DecompilerProvider theProvider, String name,
+ ColorMatcher colorMatcher, Predicate<ClangToken> ignore) {
+
+ DecompilerController controller = theProvider.getController();
DecompilerPanel panel = controller.getDecompilerPanel();
List<ClangToken> tokensWithName = panel.findTokensByName(name);
assertFalse(tokensWithName.isEmpty());