Package ghidra.app.decompiler.component
Class ClangHighlightController
java.lang.Object
ghidra.app.decompiler.component.ClangHighlightController
- Direct Known Subclasses:
LocationClangHighlightController
,NullClangHighlightController
Class to handle highlights for a decompiled function.
This class does not paint 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.
This class maintains the following types of highlights:
- Context Highlights - triggered by user clicking and some user actions; considered transient and get cleared whenever the location changes. These highlights show state such as the current field, impact of a variable (via a slicing action), or related syntax (such as matching braces)
- Secondary Highlights - triggered by the user to show all occurrences of a particular variable; they will stay until they are manually cleared by a user action. The user can apply multiple secondary highlights at the same time, with different colors for each highlight. These highlights apply to the function in use when the highlight is created. Thus, each function has a unique set of highlights that is maintained between decompilation.
- Global Highlights - triggered by clients of the
DecompilerHighlightService
; they will stay until the client of the service clears the highlight. These highlights apply to every function that is decompiler.
When multiple highlights overlap, their colors will be blended.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addHighlighter
(ghidra.app.decompiler.component.ClangDecompilerHighlighter highlighter) void
addHighlighterHighlights
(DecompilerHighlighter highlighter, Supplier<? extends Collection<ClangToken>> tokens, ColorProvider colorProvider) void
addListener
(ClangHighlightListener listener) protected void
addPrimaryHighlight
(ClangToken token, Color highlightColor) void
addPrimaryHighlights
(ClangNode parentNode, ColorProvider colorProvider) void
addPrimaryHighlights
(ClangNode parentNode, Set<PcodeOp> ops, Color hlColor) protected void
addPrimaryHighlightToTokensForBrace
(ClangSyntaxToken token, Color highlightColor) protected List
<ClangToken> addPrimaryHighlightToTokensForParenthesis
(ClangSyntaxToken tok, Color highlightColor) If input token is a parenthesis, highlight all tokens between it and its matchvoid
addSecondaryHighlighter
(Function function, DecompilerHighlighter highlighter) Adds the given secondary highlighter, but does not create any highlights.void
void
dispose()
static ClangHighlightController
abstract void
fieldLocationChanged
(FieldLocation location, Field field, EventTrigger trigger) Returns the current highlight color for the given token, based upon all known highlights, primary, secondary and highlightersReturns the color provider used by this class to generate colors.Returns all global highlighters installed in this controller.Return the current highlighted token (if exists and unique)getHighlighterHighlights
(DecompilerHighlighter highlighter) Gets all highlights for the given highlighter.getSecondaryHighlight
(ClangToken token) getSecondaryHighlighters
(Function function) Returns all secondary highlighters for the given function.long
An value that is updated every time a new highlight is added.boolean
hasContextHighlight
(ClangToken token) boolean
hasSecondaryHighlight
(ClangToken token) boolean
hasSecondaryHighlights
(Function function) protected void
void
removeHighlighter
(DecompilerHighlighter highlighter) void
removeHighlighterHighlights
(DecompilerHighlighter highlighter) Removes all highlights for this highlighter across all functionsvoid
removeListener
(ClangHighlightListener listener) void
Removes all secondary highlights for the given tokenvoid
Removes all secondary highlights for the given functionvoid
togglePrimaryHighlights
(Color hlColor, Supplier<List<ClangToken>> tokens) Toggles the primary highlight state of the given set of tokens.
-
Field Details
-
DEFAULT_HIGHLIGHT_COLOR
-
defaultHighlightColor
-
defaultParenColor
-
-
Constructor Details
-
ClangHighlightController
public ClangHighlightController()
-
-
Method Details
-
dummyIfNull
-
fieldLocationChanged
public abstract void fieldLocationChanged(FieldLocation location, Field field, EventTrigger trigger) -
getGeneratedColorProvider
Returns the color provider used by this class to generate colors. The initial color selection is random. Repeated calls to get a color for the same token will return the same color.- Returns:
- the color provider
-
getUpdateId
public long getUpdateId()An value that is updated every time a new highlight is added. This allows clients to determine if a buffered update request is still valid.- Returns:
- the value
-
hasContextHighlight
-
hasSecondaryHighlight
-
hasSecondaryHighlights
-
getSecondaryHighlight
-
getSecondaryHighlightColors
-
getPrimaryHighlights
-
getSecondaryHighlighters
Returns all secondary highlighters for the given function. This allows clients to update the secondary highlight state of a given function without affecting highlights applied to other functions.- Parameters:
function
- the function- Returns:
- the highlighters
-
getGlobalHighlighters
Returns all global highlighters installed in this controller. The global highlighters apply to all functions. This is in contrast to secondary highlighters, which are function-specific.- Returns:
- the highlighters
-
getHighlighterHighlights
Gets all highlights for the given highlighter.- Parameters:
highlighter
- the highlighter- Returns:
- the highlights
- See Also:
-
getHighlightedToken
Return the current highlighted token (if exists and unique)- Returns:
- token or null
-
clearPrimaryHighlights
public void clearPrimaryHighlights() -
togglePrimaryHighlights
Toggles the primary highlight state of the given set of tokens. If the given tokens do not all have the same highlight state (highlights on or off), then the highlights will be cleared. If all tokens are not highlighted, then they will all become highlighted.- Parameters:
hlColor
- the highlight colortokens
- the tokens
-
removeSecondaryHighlights
Removes all secondary highlights for the given function- Parameters:
f
- the function
-
removeSecondaryHighlights
Removes all secondary highlights for the given token- Parameters:
token
- the token- See Also:
-
removeHighlighter
-
removeHighlighterHighlights
Removes all highlights for this highlighter across all functions- Parameters:
highlighter
- the highlighter
-
addSecondaryHighlighter
Adds the given secondary highlighter, but does not create any highlights. All secondary highlighters pertain to a given function.- Parameters:
function
- the functionhighlighter
- the highlighter
-
addHighlighter
public void addHighlighter(ghidra.app.decompiler.component.ClangDecompilerHighlighter highlighter) -
addHighlighterHighlights
public void addHighlighterHighlights(DecompilerHighlighter highlighter, Supplier<? extends Collection<ClangToken>> tokens, ColorProvider colorProvider) -
addPrimaryHighlights
-
addPrimaryHighlights
-
addPrimaryHighlight
-
getCombinedColor
Returns the current highlight color for the given token, based upon all known highlights, primary, secondary and highlighters- Parameters:
t
- the token- Returns:
- the color
-
blend
-
addPrimaryHighlightToTokensForBrace
-
addPrimaryHighlightToTokensForParenthesis
protected List<ClangToken> addPrimaryHighlightToTokensForParenthesis(ClangSyntaxToken tok, Color highlightColor) If input token is a parenthesis, highlight all tokens between it and its match- Parameters:
tok
- potential parenthesis tokenhighlightColor
- the highlight color- Returns:
- a list of all tokens that were highlighted.
-
addListener
-
removeListener
-
notifyListeners
protected void notifyListeners() -
dispose
public void dispose()
-