gpt4 book ai didi

java - CodeNarc 的静态代码分析无法找到正确的类依赖关系

转载 作者:行者123 更新时间:2023-12-02 00:06:19 24 4
gpt4 key购买 nike

当使用 CodeNarc 对 Groovy 和 Grails 代码进行静态代码分析时,它无法找出类层次结构。在一个服务类(例如 BaseService)中有一个私有(private)方法。另一个服务类是 ChildService 扩展了 BaseService 类。 ChildService 中的方法之一调用 BaseService 中定义的私有(private)方法。但是 BaseService 类在其自己的类中的任何地方都没有使用私有(private)方法。因此,当单独分析BaseService类时,私有(private)方法将显示为未使用。但是当我们查看类层次结构时,我们可以理解它的一个子类正在调用它。
所以,我的问题是,CodeNarc 如何错过这种依赖关系?静态代码分析器不构建解析树并对其进行分析吗?如果不是,它如何分析代码?任何对静态代码分析内部结构的深入了解都将受到高度赞赏。
谢谢。

最佳答案

正如 documentation for codenarc 中所述:

UnusedPrivateMethod Rule

Checks for private methods that are not referenced within the sameclass. Note that the private modifier is not currently "respected" byGroovy code (i.e., Groovy can access private members within otherclasses).

Known limitations:

  • Does not recognize method reference through property access (e.g.getName() accessed as x.name)
  • Does not recognize method invocationswhen method name is a GString (e.g. this."$methodName"())
  • Does not recognize invoking private method of another instance (i.e. other thanthis)
  • Does not differentiate between multiple private methods with thesame name but different parameters (i.e., overloaded)
  • Does not checkfor unused constructors

所以你要have to turn this rule off .

关于java - CodeNarc 的静态代码分析无法找到正确的类依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13803469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com