#43 Check member usage

release_3.2
closed
Check (274)
5
2012-10-10
2002-03-04
No

It would be nice to check if a private member of a class is used in the
class, and to emit a warning if not. It would be nice to warn the user
about class members used only in one method (and initialized within
this method), they could be declare as method local
variables.

Ex :

class MyClass
{
private int mMyInt =
0;
private float mMyFloat = 3.2f;

public void doTheJob()

{
for (mMyInt = 0; mMyInt<6; mMyInt++)
{

System.out.println(mMyInt);
}
}
}

should be
rewritten:

class MyClass
{
public void doTheJob()
{

for (int mMyInt = 0; mMyInt<6; mMyInt++)
{

System.out.println(mMyInt);
}
}
}

Discussion

  • Oliver Burn

    Oliver Burn - 2002-03-07

    Logged In: YES
    user_id=218824

    Great idea! I am already planning to add support for this.
    Thanks for the confidence that it is a good idea. :-)

     
  • Oliver Burn

    Oliver Burn - 2002-09-08

    Logged In: YES
    user_id=218824

    I have added support for detecting unused private varaibles.

     
  • Vivek Venugopalan

    Logged In: YES
    user_id=131737

    Unused private variables check is great but it would be even
    better if you can check for one time usage only and
    recommend that the member variable should actually be a
    local variable. That will catch a lot of unncessary member
    variables in code. Reducing object bulk.

     
  • Rick Giles

    Rick Giles - 2003-07-26

    Logged In: YES
    user_id=539926

    Covered by checks in package
    com.puppycrawl.tools.checkstyle.checks.usage of the 3.2 CVS

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks