eclipse 有没有办法在Eclipse中快速大写变量名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5323930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:03:35  来源:igfitidea点击:

Is there a way to quickly capitalize the variable name in Eclipse

eclipse

提问by user496949

Any refactoring tool like this?

任何像这样的重构工具?

回答by martin jakubik

Windows

视窗

After you press Alt+Shift+Ras mentioned by kostja, you can select the text you want to change, then

按kostja 提到的Alt+ Shift+后R,您可以选择要更改的文本,然后

  • Ctrl+Shift+Yfor lowercase, or
  • Ctrl+Shift+Xfor uppercase.
  • Ctrl+ Shift+Y为小写,或
  • Ctrl+ Shift+X为大写。

Mac OS

苹果系统

  • Cmd+Shift+Ylowercase
  • Cmd+Shift+Xuppercase
  • Cmd+ Shift+Y小写
  • Cmd+ Shift+X大写

There is no intelligence in this. It just blindly changes the case on the selected characters.

这里面没有智能。它只是盲目地改变所选字符的大小写。

note: This tip comes from eclipse help. If you need to find it, click Help, Search, then type "uppercase". You'll find a page with lots of shortcuts.

注意:此提示来自 eclipse 帮助。如果需要查找,请单击“帮助”、“搜索”,然后键入“大写”。你会发现一个有很多快捷方式的页面。

回答by user2672474

What I find useful is column select using Alt+Shift+A and select a column of letters. Then use Ctrl+Shift+Y or Ctrl+Shift+X to lower case or uppercase letters.

我觉得有用的是使用 Alt+Shift+A 选择列并选择一列字母。然后使用 Ctrl+Shift+Y 或 Ctrl+Shift+X 转换为小写或大写字母。

This works for eclipse on windows.

这适用于 Windows 上的 Eclipse。

回答by Stephen C

There are a number of problems:

有很多问题:

  • fooBar -> FooBar and vice-versaare unlikely to occur unless someone has been ignoring the Java style guidelines. (I rarely encounter such code, and when I do my initial reaction is to write off the code as beyond salvage.)

  • fooBar -> FOO_BAR and vice-versaare plausible, but pretty unusual.

  • foobar -> fooBar is also plausible, but it is problematic. It would entail Eclipse figuring out where the intended word boundaries are in a sequence of characters, and that is hard to get right.

  • fooBar -> FooBar 和反之亦然不太可能发生,除非有人一直忽略 Java 风格指南。(我很少遇到这样的代码,当我这样做时,我的第一反应是把代码写下来,因为它是无法挽救的。)

  • fooBar -> FOO_BAR反之亦然是合理的,但非常不寻常。

  • foob​​ar -> fooBar 也是合理的,但它是有问题的。这将需要 Eclipse 找出预期的单词边界在字符序列中的位置,而这很难做到正确。

If you look at these, they are all either unlikely to be needed much, or too hard to do properly. Hence, it doesn't surprise me that they are not supported by the standard Eclipse codebase.

如果你看看这些,他们要么不太可能需要太多,要么太难做好。因此,标准 Eclipse 代码库不支持它们并不令我感到惊讶。

回答by kostja

Pressing Alt+Shift+Rgives you all the power to refactor your variable name to your liking. AFAIK, there is no tool or shortcut that does just the capitalizing.

Alt+Shift+R 可以让您根据自己的喜好重构变量名称。AFAIK,没有工具或快捷方式可以只进行大写。

回答by Andreas Dolk

No. You'll have to use the standard rename refactoring and retype the variable name in capital letters.

不可以。您必须使用标准的重命名重构并以大写字母重新键入变量名称。

Capitalizing variable names should be limited to those cases, where we change a class attribute to a "constant", and this doesn't happen that often...

大写变量名应该仅限于那些我们将类属性更改为“常量”的情况,而这种情况并不经常发生......