Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,33 @@ Drop it into the Eclipse
[drop-ins folder](http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fp2_dropins_format.html)
to activate the plugin.

The plugin adds a `google-java-format` formatter implementation that can be
configured in `Window > Preferences > Java > Code Style > Formatter > Formatter
Implementation`.
The plugin adds two formatter implementations:

* `google-java-format`: using 2 spaces indent
* `aosp-java-format`: using 4 spaces indent

These that can be selected in "Window" > "Preferences" > "Java" > "Code Style" >
"Formatter" > "Formatter Implementation".

#### Eclipse JRE Config

The plugin uses some internal classes that aren't available without extra
configuration. To use the plugin, you will need to edit the
[`eclipse.ini`](https://wiki.eclipse.org/Eclipse.ini) file.

Open the `eclipse.ini` file in any editor and paste in these lines towards the
end (but anywhere after `-vmargs` will do):

```
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
```

Once you've done that, restart the IDE.

### Third-party integrations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ public void closeBraces(int initialIndent) {
}

private static final int INDENTATION_SIZE = 2;
private final Formatter formatter = new Formatter();
private final Formatter formatter;
private static final CharMatcher NOT_WHITESPACE = CharMatcher.whitespace().negate();

public SnippetFormatter() {
this(JavaFormatterOptions.defaultOptions());
}

public SnippetFormatter(JavaFormatterOptions formatterOptions) {
formatter = new Formatter(formatterOptions);
}

public String createIndentationString(int indentationLevel) {
Preconditions.checkArgument(
indentationLevel >= 0,
Expand Down
Loading