Giter VIP home page Giter VIP logo

eclipsecodeformatter's Introduction

Allows using Eclipse's code formatter directly from IntelliJ. Solves the problem of maintaining a common code style in team environments where both IDEA and Eclipse are used.

Currently supports formatting of

  • Java (also emulates Eclipse's imports optimizing)
  • JavaScript
  • GWT
  • C/C++

Instructions

  • Install the plugin
  • Tutorial: Installing, Updating and Uninstalling Repository Plugins
  • Plugin repository page
  • Configure it
  • Get Eclipse formatter settings file: - Either export formatter profiles to get *.xml file
    • Go to Eclipse | Windows | Preferences | Java | Code Style | Formatter
    • Eclipse do not export default profiles, so you have to make your own ("New" button)
    • Export the profile ("Export all..." button.)
    • The result should look like this - Or enable project specific formatter settings to get org.eclipse.jdt.core.prefs
    • With your project open in Eclipse's workspace, right-click the project and choose Properties.
    • Go to Java Code Style | Formatter and select Enable project specific settings.
    • Click OK to save the settings.
    • Go to the .settings directory inside your project's directory. There you will find the org.eclipse.jdt.core.prefs file which contains the Eclipse formatter settings.
    • The result should look like this - Or export a [Workspace Mechanic] (http://marketplace.eclipse.org/content/workspace-mechanic/) configuration to get *.epf file
    • The result should look like this
  • Open a project in IntelliJ
  • Set path to the config file (IntelliJ | Settings | Other Settings | Eclipse Code Formatter | field "Eclipse preference file")
  • When using exported profiles(xml file), select desired profile in the combobox "Java formatter profile"
  • Check "Optimizing Imports" configuration
    • Set import order
      • Either leave the default
      • Or set path to Eclipse configuration file: - Go to Eclipse | Windows | Preferences | Java | Code Style | Organize Imports - Either click on "Export...", (example) - Or enable project specific settings and use "org.eclipse.jdt.ui.prefs" file which should contain the line "org.eclipse.jdt.ui.importorder=..."
    • Value of "Class count to use import with ''" and "Name count to use static import with ''" (Settings | Editor | Code Style | Java | Imports) for Idea 14 or (Settings | Editor | Code Style | Imports) for older Idea - Eclipse uses value of 99 by default
    • For versions lower than 4.0 - make sure to keep disabled IntelliJ's Import Optimizing in the reformat dialog (Settings | Editor | Show "Reformat Code" dialog), the plugin will take care of imports anyway
    • For versions higher than 4.0 - imports will be reordered together with normal IntelliJ's import optimizing
    • Disable "Optimize imports on the fly"
  • Format code as usual, notice the green bubble notification about successful formatting
  • notifications can be disabled at (Settings | Notifications)
  • Use Ctrl+Alt+O as usual, it will use this plugin
  • Use Ctrl + ~ for quick switch between formatters or icon at the main toolbar
  • [Give it 5 stars] (http://plugins.jetbrains.com/plugin/?idea&id=6546)
  • [Donate some money] (https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=75YN7U7H7D7XU&lc=CZ&item_name=Eclipse%20code%20formatter%20%2d%20IntelliJ%20plugin%20%2d%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest)

Possible problems with Java formatting

  • nothing was formatted or formatting failed
    • make sure you are using proper language level (Main Menu | File | Project Structure)
  • trailing spaces inside javadocs are stripped.
    • set "Strip trailing spaces on save" to "None"
  • file is formatted differently
    • The file is actually formatted fine, it just looks different in the editor, as the tab size and indendation are set differently in IntelliJ (Settings | Editor | Code Style | Java) than in Eclipse. Using of either tab only or space only whitespace is recommended.
    • Or it is a bug.
  • Eclipse indendation is configured for 2 spaces, but a new line gets indented by 4 spaces when Enter is pressed.
    • change code style in IntelliJ. Not all things get formatted by this plugin when you type them.
  • If nothing helps

Troubleshooting

If it is mysteriously not working, go to Main Menu | Help | Edit Debug Settings and add:

krasa.formatter

Try to reformat something and send me the log...

eclipsecodeformatter's People

Contributors

danmidwood avatar hrchu avatar krasa avatar lukasbreitwieser avatar markiewb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.