IllegalType: added more classes from Collections

This commit is contained in:
Paul Campbell 2016-09-08 20:03:11 +01:00
parent d3136df134
commit 0c12b97cd2
2 changed files with 15 additions and 6 deletions

View file

@ -1197,16 +1197,23 @@ Checks that labels are not used.
#### [IllegalType](http://checkstyle.sourceforge.net/config_coding.html#IllegalType) #### [IllegalType](http://checkstyle.sourceforge.net/config_coding.html#IllegalType)
Prevents variables, parameters and method returns from being one of the following: Prevents use of implementation classes as variables, parameters or method returns. Use the interfaces instead.
* java.util.HashSet Prevents variables, parameters and method returns from being any of the following:
* java.util.ArrayDeque
* java.util.ArrayList
* java.util.EnumMap
* java.util.EnumSet
* java.util.HashMap * java.util.HashMap
* java.util.HashSet
* java.util.IdentityHashMap
* java.util.LinkedHashMap * java.util.LinkedHashMap
* java.util.LinkedHashSet * java.util.LinkedHashSet
* java.util.TreeSet * java.util.LinkedList
* java.util.PriorityQueue
* java.util.TreeMap * java.util.TreeMap
* java.util.TreeSet
> TODO: add more classes from Collections
Valid: Valid:
```` ````

View file

@ -100,7 +100,9 @@
<module name="IllegalImport"/> <!-- prevent imports from the sun.* package --> <module name="IllegalImport"/> <!-- prevent imports from the sun.* package -->
<module name="IllegalThrows"/> <!-- prevent generic throws (i.e. Exception, Throwable, RuntimeException) --> <module name="IllegalThrows"/> <!-- prevent generic throws (i.e. Exception, Throwable, RuntimeException) -->
<module name="IllegalToken"/> <!-- prevents use of labels --> <module name="IllegalToken"/> <!-- prevents use of labels -->
<module name="IllegalType"/> <!-- prevents variables, returns or parameters of non-interface Collections classes --> <module name="IllegalType"> <!-- prevents variables, returns or parameters of non-interface Collections classes -->
<property name="illegalClassNames" value="java.util.ArrayDeque, java.util.ArrayList, java.util.EnumMap, java.util.EnumSet, java.util.HashMap, java.util.HashSet, java.util.IdentityHashMap, java.util.LinkedHashMap, java.util.LinkedHashSet, java.util.LinkedList, java.util.PriorityQueue, java.util.TreeMap, java.util.TreeSet"/>
</module>
<module name="InnerAssignment"/> <!-- prevent assignments in subexpressions (i.e. while((line = read()){}) --> <module name="InnerAssignment"/> <!-- prevent assignments in subexpressions (i.e. while((line = read()){}) -->
<module name="InnerTypeLast"/> <!-- inner classes appear after methods and fields --> <module name="InnerTypeLast"/> <!-- inner classes appear after methods and fields -->
<module name="InterfaceIsType"/> <!-- interface must define method not just constants --> <module name="InterfaceIsType"/> <!-- interface must define method not just constants -->