26

I have org.eclipse.jdt.core.prefs file, which contains eclipse code style, but I can import to intellij idea only xml files, it there any way import prefs file to intellij idea?

roman-v1
  • 728
  • 1
  • 9
  • 21
  • A remark for those who want to do the *opposite*, from Intellij to Eclipse: https://stackoverflow.com/questions/36432438/importing-code-style-formatting-settings-into-eclipse-from-intellij-idea – ch271828n Mar 05 '20 at 03:39

3 Answers3

29

Go to Eclipse's Preferences → Java → Code Style → Formatter and export the settings to an XML file via the Export All button (or Edit and then Export in dialog that opens up). Then open IntelliJ IDEA Settings → Code Style → Java, click Manage, and import that XML file by simply clicking Import.

As of IntelliJ IDEA 13, there is no possibility to import .settings/.prefs files directly.


Edit: IntelliJ can import the following Eclipse properties:

  • General
    • Right margin, Formatter on/off tags
    • Indentation
    • Indent size
    • Usage of ‘Tab’ character
    • Usage of Tab only for leading indentation (Smart Tabs)
    • Indent ‘case’ branches from ‘switch’
    • Indent class members
    • Keep comment at first column
  • Spaces (Java)
    • Before/after comma (as set for Eclipse method declaration parameters)
    • After comma in type arguments
    • Within array initializer braces
    • Within brackets (in array reference)
    • Within parentheses of: annotation, ‘for’, ‘if’, ‘catch’ ’while’, ’switch’, method, empty method, parenthesized expression, method call, type cast, ‘synchronized’
    • Before parentheses of: ‘try’, ‘for’, ’while’, ‘switch’, method, ’if’, ‘catch’, method, method call, ‘synchronized’.
    • After type cast
    • Around unary, assignment operators (if it’s set for ‘before’ and ‘after’ in Eclipse).
    • Before opening brace of: array initializer, ‘switch’
    • Before ‘?’ in conditional expression
    • Space before/after ‘:’ in conditional expression
    • Space around binary operators (a single Eclipse setting is mapped to multiple IntelliJ IDEA’s settings)
  • Blank lines
    • Around fields and methods
    • Before/after package
    • Before/after imports
    • Before method body
    • Keep blank lines in code (number of empty lines to preserve)
  • Wrapping
    • New line before: closing brace in array initializer, ‘else’ in ‘if’ statement, ‘finally’ and ‘catch’ in ‘try’ statement, binary operator (if wrapped)
    • New line after: opening brace in array initializer Special ‘else if’ treatment (compact ‘else if’)
    • Keep simple blocks in one line
    • Keep control statements in one line
    • Alignment of: array initializer expressions, arguments in method declarations and calls, field declarations, extends list, assignments, binary expressions, ‘throws’ clause, resources in ‘try’.
    • Brace style for: code blocks, methods and classes
  • JavaDoc
    • Enable JavaDoc formatting
    • Blank lines in JavaDoc
user1438038
  • 5,821
  • 6
  • 60
  • 94
  • I haven't got eclipse project with these settings and if I try open this project by eclipse they are not configured for it. I can't import .prefs files to eclipse too. – roman-v1 Nov 20 '14 at 09:24
  • To import settings in Eclipse, select File → Import. In the Import wizard select General → Preferences and click Next. Click Browse... and locate the file you are going to import. Click Import all to accept all of the preferences defined in the file. If you want to import only few preferences, choose them from the list. Finally, click Finish. – user1438038 Nov 20 '14 at 09:32
  • I imported settings to eclipse and they works there, but when I export them to xml file, it's nearly empty and doesn't contains rules: " " – roman-v1 Nov 20 '14 at 12:15
  • 2
    The JetBrains web site states: *Keep in mind that code style settings in IntelliJ IDEA and Eclipse are fundamentally different and can’t be mapped one to another with complete accuracy.* I updated my answer and added information about which Eclipse properties are supported by IntelliJ IDEA 13. – user1438038 Nov 20 '14 at 12:21
  • 1
    I'm not clicked export all, but click edit close and click export there, and it exported correct file, please add it to your answer. – roman-v1 Nov 20 '14 at 13:09
  • Done, added further instructions to open edit dialog. – user1438038 Nov 20 '14 at 13:19
13

In the latest (2020) IntelliJ IDEA, if you have the "Eclipse interoperability" plugin installed, it's as simple as:

Settings > Editor > Code Style > Java > ⚙️ > Import Scheme > Eclipse XML Profile

enter image description here

Dónal
  • 185,044
  • 174
  • 569
  • 824
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • What if I have two different formatters for Java and JS how do I set that? – Rishabh Deep Singh Apr 17 '20 at 10:38
  • 1
    @RishabhDeepSingh I think the JS stuff is on the paid version of IntelliJ; I use VSCode for the front end modules of my IntelliJ multi module projects, by the way – Andrea Ligios Apr 17 '20 at 12:54
  • I'm using IntelliJ 2020.1 and I don't see that as an option. Maybe you have a plugin installed that adds support for Eclipse? https://share.getcloudapp.com/d5uv1k4d – Dónal Apr 30 '20 at 13:30
  • @Dónal It's out of the box in 2020.1 (as it was in 2019.3 in the picture), but I'm on Linux. I'm not sure if the Mac version is lacking this option. Pretty weird, though. In the installed plugins I can see a bundled plugin (so out of the box, not something I've installed) called `Eclipse Interoperability` which _might_ be responsible for this kind of stuff. Does your Mac version of Intellij have it installed? If not, can you install it from the Marketplace? – Andrea Ligios Apr 30 '20 at 23:03
  • 1
    @AndreaLigios I installed the "Eclipse interoperability" plugin and that option now appears. Thanks for the suggestion – Dónal May 02 '20 at 13:45
  • Thanks for the feedback, @Dónal :) I'm glad that it helped – Andrea Ligios May 02 '20 at 19:53
12

Try the Eclipse Code Formatter plugin. It's easy to configure and works well.

Dónal
  • 185,044
  • 174
  • 569
  • 824
kn_pavan
  • 1,510
  • 3
  • 21
  • 42
  • 1
    This covers a lot of settings that the native intelliJ formatter does not when importing an eclipse format xml file. It was the only way I could get code consistent with our eclipse devs. – Robbie Aug 15 '19 at 17:22