#573 new check: VariableDeclarationUsageDistanceCheck

Future
closed
nobody
Check (274)
5
2013-11-17
2011-05-08
No

Check distance between declaration of variable and its first usage of it.
To developer: be aware of blocks { ... } and declaration out the block and usage inside of block - this is a bit complicate the task of detection such cases.
Options:
- Allowed distance (in rows count); Default is 0;
- Ignore variable names (regexp). Default is "";

Problematic code :
int count;
a=a+b;
b=a+a;
count = b; // DECLARATION SHOULD BE HERE

Problematic code:
int count;
{
a=a+b;
count = b; // DECLARATION SHOULD BE HERE
}

Correct code:
int count;
{
a=a+b;
count = b;
}
count = 1;

Discussion

  • Roman Ivanov

    Roman Ivanov - 2012-05-30

    Cases that VariableDeclarationUsageDistanceCheck have to support
    1.
    int mm = Integer.parseInt(time.substring(div + 1).trim());

    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timeNow);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.HOUR_OF_DAY, hh);
    cal.set(Calendar.MINUTE, mm);
    

    2.
    Option srcDdlFile = OptionBuilder.create("f");
    Option logDdlFile = OptionBuilder.create("o");
    Option help = OptionBuilder.create("h");

    Options options = new Options();
    options.addOption(srcDdlFile, logDdlFile, help);
    
     
  • Ivan Sopov

    Ivan Sopov - 2013-11-17

    Implemented in sandbox sevntu.checktyle project.

     
  • Ivan Sopov

    Ivan Sopov - 2013-11-17
    • status: open --> closed
    • Group: --> Future
     

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

Sign up for the SourceForge newsletter:





No, thanks