Import google-java-format from Eclipse to VSCode

1.1k Views Asked by At

I have an archive plugin for Eclipse that contains an personalized google-java-format implementation, I want to import this to VSCode editor, is it possible to this?I found how to do this with xml files but not with archives (a jar containing *.class files).

Thank you for your help.

2

There are 2 best solutions below

4
Shi Chen On

Could you get the xml profile in your mentioned plugin? If yes, make sure you have installed Java extension first, VSCode can use a specified Eclipse xml profile as it's formatter profile.

You can check the setting java.format.settings.url. When it's specified, the given formatter profile will be used in VSCode Java formatting.

Another way to use it is to trigger command Java: Open Java formatter settings, and it will help you generate a default formatter profile, you can change the content to what you want.

0
Vittore Marcas On

To directly set "Google Java Style" as "Java's format" on VSCode, please:

1.Install "Extension Pack for Java".

e.g: "Extension Pack for Java v0.9.1" + "Language Support for Java(TM) by Red Hat v0.64.1" for "Java1.8".

Making sure COMPILING, RUNNING and DEBUGGING are successful before "Next Step"!

2.Set the default formatter of Java into "RedHat".

2.1Using hotKeyMap to open the Settings of VSCode, e.g: Ctrl/Cmd + ,

( or Click the logo of VSCode "Code" button and choose "Preference" menu and then click "Setting")

2.2Type "javahome" in the "Search settings" space, then click "Edit in settings.json",

2.3Adding the below code into your "settings.json",

"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml",
"java.format.settings.profile": "GoogleStyle",
"java.format.settings.imports.onDemand": false,
"java.format.settings.imports.regexp": "^[a-z.]*",
"[java]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "redhat.java",
    "editor.tabSize": 2
}

2.4Then restart the "VSCode", Using shift + alt/option + f to automatic "Java's format" into "Google Java Style".

END!