Static analysis tool for Java that reports subclassing/implementing specific classes?
We just refactored several implementations of ThreadFactory into a single class. I'd like to set up a build which will report if new implementations of ThreadFactory get checked 开发者_JAVA百科in.
Two solid utilities are:
FindBugs
PMD
Why don't you just make ThreadFactory final if you don't want it to be subclassed? The modifier can be removed if later you decide a subclass is indeed needed.
You can write custom detector for FindBugs:
- http://www.ibm.com/developerworks/library/j-findbug2/
- http://www.danielschneller.com/2007/05/findbugs-writing-custom-detectors-part.html
You can use JArchitect for such need. For that you have to set a baseline from which you want to detect the new implementations and add the following rule using cqlinq
from t in Types
let depth0 = t.DepthOfDeriveFrom("ThreadFactory")
where depth0 == 1 && !t.IsInOlderBuild()
select new { t, depth0 }
精彩评论