开发者

Static analysis tool for Java that reports subclassing/implementing specific classes?

开发者 https://www.devze.com 2023-02-10 09:40 出处:网络
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

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:

  1. http://www.ibm.com/developerworks/library/j-findbug2/
  2. 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 }
0

精彩评论

暂无评论...
验证码 换一张
取 消