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());
newMiddleMouse.apply();
activeMiddleMouse = newMiddleMouse;
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,8 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import docking.widgets.EventTrigger;
import docking.widgets.fieldpanel.field.Field;
import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.app.decompiler.ClangSyntaxToken;
import ghidra.app.decompiler.ClangToken;
import ghidra.app.decompiler.*;
/**
* Class to handle location based highlights for a decompiled function.
@@ -47,10 +46,23 @@ public class LocationClangHighlightController extends ClangHighlightController {
return; // do not highlight whitespace
}
addPrimaryHighlight(tok, defaultHighlightColor);
if (tok instanceof ClangOpToken) { // e.g., '='
return;
}
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);
addPrimaryHighlightToTokensForBrace((ClangSyntaxToken) tok, defaultParenColor);
}
else {
addPrimaryHighlight(tok, defaultHighlightColor);
}
}
}