checkstyle - prohibit initializing object of type -
suppose have external library class called foo. can't change foo have private constructor, have foofactory class wrote.
so have foofactory.getafoo()
want checkstyle catch new foo()
in rest of code, force using factory.
i have this:
<module name="illegaltokentext"> <property name="tokens" value="literal_new"/> <property name="format" value="foo"/> </module>
but doesn't seem detect new foo()
.
i use regex cleaner.
i had similar problem preventing extending class:
<module name="illegaltokentext"> <property name="tokens" value="extends_clause"/> <property name="format" value="androidtestcase"/> </module>
neither of these checkstyle module seem @ all.
what doing wrong?
illegaltokentext checks illegal text on token itself, not on subsequent ident tokens or such. why seems nothing in case.
in case, may want try using sevntu checkstyle extension, offers check called forbidinstantiation might solve problem. have no documentation aware of, linking source code javadoc. when use sevntu checkstyle, sure use right versions of regular checkstyle , sevntu checkstyle, because not combinations compatible (overview).
if not help, have roll own.
Comments
Post a Comment