在Eclipse中对齐多行Java字符串 [英] Aligning multiline Java strings in Eclipse

查看:540
本文介绍了在Eclipse中对齐多行Java字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Eclipse格式化系统有点新了。给定一个字符串的赋值,如下所示:

  (安装)<  -  [:CURRENT]  - (计算机名称)字符串cypher =可选匹配(更新:更新{名称:{名称}}),
+(更新) - [:INSTALLED_IN] :COMPUTER {name:{computerName}})
+RETURN更新,安装,电脑;

我希望在使用 Ctrl + Shift + F 并生成以下代码,所有 + 符号很好地在 = $ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' $ b +(update) - [:INSTALLED_IN] - >(installation)< - [:CURRENT] - (computer:COMPUTER {name:{computerName}})
+RETURN更新,电脑;

我该如何做到这一点?

我使用了我导入到Eclipse中的这个formatter.xml文件: http://pastebin.com/iThW8Lub 也许这里需要一些调整?

解决方案

在Eclipse中使用格式化程序设置,并不能正确地 所要找的。我怀疑这是不可能的给定的格式化设置(然而,你可以找到或写一个插件,将做你想做的)。

那是说,我能够实现两个选项,是最接近你正在寻找的。

这是为开普勒的Eclipse:



转至首选项> Java>代码样式>格式化器。点击编辑您的个人资料。转到换行选项卡。选择表达式。对于换行策略选择不换行。现在展开表达式列表并选择二进制表达式



现在选择你喜欢的包装策略。这将影响包装前每行的元素数量。我会用>在需要的时候换行<​​/ code>,但是您可以选择将每个元素放在一个单独的行中。



缩进政策,选择列上的缩进



现在,您可以选择/取消选中在操作符之前换行,这将分别为您生成效果1和效果2:
$ b $ $ $ $ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ [:INSTALLED_IN] - >(installation)< - [:CURRENT] - (computer:COMPUTER {name:{computerName}})
+RETURN update,installation,computer;



效果2:[]在运算符之前换行



< (更新:UPDATE {name:{name}}),+
(update) - [:INSTALLED_IN] - >(安装)< - [:CURRENT] - (computer:COMPUTER {name:{computerName}})+
RETURN update,installation,computer;

在我看来,效果1虽然不太整洁,但更具可读性,但是这完全取决于你。



希望这有助于!你总是有手动的代码格式来回落=)


I'm a little new with the Eclipse formatter system. Given an assignment to String over a couple of lines like this:

String cypher = "OPTIONAL MATCH (update:UPDATE {name: {name}}),"
        + "(update)-[:INSTALLED_IN]->(installation)<-[:CURRENT]-(computer:COMPUTER {name: {computerName}})"
        + "RETURN update, installation, computer";

I wish to have Eclipse format it when hitting Ctrl+Shift+F and produce the following, with all + signs aligning nicely under =:

String cypher = "OPTIONAL MATCH (update:UPDATE {name: {name}}),"
              + "(update)-[:INSTALLED_IN]->(installation)<-[:CURRENT]-(computer:COMPUTER {name: {computerName}})"
              + "RETURN update, installation, computer";

How can I achieve that?

I'm using this formatter.xml file which I've imported into Eclipse: http://pastebin.com/iThW8Lub Maybe some tweak here is needed?

解决方案

I played around with the formatter settings in Eclipse, and was not able to achieve exactly what you are looking for. I suspect that it is not possible with the given formatter settings (you could, however, find or write a plug-in that will do what you want).

That being said, I was able to achieve two options that are the closest to what you are looking for.

This is for Eclipse Kepler:

Go to Preferences > Java > Code Style > Formatter. Click to Edit your profile. Go to the Line Wrapping tab. Select Expressions. For Line wrapping policy select Do not wrap. Now expand the Expressions list and select Binary Expressions.

Now choose the wrapping policy you prefer. This will affect the number of elements on each line before the wrapping. I go with Wrap when necessary, but you could choose to have every element on a separate line.

For indentation policy, choose Indent on column.

Now, you can choose to check/uncheck Wrap before operator, which will give you Effect 1 and Effect 2 respectively:

Effect 1: [x] Wrap before operator

String cypher = "OPTIONAL MATCH (update:UPDATE {name: {name}}),"
                + "(update)-[:INSTALLED_IN]->(installation)<-[:CURRENT]-(computer:COMPUTER {name: {computerName}})"
                + "RETURN update, installation, computer";

Effect 2: [ ] Wrap before operator

String cypher = "OPTIONAL MATCH (update:UPDATE {name: {name}})," +
                "(update)-[:INSTALLED_IN]->(installation)<-[:CURRENT]-(computer:COMPUTER {name: {computerName}})" +
                "RETURN update, installation, computer";

In my opinion, Effect 1, while less neat, is more readable, and that's the one I go with, but it's totally up to you.

Hope this helps! You always have manual code formatting to fall back on =)

这篇关于在Eclipse中对齐多行Java字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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