Feature Request: Select block of code/method, hit key, shows example execution
Here's a feature that I think could offer a major advantage for IntelliJ - as important as code navigation and refactoring.
Imagine I have some code:
public String doSomething(String s) { return s + " hello " + s.trim(); }
And some other code:
// bunch of stuff
doSomething(someString)
Now, currently, with the cursor on doSomething, I can hit ctrl-shift-i to show the underlying code.
What would be awesome is if I could hit another keystroke (or maybe the same) and it would popup a table showing some example inputs and results.
Eg
Input | Results |
---|---|
null | NPE |
"" | " hello " |
"example" | "example hello example" |
" example " | " example hello example" |
"Exa MPLE" | "Exa MPLE hello Exa MPLE" |
Potential issues:
- coming up with list of inputs - really not that hard - for Strings, the list above would be enough to cater for a lot of cases - alternatively, it could be interactive, have an editable textbox for each input, run the code and update the results on the fly as you type, like the Regex plugin
- complex parameters - ie compound objects - that's ok, just don't support that use case initially, just handling Strings and primitives would be great initially
If not a core part of the product, maybe someone keen could hack up a plugin to demonstrate the concept.
BTW I originally posted this in the EAP discussion group but then looked at the list of recent messages and it appears very dead... - so posting it here instead.
Please sign in to leave a comment.
I think this cannot be implemented in any useful way.
There are simply too many potential inputs/outputs/side effects to the code. How about arbritratry objects that are passed to code (how would you supply a JFrame or a hibernate session object to the code). How should IDEA setup referenced object graphs?
If I want to test-drive the code I use the debugger or write unit tests. Also I would complain to the original developer about missing Javadoc.
How would you handle JFrame or hibernate objects? Don't deal with those cases.
There are a lot of complexities but that's what JetBrains are good at dealing with.
The same kind of objections were probably voiced before the Extract Method refactoring became common. There are all sorts of cases where a code selection means that extract method is not possible - don't worry about those, work on the cases where it can work.
Complaining to the original dev is not an option when you're working on some 8 year old codebase at Megacorp X.