的IntelliJ /爪哇 - 识别注解的方法的调用 [英] Intellij/ Java - identify calls to annotated methods

查看:120
本文介绍了的IntelliJ /爪哇 - 识别注解的方法的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够识别通话与IntelliJ IDEA的13个具体的注释,在编译时的方法或使用静态code分析,来电来样@标识德precated方法。

我看着在做想法结构的搜索,这些静态code分析的支持,并且我能够找出方法从那里调用,但我不能找到一种方法,这些限制在调用方法与注解。

例如

 公共类A {
  @foo
  公共无效美孚(){
    // 做一点事...
  }  公共无效栏(){
    //做别的事情....
  }}公共类主要{
  公共静态无效的主要(字符串参数... args){
    A中新= A();    a.foo(); //< ----应强调
    一间酒吧();
  }
}


解决方案

您可以在IDEA做到这一点(这将涉及使用IDEA的内部接口;我不知道随便哪一个提供访问注释)。

根据您的使用情况下,另一种选择是使用外部工具,如检查框架。的优点是,它在外部支持的,并具有大量的现有功能,所以将有少自己code编写和维护的。此外,谁不使用IDEA其他人将能够运行分析。的缺点是,将有与IDE少紧密集成;你需要配置IDEA运行分析,这很简单。

I need to be able to identify calls to methods with specific annotations in Intellij Idea 13, during compile time or by using static code analysis, like calls to @Deprecated methods are identified.

I have looked into doing a structural search in idea, these are supported in static code analysis, and am able to identify method calls from there, but I can't find a way to limit these to calls to method with annotations.

For example

public class A {
  @Foo
  public void foo(){
    // do something... 
  }

  public void bar() {
    // do something else.... 
  }

}

public class main {
  public static void main(String... args){
    A a = new A();

    a.foo(); // <---- should be highlighted
    a.bar();
  }
}

解决方案

You could do this in IDEA (which would involve using IDEA's internal interfaces; I don't know offhand which ones give access to annotations).

Depending on your use case, another alternative would be to use an external tool such as the Checker Framework. The advantage is that it is externally supported and has a lot of existing functionality, so there would be less of your own code to write and maintain. Additionally, other people who don't use IDEA would be able to run the analysis. The disadvantage is that there would be less tight integration with the IDE; you would need to configure IDEA to run the analysis, which is straightforward.

这篇关于的IntelliJ /爪哇 - 识别注解的方法的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆