google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

organize imports doesnt work for Eclipse Oxygen.3a Release (4.7.3a)

Open leByteBuster opened this issue 6 years ago • 6 comments

I'm trying to setup google-java-format plugin for eclipse and for intellij so my team can work with different IDEs. However, though it works well for Intellij it doesnt for the mentioned eclipse version. It formats the code but imports arent touched at all.

leByteBuster avatar Jun 18 '18 11:06 leByteBuster

Just tried the same with Eclipse Neon. Same Problem - imports arent organized. I'm using version 1.6. Is there something missing in the documentation maybe? It only says to

Drop it into the Eclipse drop-ins folder to activate the plugin.

leByteBuster avatar Jun 18 '18 12:06 leByteBuster

Okay. As described here: https://github.com/google/google-java-format you only have to activate the plugin. For intellij it says you have to load a xml config file also. So i wondered if this is needed for eclipse too. So i tried to load the config file from https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml As it seems it works. So i dont know if the google formatter should work without doing this because for me it didnt.

leByteBuster avatar Jun 18 '18 14:06 leByteBuster

Just a guess, but maybe it's because formatting happens in https://github.com/google/google-java-format/blob/d109789d7e078a3e81803683727096412f463ba8/core/src/main/java/com/google/googlejavaformat/java/ImportOrderer.java while the plugin may be using just the https://github.com/google/google-java-format/blob/4ae067aef19d0882c5a61f514ea40fa88e9b7067/core/src/main/java/com/google/googlejavaformat/java/SnippetFormatter.java

jakub-bochenski avatar Jul 04 '18 17:07 jakub-bochenski

After a quick look I'm quite convinced that the SnippetFormatter that Eclipse plugin is using just doesn't organize imports.

jakub-bochenski avatar Jul 04 '18 17:07 jakub-bochenski

To fix my problem with eclipse import organization I had to manually:

  • Remove all packages from Java->Appearance->Code Style->Organize Imports
  • Create a new "Active profile"
  • Set Between import groups = 1

youngm avatar Jan 23 '19 21:01 youngm

For me worked only by removing all packages from the "Organize Imports" section (after adding the google java format plugin -1.6 only, January 2020- and the google style guide xml for eclipse). Hope it works for you.

image

PD: The only missing part is the line or groups as mentioned in comment above, but order and priority seems ok

alanamircruz avatar Jan 16 '20 12:01 alanamircruz