Java IntelliJ 中可能发生的事情在 Eclipse 中不可能发生?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/239732/
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-08-11 11:54:08  来源:igfitidea点击:

Things possible in IntelliJ that aren't possible in Eclipse?

javaeclipseideintellij-idea

提问by Epaga

I have heard from people who have switched either way and who swear by the one or the other.

我听说有人改变了任何一种方式并且对一种或另一种发誓。

Being a huge Eclipse fan but having not had the time to try out IntelliJ, I am interested in hearing from IntelliJ users who are "ex-Eclipsians" some specific things that you can do with IntelliJ that you can not do with Eclipse.

作为 Eclipse 的忠实粉丝,但还没有时间尝试 IntelliJ,我很想听听“前 Eclipsians”IntelliJ 用户的一些具体事情,这些事情您可以使用 IntelliJ 完成而 Eclipse 无法完成。

Note: This is not a subjective question nor at all meant to turn into an IDE holy war. Please downvote any flamebait answers.

注意:这不是一个主观问题,也绝不意味着要变成 IDE 圣战。请对任何火焰诱饵答案投反对票

采纳答案by Pavel Feldman

CTRL-click works anywhere

CTRL 键单击适用于任何地方

CTRL-click that brings you to where clicked object is defined works everywhere - not only in Java classes and variables in Java code, but in Spring configuration (you can click on class name, or property, or bean name), in Hibernate (you can click on property name or class, or included resource), you can navigate within one click from Java class to where it is used as Spring or Hibernate bean; clicking on included JSP or JSTL tag also works, ctrl-click on JavaScript variable or function brings you to the place it is defined or shows a menu if there are more than one place, including other .js files and JS code in HTML or JSP files.

CTRL-click 将您带到定义被单击对象的位置 - 不仅在 Java 代码中的 Java 类和变量中,而且在 Spring 配置中(您可以单击类名、属性或 bean 名称),在 Hibernate 中(您可以单击属性名称或类,或包含的资源),您可以一键从 Java 类导航到用作 Spring 或 Hibernate bean 的位置;单击包含的 JSP 或 JSTL 标记也有效,按住 ctrl 单击 JavaScript 变量或函数会将您带到定义它的位置,或者如果有多个位置,则显示一个菜单,包括其他 .js 文件和 HTML 或 JSP 中的 JS 代码文件。

Autocomplete for many languagues

许多语言的自动完成

Hibernate

休眠

Autocomplete in HSQL expressions, in Hibernate configuration (including class, property and DB column names), in Spring configuration

在 HSQL 表达式中、在 Hibernate 配置中(包括类、属性和 DB 列名)、在 Spring 配置中自动完成

<property name="propName" ref="<hit CTRL-SPACE>"

and it will show you list of those beans which you can inject into that property.

它会向您显示可以注入该属性的 bean 列表。

Java

爪哇

Very smart autocomplete in Java code:

Java 代码中非常智能的自动完成功能:

interface Person {
    String getName();
    String getAddress();
    int getAge();
}
//---
Person p;
String name = p.<CTRL-SHIFT-SPACE>

and it shows you ONLY getName(), getAddress()and toString()(only they are compatible by type) and getName()is first in the list because it has more relevant name. Latest version 8 which is still in EAP has even more smart autocomplete.

它仅向您显示getName()getAddress()toString()(只有它们按类型兼容)并且getName()在列表中排在第一位,因为它具有更相关的名称。仍在 EAP 中的最新版本 8 具有更智能的自动完成功能。

interface Country{
}
interface Address {
    String getStreetAddress();
    String getZipCode();
    Country getCountry();
}
interface Person {
    String getName();
    Address getAddress();
    int getAge();
}
//--- 
Person p;
Country c = p.<CTRL-SHIFT-SPACE>

and it will silently autocomplete it to

它会默默地自动完成它

Country c = p.getAddress().getCountry();

Javascript

Javascript

Smart autocomplete in JavaScript.

JavaScript 中的智能自动完成。

function Person(name,address) {
    this.getName = function() { return name };
    this.getAddress = function() { return address };
}

Person.prototype.hello = function() {
    return "I'm " + this.getName() + " from " + this.get<CTRL-SPACE>;
}

and it shows ONLY getName()and getAddress(), no matter how may get* methods you have in other JS objects in your project, and ctrl-click on this.getName()brings you to where this one is defined, even if there are some other getName()functions in your project.

并且它只显示getName()getAddress(),无论您在项目中的其他 JS 对象中如何使用 get* 方法,并且按住 ctrl 单击this.getName()会将您带到定义此的位置,即使您的项目中还有其他一些getName()函数。

HTML

HTML

Did I mention autocomplete and ctrl-clicking in paths to files, like <script src="", <img src="", etc?

我有没有提到文件路径中的自动完成和 ctrl 单击,例如 <script src=""、<img src="" 等?

Autocomplete in HTML tag attributes. Autocomplete in style attribute of HTML tags, both attribute names and values. Autocomplete in class attributes as well.
Type <div class="<CTRL-SPACE> and it will show you list of CSS classes defined in your project. Pick one, ctrl-click on it and you will be redirected to where it is defined.

在 HTML 标签属性中自动完成。自动完成 HTML 标签的样式属性,包括属性名称和值。类属性中的自动完成也是如此。
输入 <div class="<CTRL-SPACE> ,它会显示你的项目中定义的 CSS 类列表。选择一个,按住 ctrl 键单击它,你将被重定向到它定义的位置。

Easy own language higlighting

轻松突出自己的语言

Latest version has language injection, so you can declare that you custom JSTL tag usually contains JavaScript and it will highlight JavaScript inside it.

最新版本有语言注入,所以你可以声明你的自定义 JSTL 标签通常包含 JavaScript,它会突出显示其中的 JavaScript。

<ui:obfuscateJavaScript>function something(){...}</ui:obfuscateJavaScript>

Indexed search across all project.

对所有项目进行索引搜索。

You can use Find Usages of any Java class or method and it will find where it is used including not only Java classes but Hibernate, Spring, JSP and other places. Rename Method refactoring renames method not only in Java classes but anywhere including comments (it can not be sure if string in comments is really method name so it will ask). And it will find only your method even if there are methods of another class with same name. Good source control integration (does SVN support changelists? IDEA support them for every source control), ability to create a patch with your changes so you can send your changes to other team member without committing them.

您可以使用任何 Java 类或方法的 Find Usages,它会找到使用它的地方,不仅包括 Java 类,还包括 Hibernate、Spring、JSP 和其他地方。重命名方法重构不仅在 Java 类中重命名方法,而且在包括注释在内的任何地方重命名方法(无法确定注释中的字符串是否真的是方法名称,因此它会询问)。即使存在同名的另一个类的方法,它也只会找到您的方法。良好的源代码控制集成(SVN 是否支持更改列表?IDEA 支持每个源代码控制),能够使用您的更改创建补丁,以便您可以将更改发送给其他团队成员而无需提交它们。

Improved debugger

改进的调试器

When I look at HashMapin debugger's watch window, I see logical view - keys and values, last time I did it in Eclipse it was showing entries with hash and next fields - I'm not really debugging HashMap, I just want to look at it contents.

当我在调试器的监视窗口中查看HashMap时,我看到了逻辑视图 - 键和值,上次我在 Eclipse 中执行它时,它显示了带有哈希和下一个字段的条目 - 我并不是真的在调试HashMap,我只是想看看它的内容。

Spring & Hibernate configuration validation

Spring & Hibernate 配置验证

It validates Spring and Hibernate configuration right when you edit it, so I do not need to restart server to know that I misspelled class name, or added constructor parameter so my Spring cfg is invalid.

当您编辑它时,它会正确验证 Spring 和 Hibernate 配置,所以我不需要重新启动服务器来知道我拼错了类名,或者添加了构造函数参数所以我的 Spring cfg 无效。

Last time I tried, I could not run Eclipse on Windows XP x64.

上次尝试时,我无法在 Windows XP x64 上运行 Eclipse。

and it will suggest you person.nameor person.address. Ctrl-click on person.nameand it will navigate you to getName()method of Personclass.

它会建议你PERSON.NAMEperson.address。按住 Ctrl 键单击person.name,它将导航到Person类的getName()方法。

Type Pattern.compile("");put \\ there, hit CTRL-SPACE and see helpful hint about what you can put into your regular expression. You can also use language injection here - define your own method that takes string parameter, declare in IntelliLang options dialog that your parameter is regular expression - and it will give you autocomplete there as well. Needless to say it highlights incorrect regular expressions.

类型Pattern.compile("");把\\那里,按CTRL-SPACE,看什么,你可以把你的正则表达式有用的提示。您还可以在此处使用语言注入 - 定义您自己的接受字符串参数的方法,在 IntelliLang 选项对话框中声明您的参数是正则表达式 - 它也会在那里为您提供自动完成功能。不用说,它突出显示了不正确的正则表达式。

Other features

其他特性

There are few features which I'm not sure are present in Eclipse or not. But at least each member of our team who uses Eclipse, also uses some merging tool to merge local changes with changes from source control, usually WinMerge. I never need it - merging in IDEA is enough for me. By 3 clicks I can see list of file versions in source control, by 3 more clicks I can compare previous versions, or previous and current one and possibly merge.

我不确定 Eclipse 中是否存在一些功能。但至少我们团队中每个使用 Eclipse 的成员,也使用一些合并工具将本地更改与源代码管理的更改合并,通常是 WinMerge。我从不需要它 - 合并 IDEA 对我来说就足够了。点击 3 次我可以看到源代码管理中的文件版本列表,再点击 3 次我可以比较以前的版本,或者以前的和当前的版本,并可能合并。

It allows to to specify that I need all .jars inside WEB-INF\libfolder, without picking each file separately, so when someone commits new .jar into that folder it picks it up automatically.

它允许指定我需要WEB-INF\lib文件夹内的所有.jar,而无需单独选择每个文件,因此当有人将新的 .jar 提交到该文件夹​​时,它会自动选择它。

Mentioned above is probably 10% of what it does. I do not use Maven, Flex, Swing, EJB and a lot of other stuff, so I can not tell how it helps with them. But it does.

上面提到的可能是它所做的10%。我不使用 Maven、Flex、Swing、EJB 和许多其他东西,所以我不知道它对它们有什么帮助。但确实如此。

回答by krosenvold

IntelliJ has intellisense and refactoring support from code into jspx documents.

IntelliJ 具有从代码到 jspx 文档的智能感知和重构支持。

回答by Mo.

The IntelliJ debugger has a very handy feature called "Evaluate Expression", that is by far better than eclipses pendant. It has full code-completion and i concider it to be generally "more useful".

IntelliJ 调试器有一个非常方便的功能,称为“评估表达式”,它比 eclipses pendant 好得多。它具有完整的代码完成功能,我认为它通常“更有用”。

回答by Mo.

IntelliJ has some pretty advanced code inspections (comparable but different to FindBugs).

IntelliJ 有一些非常先进的代码检查(与 FindBugs 类似但不同)。

Although I seriously miss a FindBugs plugin when using IntelliJ (The Eclipse/FindBugs integration is pretty cool).

尽管我在使用 IntelliJ 时非常想念 FindBugs 插件(Eclipse/FindBugs 集成非常酷)。

Hereis an official list of CodeInspections supported by IntelliJ

是 IntelliJ 支持的 CodeInspections 的官方列表

EDIT: Finally, there is a findbugs-pluginfor IntelliJ. It is still a bit beta but the combination of Code Inspections and FindBugs is just awesome!

编辑:最后,IntelliJ有一个findbugs-plugin。它仍然有点测试版,但代码检查和 FindBugs 的组合非常棒!

回答by Chris Kessel

Well, for me it's a thousand tiny things. Some of the macros, the GUI layout in general in Eclipse I find awful. I can't open multiple projects in different windows in Eclipse. I can open multiple projects, but then it's view based system swaps a bunch of things around on me when I switch files. IntelliJ's code inspections seem better. Its popup helpers to fix common issues is nice. Lots of simple usability things like the side bar where I can hover over a hot spot and it'll tell me every implementing subclass of a method or the method I'm implementing and from where.

嗯,对我来说,这是一千件小事。我觉得 Eclipse 中的一些宏和 GUI 布局很糟糕。我无法在 Eclipse 的不同窗口中打开多个项目。我可以打开多个项目,但是当我切换文件时,基于视图的系统会在我身上交换一堆东西。IntelliJ 的代码检查似乎更好。它用于修复常见问题的弹出式助手很好。许多简单的可用性内容,例如我可以将鼠标悬停在热点上的侧栏,它会告诉我方法的每个实现子类或我正在实现的方法以及从哪里实现。

Whenever I've had to use, or watch someone use, Eclipse it seems like they can do most of the things I can do in IntelliJ, but it takes them longer and it's clunkier.

每当我不得不使用或看到有人使用 Eclipse 时,它​​们似乎可以完成我在 IntelliJ 中可以完成的大部分事情,但是它们需要更长的时间并且更笨拙。

回答by OscarRyz

Probably is not a matter of whatcan/can't be done, but how.

可能不是什么能/不能做的问题,而是如何做。

For instance both have editor surrounded with dock panels for project, classpath, output, structure etc. But in Idea when I start to type all these collapse automatically let me focus on the code it self; In eclipse all these panels keep open leaving my editor area very reduced, about 1/5 of the total viewable area. So I have to grab the mouse and click to minimize in those panels. Doing this all day long is a very frustrating experience in eclipse.

例如,两者都有编辑器,周围有用于项目、类路径、输出、结构等的停靠面板。但是在 Idea 中,当我开始自动输入所有这些折叠时,让我专注于代码本身;在 Eclipse 中,所有这些面板都保持打开状态,使我的编辑器区域非常小,大约占总可视区域的 1/5。所以我必须抓住鼠标并单击以最小化这些面板。在日食中整天这样做是非常令人沮丧的经历。

The exact opposite thing happens with the view output window. In Idea running a program brings the output window/panel to see the output of the program even if it was perviously minimized. In eclipse I have to grab my mouse again and look for the output tab and click it to view my program output, because the output window/panel is just another one, like all the rest of the windows, but in Idea it is treated in a special way: "If the user want to run his program, is very likely he wants to see the output of that program!" It seems so natural when I write it, but eclipse fails in this basic user interface concept.

视图输出窗口发生了完全相反的事情。在 Idea 中,运行程序会带来输出窗口/面板,以查看程序的输出,即使它先前已最小化。在 eclipse 中,我必须再次抓住我的鼠标并查找输出选项卡并单击它以查看我的程序输出,因为输出窗口/面板只是另一个窗口/面板,就像所有其他窗口一样,但在 Idea 中它被处理一种特殊的方式:“如果用户想运行他的程序,很可能他想看到那个程序的输出!” 我写的时候看起来很自然,但是 eclipse 在这个基本的用户界面概念上失败了。

Probably there's a shortcut for this in eclipse ( autohide output window while editing and autoshow it when running the program ) , but as some other tens of features the shortcut must be hunted in forums, online help etc while in Idea is a little bit more "natural".

在 Eclipse 中可能有一个快捷方式(在编辑时自动隐藏输出窗口并在运行程序时自动显示它),但作为其他数十种功能,必须在论坛、在线帮助等中寻找快捷方式,而在 Idea 中则要多一些”自然”。

This can be repeated for almost all the features both have, autocomplete, word wrap, quick documentation view, everything. I think the user experience is far more pleasant in Idea than in eclipse. Then the motto comes true "Develop with pleasure"

对于几乎所有功能都可以重复此操作,自动完成,自动换行,快速文档视图等等。我认为 Idea 的用户体验远比 Eclipse 令人愉快。然后座右铭成真“快乐地发展”

Eclipse handles faster larger projects ( +300 jars and +4000 classes ) and I think IntelliJ Idea 8 is working on this.

Eclipse 处理更快的大型项目(+300 个 jar 和 +4000 个类),我认为 IntelliJ Idea 8 正在解决这个问题。

All this of course is subjective. How can we measure user experience?

当然,这一切都是主观的。我们如何衡量用户体验?

回答by Darron

Structural search and replace.

结构搜索和替换。

For example, search for something like:

例如,搜索以下内容:

  System.out.println($string$ + $expr$);

Where $string$ is a literal, and $expr$ is an expression of type my.package.and.Class, and then replace with:

其中 $string$ 是文字,$expr$ 是 my.package.and.Class 类型的表达式,然后替换为:

  $expr$.inspect($string$);

回答by oxbow_lakes

If you have the cursor on a method then CTRL+SHIFT+Iwill popup the method implementation. If the method is an interfacemethod, then you can use up- and down- arrows to cycle through the implementations:

如果您将光标放在方法上,CTRL+SHIFT+I则会弹出方法实现。如果方法是一个interface方法,那么您可以使用向上和向下箭头循环浏览实现:

Map<String, Integer> m = ...
m.contains|Key("Wibble");

Where | is (for example) where your cursor is.

哪里| 是(例如)光标所在的位置。

回答by yalestar

Two things that IntelliJ does that Eclipse doesn't that are very valuable to me:

IntelliJ 所做而 Eclipse 所做的两件事对我来说并不重要:

Method separators: those faint gray lines between methods make code muchmore readable

方法分离:方法之间的那些微弱灰线使代码得多更易读

Text anti-aliasing: makes code look so nice in the IDE

文本抗锯齿:使代码在 IDE 中看起来非常漂亮

回答by Swapnonil Mukherjee

Show Navigation Bar ALT-Home.

显示导航栏 ALT-Home。