使用带有JDT的带注释参数编写Java方法签名

时间:2023-01-14 11:59:14

I am writing an eclipse plug-in which generates code. I am leveraging eclipse jdt to gen out classes, fields, and methods. One of the requirements I have is to generate methods with annotated paramaters...

我正在编写一个生成代码的eclipse插件。我正在利用eclipse jdt来创建类,字段和方法。我的要求之一是生成带有注释参数的方法......

public returnType foo(@someAnnotation int id)
{
     .....
     .....
}

Does anybody know how to write out the @someAnnotation using JDT? To write out normal parameters in JDT you could do something like the following

有人知道如何使用JDT写出@someAnnotation吗?要在JDT中写出正常参数,您可以执行以下操作

Signature.createTypeSignature("int", false)

2 个解决方案

#1


Have you tried debugging the creation of a type signature with an annotation and inspect the parameters passed to createTypeSignature?

您是否尝试使用注释调试类型签名的创建并检查传递给createTypeSignature的参数?

#2


Yes I have tried this. The createTypeSignature() function does validation on the String that is passed to it. When it sees something like the following it throws an exception...

是的,我试过这个。 createTypeSignature()函数对传递给它的String进行验证。当它看到类似下面的内容时会引发异常......

Signature.createTypeSignature("@PathParam(\"custId\") int");

Hope this clears it up, and thanks for the response. Let me know if you have any other ideas.

希望这清除它,并感谢您的回应。如果您有任何其他想法,请告诉我。

#1


Have you tried debugging the creation of a type signature with an annotation and inspect the parameters passed to createTypeSignature?

您是否尝试使用注释调试类型签名的创建并检查传递给createTypeSignature的参数?

#2


Yes I have tried this. The createTypeSignature() function does validation on the String that is passed to it. When it sees something like the following it throws an exception...

是的,我试过这个。 createTypeSignature()函数对传递给它的String进行验证。当它看到类似下面的内容时会引发异常......

Signature.createTypeSignature("@PathParam(\"custId\") int");

Hope this clears it up, and thanks for the response. Let me know if you have any other ideas.

希望这清除它,并感谢您的回应。如果您有任何其他想法,请告诉我。