Missing inspection ?


Is there an inspection that detects that in the code below,

boolean doDebug = Level1.DEBUG;

could be tightened into:
boolean doDebug = Level0.DEBUG;

6 comments


No, but there will be in within the next couple of EAP releases. Good one. Someone assign this to me, please.

--Dave Griffith

0

Refactor|Use Interface where possible.

--
regards,
Alexey Kudravtsev
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


"Alain Ravet" < alainravet-jetbrains@yahoo.com> wrote in message
news:22306215.1100359806388.JavaMail.itn@is.intellij.net...
>

Is there an inspection that detects that in the code below,

>

boolean doDebug = Level1.DEBUG;

>

could be tightened into:
boolean doDebug = Level0.DEBUG;

>
>

 public  class Level0  {
>    public final static boolean DEBUG=false;
> }
>
> public class Level1 extends Level0 {
> }
>
> public class Spike {
>    public static void main (String[] args)    {
>        boolean doDebug = Level1.DEBUG;
>        System.out.println ("doDebug = " + doDebug);
>    }
> }
> ]]>



0

Alexey

>Refactor|Use Interface where possible.

>


First you inspect, then you refactor;
We need a real inspection, to find the interfaces to use where possible.

Alain

0


Won't work unless LevelO is an interface, yes? In any case, the point of an inspection is to act as a sensor for the issue, not just a fix if you happen to run across it.

--Dave Griffith

0

The issue being not relying on the class referenced always inheriting from the parent class? Thus a tightening of the reference?

0


I had pegged the issue as simpler, namely that you shouldn't rely on Java's half-assed semantics for "inheritance" of static fields or methods. If you want to access a static, use .]]>. There are already inspections for avoiding accessing a static via an instance and accessing a static implicitly (name only if you're in the same class). This is just a stylistic tightening up of the access pattern (although like many stylistic inspections it can find real bugs hiding in bad style as well).

--Dave Griffith

0

Please sign in to leave a comment.