GP-5414 - Decompiler - Updated highlighting to ignore syntax tokens

This commit is contained in:
dragonmacher
2025-03-04 17:26:33 -05:00
parent 6d4f6e0854
commit 99659967e2
2 changed files with 22 additions and 5 deletions
@@ -262,6 +262,11 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
} }
} }
// exclude tokens that users do not want to highlight
if (token instanceof ClangSyntaxToken || token instanceof ClangOpToken) {
return;
}
ActiveMiddleMouse newMiddleMouse = new ActiveMiddleMouse(token.getText()); ActiveMiddleMouse newMiddleMouse = new ActiveMiddleMouse(token.getText());
newMiddleMouse.apply(); newMiddleMouse.apply();
activeMiddleMouse = newMiddleMouse; activeMiddleMouse = newMiddleMouse;
@@ -20,8 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import docking.widgets.EventTrigger; import docking.widgets.EventTrigger;
import docking.widgets.fieldpanel.field.Field; import docking.widgets.fieldpanel.field.Field;
import docking.widgets.fieldpanel.support.FieldLocation; import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.app.decompiler.ClangSyntaxToken; import ghidra.app.decompiler.*;
import ghidra.app.decompiler.ClangToken;
/** /**
* Class to handle location based highlights for a decompiled function. * Class to handle location based highlights for a decompiled function.
@@ -47,10 +46,23 @@ public class LocationClangHighlightController extends ClangHighlightController {
return; // do not highlight whitespace return; // do not highlight whitespace
} }
addPrimaryHighlight(tok, defaultHighlightColor); if (tok instanceof ClangOpToken) { // e.g., '='
return;
}
if (tok instanceof ClangSyntaxToken) { if (tok instanceof ClangSyntaxToken) {
int type = tok.getSyntaxType();
if (type == ClangToken.GLOBAL_COLOR) {
// namespaces can fit this case sometimes
addPrimaryHighlight(tok, defaultHighlightColor);
}
addPrimaryHighlightToTokensForParenthesis((ClangSyntaxToken) tok, defaultParenColor); addPrimaryHighlightToTokensForParenthesis((ClangSyntaxToken) tok, defaultParenColor);
addPrimaryHighlightToTokensForBrace((ClangSyntaxToken) tok, defaultParenColor); addPrimaryHighlightToTokensForBrace((ClangSyntaxToken) tok, defaultParenColor);
} }
else {
addPrimaryHighlight(tok, defaultHighlightColor);
}
} }
} }