Question

I want to run certain inspection on Java project. I see this inspection working in real-time in edit window. But when I use "Analyze -> Run Inspection By Name" I can't find this inspection. Actually there is one with the same name but it's for JavaScript(tried it though, not working, as expected). Can anyone tell me exact name of inspection I need or teach me how to figure it out?

Here's code sample:

private Integer getInteger(){
    //x on the line below will be highlighted by inspection saying
    // "Local variable 'x' is redundant more... (Ctrl+F1)"
    Integer x = 5;
    return x;
}

Update: I managed to launch needed inspection using workaround. I created test case like above, then pressed Alt+Enter on highlighted region then right arrow key and selected "Run inspection on".enter image description here This is working, but still leaves unclear how to run same inspection via "Analyze -> Run Inspection By Name"

Was it helpful?

Solution 3

This was caused by a bug, which was fixed in IntelliJ IDEA 14.

OTHER TIPS

I get the "Local variable 'i' is redundant message" (and a "yellow" analysis) when I type this code:

public int testMe()
{
   int i = 5;  // The 'i' is highlighted
   return i;
}

I can suppress this warning (and get a "green" analysis, no warnings), by adding this annotation:

@SuppressWarnings("UnnecessaryLocalVariable")
public int testMe()
{
   int i = 5;
   return i;
}

Try "Redundant Local Variable". This seems to be the description to match the annotation, according to this list of suppress warnings arguments.

Warning Description         Warning Name
Redundant local variable    UnnecessaryLocalVariable

In my IntelliJ IDEA 12.1.5 it's called Redundant local variable, I think.

Your x is redundant because you are not using that variable anywhere in that scope, besides returning it. And so that code

Integer x = 5;
return x;

can be simplified to

return 5;

Yet to avoid "magic numbers" like return 5; you could assign it to a class constant (private static final Integer X = 5;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top