如何将 eclipse 代码样式导入到 Intellij 想法?

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

How import eclipse code style to intellij idea?

eclipseintellij-ideapreferences

提问by roman-v1

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?

我有 org.eclipse.jdt.core.prefs 文件,其中包含 eclipse 代码样式,但是我只能将 xml 文件导入到 intellij idea,有什么办法可以将 prefs 文件导入到 intellij idea?

回答by user1438038

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.

转到 Eclipse 的首选项 → Java → 代码样式 → 格式化程序,然后通过“全部导出”按钮(或在打开的对话框中编辑然后导出)将设置导出到 XML 文件。然后打开 IntelliJ IDEA 设置 → 代码样式 → Java,单击管理,然后只需单击导入即可导入该 XML 文件。

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

从 IntelliJ IDEA 13 开始,无法直接导入.settings/.prefs文件。



Edit:IntelliJ can import the following Eclipse properties:

编辑:IntelliJ 可以导入以下 Eclipse 属性:

  • 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
  • 一般的
    • 右边距,格式化程序开/关标签
    • 缩进
    • 缩进尺寸
    • 'Tab' 字符的使用
    • 仅将 Tab 用于前导缩进(智能标签)
    • 从“switch”缩进“case”分支
    • 缩进类成员
    • 在第一列保留评论
  • 空格 (Java)
    • 前/后逗号(为 Eclipse 方法声明参数设置)
    • 类型参数中的逗号之后
    • 在数组初始值设定项大括号内
    • 括号内(在数组引用中)
    • 括号内:注解、'for'、'if'、'catch'、'while'、'switch'、方法、空方法、带括号的表达式、方法调用、类型转换、'synchronized'
    • 括号前:'try'、'for'、'while'、'switch'、method、'if'、'catch'、method、方法调用、'synchronized'。
    • 类型转换后
    • 围绕一元赋值运算符(如果它在 Eclipse 中设置为“之前”和“之后”)。
    • 在打开大括号之前:数组初始值设定项,'switch'
    • 前 '?' 在条件表达式中
    • 条件表达式中“:”之前/之后的空格
    • 二元运算符周围的空间(单个 Eclipse 设置映射到多个 IntelliJ IDEA 设置)
  • 空行
    • 围绕字段和方法
    • 包装前/后
    • 导入前/导入后
    • 方法体之前
    • 在代码中保留空行(要保留的空行数)
  • 包装
    • 之前的新行:数组初始值设定项中的右大括号、“if”语句中的“else”、“try”语句中的“finally”和“catch”、二元运算符(如果已包装)
    • 后面的新行:在数组初始值设定项中打开大括号特殊的“else if”处理(紧凑的“else if”)
    • 将简单的块放在一行
    • 将控制语句保持在一行
    • 对齐:数组初始值设定项表达式、方法声明和调用中的参数、字段声明、扩展列表、赋值、二进制表达式、“throws”子句、“try”中的资源。
    • 大括号样式:代码块、方法和类
  • Java文档
    • 启用 JavaDoc 格式
    • JavaDoc 中的空行

回答by kn_pavan

Try Eclipse Formatterplugin. It's easy to configure and works well.

试试Eclipse Formatter插件。它易于配置且运行良好。

回答by Andrea Ligios

In the latest (2020) IntelliJ IDEA, it's as simple as that:

在最新的(2020 年)IntelliJ IDEA 中,就这么简单:

Settings> Editor> Code Style> Java> ??> Import Scheme> Eclipse XML Profile

Settings> Editor> Code Style> Java> ??> Import Scheme>Eclipse XML Profile

enter image description here

在此处输入图片说明