Thursday, May 8, 2014

Sevntu Checkstyle release 1.11.0


official page: http://sevntu-checkstyle.github.io/sevntu.checkstyle/#1.11.0


 New and noteworthy:

1) new Check "Enum Values Check", issue, done by Pavel Baranchikov.

Check forces enum values to match the specific pattern. According to "Java Coding Style" by Achut Reddy p 3.3 constants include "all static final object reference types that are never followed by " ." (dot).", i.e. enums, which are followed by dot while used in the code are to be treated as static object references, while enums, that are not used with following dot, should be treated as constants.
Enums are defined to be used as class have some own methods. This condition is used to distinguish between Values Enumeration and Class Enumeration. Values Enumeration looks like the following:
enum SimpleErrorEnum
  {
      FIRST_SIMPLE, SECOND_SIMPLE, THIRD_SIMPLE;
  }
While Class Enumeration has some methods, for example:
 enum SimpleErrorEnum
   {
       FIRST_SIMPLE, SECOND_SIMPLE, THIRD_SIMPLE;
 
       public String toString() {
           return Integer.toString(ordinal() + 10);
       }
   }
Name format for Class Enumeration is specified with setObjFormat(String) , while format for enum constants - with setConstFormat(String)
To avoid assuming enum as static object reference, while using some specific methods, setExcludes(List) can be used. For example to make enum in the previous example a constant set Excludes property to a value toString
By default toString is used as an exclusion.

2) new Check "Map Iteration In For Loop", issue, done by Max Vetrenko

This check can help you to write the whole for-each map iteration more correctly:
  1. If you iterate over a map using map.keySet() or map.entrySet(), but your code uses only map values, Check will propose you to use map.values() instead of map.keySet() or map.entrySet(). Replacing map.keySet() or map.entrySet() with map.values() for such cases can a bit improve an iteration performance.Bad:
    for (Map.Entry; entry : map.entrySet()){
       System.out.println(entry.getValue());
    }
    for (String key : map.keySet(){
       System.out.println(map.get(key));
    }
    Good:
    for (String value : map.values()){
       System.out.println(value);
    }
  2. If you iterate over a map using map.entrySet(), but never call entry.getValue(), Check will propose you to use map.keySet() instead of map.entrySet(). to iterate over map keys only.Bad:
    for (Map.Entry entry : map.entrySet()){
       System.out.println(entry.getKey());
    }
    Good:
    for (String key : map.keySet()){
       System.out.println(key);
    }
  3. If you iterate over a map with map.keySet() and use both keys and values, check will propose you to use map.entrySet() to improve an iteration performance by avoiding search operations inside a map. For this case, iteration can significantly grow up a performance.Bad:
    for (String key : map.keySet()){
       System.out.println(key + "  " + map.get(key));
    }
    Good:
    for (Map.Entry entry : map.entrySet()){
       System.out.println(entry.getValue() + "   " + entry.getKey());
    }


3) new check "Forbid Throw Anonymous Exception", issue, done by Max Vetrenko.

Forbid throwing anonymous exception. limitation: This Check does not validate cases then Exception object is created before it is thrown.
For example:
catch (Exception e) {
   throw new RuntimeException() { //anonymous exception
    //some code
   };


4) new check "Finalize Implementation", issue, done by Max Vetrenko.

This Check detects 3 most common cases of incorrect finalize() method implementation:
  • negates effect of superclass finalize
    protected void finalize() { }
    protected void finalize() { doSomething(); }
  • useless (or worse) finalize
    protected void finalize() { super.finalize(); }
  • public finalize
    public void finalize() {
       try { doSomething(); } 
       finally { super.finalize(); } 
    }
    


5) Update for CustomDeclarationOrderCheck, issue, done by Baratali Izmailov.

details, In short:
1) macros for Fields with assigning to Anonymous classes
2) macros for Setter/Geter
3) macros for nested interfaces, nested enumarations
4) Inner Classes in methods are ignored
5) macros for "main()" method

Format with usage of all marcoses could be found there.

General information:
repository: https://github.com/sevntu-checkstyle/sevntu.checkstyle
mail-list: https://groups.google.com/forum/?hl=en#!forum/sevntu-checkstyle

No comments:

Post a Comment