Repository navigation
Log points to easily dump content of local variables #9732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jtulach
wants to merge
13
commits into
apache:master
Choose a base branch
from
jtulach:jtulach/LogPoints
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+447
−152
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
978f6ce
Log point easily dumping local variables
jtulach 8685bd7
Using {lineNumber} placeholder
jtulach 8ad2c53
Only enable the logpoint action on Java sources
jtulach 64af419
Removing unnecessary imports
jtulach 15eb8c4
Unit testing printLocals
jtulach e644433
Valid and failing (right now) logpoint review test
jtulach 96ee933
Removing unused import
jtulach 4db2f0a
Variable.toFixed() creates a snapshot of a variable
jtulach 147bcc7
Directly call toFixed()
jtulach 8075fdc
Call it Variable.asValue
jtulach e7a606d
Needs latest version of api.debugger.jpda
jtulach a86773c
Removing unnecessary space
jtulach 87121f3
Expanding tooltip to provide more info
jtulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| Manifest-Version: 1.0 | ||
| OpenIDE-Module: org.netbeans.api.debugger.jpda/2 | ||
| OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties | ||
| OpenIDE-Module-Specification-Version: 3.46 | ||
| OpenIDE-Module-Specification-Version: 3.47 | ||
| OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,18 +138,18 @@ private boolean isPrimitive (Object node) { | |
| ); | ||
|
|
||
|
|
||
| private Map fixedWatches = new LinkedHashMap(); | ||
| private HashSet listeners; | ||
| private ContextProvider contextProvider; | ||
| private Map<KeyWrapper, String> fixedWatches = new LinkedHashMap<>(); | ||
| private HashSet listeners; | ||
| private final ContextProvider contextProvider; | ||
|
|
||
|
|
||
| public FixedWatchesManager (ContextProvider contextProvider) { | ||
| this.contextProvider = contextProvider; | ||
| } | ||
|
|
||
| public void deleteAllFixedWatches() { | ||
| Collection nodes = new ArrayList(fixedWatches.keySet()); | ||
| for (Iterator iter = nodes.iterator(); iter.hasNext();) { | ||
| Collection<KeyWrapper> nodes = new ArrayList<>(fixedWatches.keySet()); | ||
| for (Iterator<KeyWrapper> iter = nodes.iterator(); iter.hasNext();) { | ||
| fixedWatches.remove(iter.next()); | ||
| fireModelChanged(new ModelEvent.NodeChanged(FixedWatchesManager.this, | ||
| TreeModel.ROOT, | ||
|
|
@@ -361,18 +361,9 @@ private void createFixedWatch (Object node) { | |
| } | ||
| } | ||
|
|
||
| public void addFixedWatch (String name, Variable variable) { | ||
| public void addFixedWatch (String name, Variable orig) { | ||
| // Clone the variable to assure that it's unique and sticks to the JDI value. | ||
| if (variable instanceof Cloneable) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| try { // terrible code to invoke the clone() method | ||
| java.lang.reflect.Method cloneMethod = variable.getClass().getMethod("clone", new Class[] {}); | ||
| cloneMethod.setAccessible(true); | ||
| Object newVar = cloneMethod.invoke(variable, new Object[] {}); | ||
| if (newVar instanceof Variable) { | ||
| variable = (Variable) newVar; | ||
| } | ||
| } catch (Exception ex) {} // Ignore any exceptions | ||
| } | ||
| Variable variable = orig.asValue(); | ||
| fixedWatches.put (new KeyWrapper(variable), name); | ||
| fireModelChanged (new ModelEvent.NodeChanged( | ||
| this, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor points about
{locals}:{locals}is printed literally.Both are fine if documented, but I couldn't find
{locals}mentioned anywhere a user would see it, e.g. near the print text field in the breakpoint customizer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. That's the intention. I considered it, but dumping all the local variables (inherently multi line) in the middle of the (single line) message seem inappropriate.
Should it be also removed? I guess we don't need to dump the variables twice, right?
Where do you want me to add a reference to
{locals}? If there is some suitable place I happily add some text there. However I think the wholeBreakpointOutputinfrastructure{=expr},{className}, etc. is mostly undocumented. Which my be the reason why not many people found they can configure log points themselves.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing the locals after the message makes sense to me. Yes, I'd remove every occurrence and print the locals once.
For documentation, the print text field in
ActionsPanel(tfPrintText) has no tooltip. A tooltip listing the placeholders ({className},{methodName},{lineNumber},{threadName},{=expression},{locals}) would be a small, natural place to put it, and it would cover the undocumented ones you mentioned too. It doesn't need to be part of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tooltip expanded in 87121f3 now it looks like