JAXB如何从JDefinedClass中删除任何内容 [英] JAXB how to remove anything from JDefinedClass

查看:77
本文介绍了JAXB如何从JDefinedClass中删除任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jaxb从xsd生成代码。

i am using jaxb to generate code from an xsd.

生成的代码包含大量注释;对于类和字段。

The generated code contains a lot of annotations; for classes and fields.

我正在尝试使用 com.sun.tools.internal.xjc.Plugin 来修改生成的代码。

I am trying to use com.sun.tools.internal.xjc.Plugin to modify the generated code.

在插件 run()方法中,我们得到一个概述类,我们可以从中获得 ClassOutline ClassOutline 有一个 JDefinedClass 最终成员,其中包含将要生成的实际类的信息。

In the plugin run() method we are given an Outline class from which we can get ClassOutline. ClassOutline has an JDefinedClass final member which has the info about actual class which will be generated.

如果我想添加任何内容,可以使用 JDefinedClass 中的apis。但如果我想删除某些东西,就没有办法了。

If i want to add anything, there are apis in JDefinedClass which can be used. But if i want to remove something, there is no way.

例如。我无法清除注释,因为 JDefinedClass.annotations()方法返回 UnmodifiableCollection 。所以我无法清除它或从中移除任何东西。

e.g. i cannot clear annotations, because the JDefinedClass.annotations() method returns an UnmodifiableCollection. so i cannot clear it or remove anything from it.

我试图通过调用<$创建另一个 JDefinedClass c $ c> _class 方法,但 ClassOutline.implClass 变量是最终的,所以我无法设置它。

i tried to create another JDefinedClass by invoking the _class method but the ClassOutline.implClass variable is final, so i cannot set it.

如何获得没有任何注释的 JDefinedClass

how to get a JDefinedClass which does not have any annotations?

还有另一个阶段代码生成,我可以陷入真正控制 JDefinedClass 的生成?

is there another phase of code generation which i can trap into to really control the generation of JDefinedClass?

推荐答案

代码模型确实主要是只写。但是,谈到注释,你可能错过了像 com.sun.codemodel.JDefinedClass.removeAnnotation(JAnnotationUse) com.sun.codemodel这样的方法。 .JMethod.removeAnnotation(JAnnotationUse)(从 com.sun.codemodel.JAnnotatable.removeAnnotation(JAnnotationUse)实现)。

The code model is, indeed mostly "write only". But, speaking of annotations, you have probably missed the methods like com.sun.codemodel.JDefinedClass.removeAnnotation(JAnnotationUse) and com.sun.codemodel.JMethod.removeAnnotation(JAnnotationUse) (implemented from com.sun.codemodel.JAnnotatable.removeAnnotation(JAnnotationUse)).

所以他们在那里。您可以使用普通的CodeModel API删除注释。

So they're there. You can remove annotations with the normal CodeModel API.

正如我所看到的,您还可以从类中删除字段和方法。那你到底错过了什么?

As I can see, you can also remove fields and methods from classes. So what exactly are you missing?

这篇关于JAXB如何从JDefinedClass中删除任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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