使用IDE上下文行为创建Java注释 [英] Create a Java Annotation with IDE contextual behaviour

查看:138
本文介绍了使用IDE上下文行为创建Java注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个注释

  / ** 
*突出显示此方法在XML $ b中声明$ b * /
public @interface FromXML {
}

使用这个方法看起来像这样:

  @FromXML 
public void onSomethingClick(View v){

}

v Android反射系统需要使用变量来调用此方法。
然而,输入的var v 没有使用,所以我的IDE警告我这个。 我喜欢此警告,并希望其余的代码





隐藏我可以做的警告

  @SuppressWarnings(unused)
@FromXML
public void onSomethingClick(View v){

}

或者我可以添加param标签



但是相反,IDE(eclipse)读取我的 @FromXML 注释,并没有给我警告。



我知道您不能扩展注释,但是这基本上是我想要做的。



有没有办法我可以添加我的注释来被识别为抑制警告s '注释。





有没有办法将我的注释编码为喜欢'抑制警告'

解决方案

确定我不能以任何简单的方式或形式来做到这一点。
$ b

查看注释包 http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/package-summary.html



我无法扩展注释:
为什么不能在Java中扩展注释?



我无法实现另一个注释 java.lang.Override



我不能模仿/模拟/假装是 @Override



如果我将 @Override 添加到我的 @FromXML 中,它不会继承下来。



唯一的办法是创建一个可以识别我的注释并停止警告的Eclipse插件。耻辱,因为我找不到一个简单的方法来做到这一点。



我也下了创建一个接口为我的路由,我的 @FromXML 入门点,这是非常好的,并传达我的活动是一种类型,因此我不需要注释了,也许这个设计更改是答案。


I've created an Annotation

/**
 * Highlights this method is declared in XML
 */
public @interface FromXML {
}

I'm using this on methods that look like this:

@FromXML
public void onSomethingClick(View v){

}

The v variable is needed by the Android reflection system to call this method. However the input var v is unused, so my IDE warns me of this. I like this warning and want it on for the rest of my code.

To hide the warning I could do

@SuppressWarnings("unused")
@FromXML
public void onSomethingClick(View v){

}

or I could add a param tag

But I would rather that the IDE (eclipse) reads my @FromXML annotation and doesn't give me the warning.

I know you can't extend an Annotation, but thats basically what I want to do.

Is there a way I can add my annotation to be recognised as a 'suppress warnings' annotation.

or

Is there a way to code my annotation to 'act like' suppress warnings?

解决方案

Ok I can't do this in any easy way or form.

Looking at the annotation package http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/annotation/package-summary.html

I can't extend an annotation: Why is not possible to extend annotations in Java?

I can't implement another annotation java.lang.Override

I can't mimic / mock / pretend to be @Override

If I add @Override to my @FromXML it is NOT inherited down the chain.

The only way would be to create an Eclipse plugin that recognises my annotation and stops the warning. Shame because I can't find an easy way to do this.

I also went down the route of creating an interface for my @FromXML entry points, this was very nice and communicated my Activity was of a type and therefore I didn't need the annotation anymore, perhaps this design change is the answer.

这篇关于使用IDE上下文行为创建Java注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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