how do i get rid of this warning?

here is some example code

        IReport report = new Report(url, usedFacts, path, reportSpecification, reportName, reportSize.height, reportSize.width);
        return report;

I split the report into a variable instead of just "return new Report(url, usedFacts, path, reportSpecification, reportName, reportSize.height, reportSize.width);" because if I use the debugger I want to be able to inspect the value as I step through the code.

This is fine, except I get a IJ code warning on all cases like this of: "Local variable report is redundant"

I'm guessing everyone runs into this.  Do you just supress that warning or is there a way to see the value of the return value in the debugger?

2 comments
Comment actions Permalink

Hello phil,

Press Alt-Enter, then right arrow to open the inspection settings, check
the checkbox for ignoring immediately returned variables.

here is some example code

IReport report = new Report(url, usedFacts, path,
reportSpecification, reportName, reportSize.height, reportSize.width);
return report;
I split the report into a variable instead of just "return new
Report(url, usedFacts, path, reportSpecification, reportName,
reportSize.height, reportSize.width);" because if I use the debugger I
want to be able to inspect the value as I step through the code.

This is fine, except I get a IJ code warning on all cases like this
of: "Local variable report is redundant"

I'm guessing everyone runs into this. Do you just supress that
warning or is there a way to see the value of the return value in the
debugger?

---
Original message URL:
http://www.jetbrains.net/devnet/message/5242761#5242761

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

philswenson wrote:
is there a way to see the value of the return value in the debugger?

A feature to evaluate the return expression has been requested in the past (see http://www.jetbrains.net/jira/browse/IDEA-2912 and http://www.jetbrains.net/jira/browse/IDEADEV-10996) but has been deemed as something that can't be implemented because the Java debugger itself (i.e. the JPDA API) does not support it.

While this isn't the most eloquent or ideal solutions, when I want to evaluate the return expression of a method, I set a break point on the return line. When the debugger pauses, I do the following key sequence:

  1. esc   //moves focus from 'debug' tool window to editor
  2. Ctrl + right-arrow {twice} //moves cursor past the 'return' keyword to in front of the expression
  3. Shift + end  //selects to end of statement (if multiple lines you can also use shift+down-arrow to get those lines)
  4. Shift + left arrow  //deselects the semi-colon
  5. ctrl +alt + F8 // Evaluates expression at cursor; an alternative would be alt + F8 to open the expression dialog.


Unfortunately I have not been able to get this to work with a macro. Of course, the above can also be done with the mouse.

While my above method may seem like a bit of a pain, it's workable and prevents you from needing to add variables in your code. This is especially important if the code is not under your control. And once you get use to the key sequence after using it a few times, it becomes second nature.

Of course a third option is to do this:

IReport report = new Report(url, usedFacts, path, reportSpecification, reportName, reportSize.height, reportSize.width);
slf4jLogger.debug("FooMethod returning value of {}", report};
return report;

This way the variable is not redundant, and there is some value add to your code in terms of the logging. Just an idea.

Hope that helps.

0

Please sign in to leave a comment.