如何“正确”缩进流畅的界面模式与日食?
我刚刚为一些流畅的界面创建了一个生成器。现在我有很多代码看起来像这样:
new MyFluentInterface()
.setFirst( "first" )
.setSecond( "second" )
.setThird( "third" )
.invoke( obj );
我喜欢上面显示的缩进,但我找不到配置 Eclipse 来正确缩进的方法。
eclipse 总是这样缩进:
new MyFluentInterface()
.setFirst( "first" )
.setSecond( "second" )
.setThird( "third" )
.invoke( obj );
如何配置 eclipse 以便缩进这个流畅的界面模式,如我的第一个代码示例所示?
I just created a generator for some fluent interfaces. Now I have lots of code looking like this:
new MyFluentInterface()
.setFirst( "first" )
.setSecond( "second" )
.setThird( "third" )
.invoke( obj );
I like the indentation shown above, but I can't find a way to configure eclipse to indent this correctly.
eclipse always indents like this:
new MyFluentInterface()
.setFirst( "first" )
.setSecond( "second" )
.setThird( "third" )
.invoke( obj );
How can I configure eclipse so that it indents this fluent interface pattern as shown in my first code example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Eclipse 3.6,这似乎可以通过配置自定义 Java > 来实现。代码风格>格式化程序配置文件。编辑它并转到换行选项卡并选择函数调用>合格的调用。然后,在合格调用设置中,配置如下内容:
这将 (应该)产生预期的结果:
但这显然会影响所有代码,我个人不喜欢。所以我使用新的 Eclipse 3.6 中的关闭/开启标签(编辑配置文件时的最后一个选项卡):
并附上未按照我想要的方式格式化的部分并自己完成:
选择你的毒药:)
With Eclipse 3.6, this seems doable by configuring your custom Java > Code Style > Formatter profile. Edit it and go to the Line Wrapping tab and select Function Call > Qualified invocations. Then, in the Settings for qualified invocations, configure things like this:
This will (should) produce the expected result:
But this will obviously affect all the code, which I personally don't like. So I'm using the new Off/On Tags from Eclipse 3.6 (last tab when editing a profile):
And enclose the parts that don't get formatted as I want and do it myself:
Pick your poison :)