节俭生成的Java代码生成警告的负载

问题描述:

我们的项目使用了一些节俭生成的类.这些类生成的Java代码会生成几百个警告,其中大多数未使用,并且未声明较长的serialVersionUID(来自Comparable).

Our project uses several thrift-generated classes. The java code generated by these classes is generating several hundred warnings, most of them unused imports and not declaring a long serialVersionUID (from Comparable).

代码库的其余部分也...也要生成警告,礼貌地说,我不想只是禁用节俭代码正在生成的类型的警告.我能用节俭做些什么来使其生成更好的代码吗?有没有办法在生成的代码中包含警告抑制修饰?

The rest of the codebase is... also generating warnings, to put it politely, and I don't want to just disable warnings of the type the thrift code is generating. Is there anything I can do with thrift to get it to generate better code? Is there a way to include warning suppression decoration in the generated code?

我们正在使用节俭的0.9.1.

We're using thrift 0.9.1.

标准Thrift Java实现的替代方法是 Facebook斯威夫特.

An alternative to the standard Thrift Java implementation is Facebook Swift.

您可以使用该软件附带的Swift Generator工具从您的IDL生成带注释的Java类,这更加干净,我很确定它们也可以选择修改模板.

You can use the the Swift Generator tool included with that software to generate annotated Java classes from your IDL which are much cleaner, and I'm pretty sure they have an option for modifying the templates as well.

如果您不想使用其随附的"Nifty"服务器,而是与标准Thrift传输集成,则可以使用 NiftyProcessorAdapters 实用工具类创建TProcessor:

If you don't want to use their included "Nifty" server, and integrate instead with the standard Thrift transports, you can use the NiftyProcessorAdapters utility class to create a TProcessor:

ThriftCodecManager codecManager = new ThriftCodecManager(
    new CompilerThriftCodecFactory(false)
);
List<ThriftEventHandler> eventList = Collections.emptyList();
ThriftServiceProcessor proc = new ThriftServiceProcessor(codecManager, eventList, svc);
this.multiplex.registerProcessor(name, NiftyProcessorAdapters.processorToTProcessor(proc));

Swift生成的代码基本上只是POJO,不应有那么多警告.也就是说,Swift运行时引入了很多依赖关系,可能并不适合所有应用程序.

The code that Swift generates is basically just POJOs, and should not be nearly as many warnings. That said the Swift runtime pulls in a bunch of dependencies and may not be suitable for all applications.