1- # google -java-format
1+ # palantir -java-format
22
3- ` google -java-format` is a program that reformats Java source code to comply with
4- [ Google Java Style] [ ] .
3+ ` palantir -java-format` is a program that reformats Java source code to comply with
4+ [ Palantir Java Style] [ ] .
55
6- [ Google Java Style ] : https://google.github.io/styleguide/javaguide.html
6+ It is a fork of [ google-java-format] , but intending to achieve the following goals:
7+
8+ * Enforce the Palantir Java Style, whose main difference compared to Google's style is that we use 120 character lines and 4 space indent.
9+
10+ * Produce more compact code - Keep long method chains and invocations, as well as assignments and lambdas, on a single line, if we can break only the last argument of a method call, or the last method call in a chain.
11+
12+ * don't break [ NON-NLS markers] [ ] - these are comments that are used when implementing NLS internationalisation, and need to stay on the same line with the strings they come after.
13+
14+ We thank everyone who's worked on google-java-format for their good work and for making it available for free online. It's thanks to their work that we could incorporate our coding style preferences into a formatter so easily.
15+
16+ [ google-java-format] : https://github.com/google/google-java-format
17+ [ Palantir Java Style ] : https://github.com/palantir/gradle-baseline/blob/develop/docs/java-style-guide/readme.md
18+ [ NON-NLS markers ] : https://stackoverflow.com/a/40266605
719
820## Using the formatter
921
1022### from the command-line
1123
12- [ Download the formatter] ( https://github.com/google/google -java-format/releases )
24+ [ Download the formatter] ( https://github.com/palantir/palantir -java-format/releases )
1325and run it with:
1426
1527```
16- java -jar /path/to/google -java-format-1.7 -all-deps.jar <options> [files...]
28+ java -jar /path/to/palantir -java-format-<version> -all-deps.jar <options> [files...]
1729```
1830
1931The formatter can act on whole files, on limited lines (` --lines ` ), on specific
2032offsets (` --offset ` ), passing through to standard-out (default) or altered
2133in-place (` --replace ` ).
2234
2335To reformat changed lines in a specific patch, use
24- [ ` google-java-format-diff.py ` ] ( https://github.com/google/google -java-format/blob/master/scripts/google-java-format-diff.py ) .
36+ [ ` google-java-format-diff.py ` ] ( https://github.com/palantir/palantir -java-format/blob/master/scripts/google-java-format-diff.py ) .
2537
2638*** Note:*** * There is no configurability as to the formatter's algorithm for
2739formatting. This is a deliberate design decision to unify our code formatting on
@@ -30,18 +42,18 @@ a single format.*
3042### IntelliJ, Android Studio, and other JetBrains IDEs
3143
3244A
33- [ google -java-format IntelliJ plugin] ( https://plugins.jetbrains.com/plugin/8527 )
45+ [ palantir -java-format IntelliJ plugin] ( https://plugins.jetbrains.com/plugin/8527 )
3446is available from the plugin repository. To install it, go to your IDE's
3547settings and select the ` Plugins ` category. Click the ` Marketplace ` tab, search
36- for the ` google -java-format` plugin, and click the ` Install ` button.
48+ for the ` palantir -java-format` plugin, and click the ` Install ` button.
3749
38- The plugin will be disabled by default. To enable it in the current project, go
39- to ` File→Settings...→google -java-format Settings ` (or `IntelliJ
40- IDEA→Preferences...→Other Settings→google -java-format Settings` on macOS) and
41- check the ` Enable google -java-format ` checkbox. (A notification will be
50+ The plugin will be enabled by default. To disable it in the current project, go
51+ to ` File→Settings...→palantir -java-format Settings ` (or `IntelliJ
52+ IDEA→Preferences...→Other Settings→palantir -java-format Settings` on macOS) and
53+ check the ` Enable palantir -java-format ` checkbox. (A notification will be
4254presented when you first open a project offering to do this for you.)
4355
44- To enable it by default in new projects, use `File→Other Settings→Default
56+ To disable it by default in new projects, use `File→Other Settings→Default
4557Settings...`.
4658
4759When enabled, it will replace the normal ` Reformat Code ` action, which can be
@@ -55,13 +67,12 @@ and import it into File→Settings→Editor→Code Style.
5567
5668### Eclipse
5769
58- A
59- [ google-java-format Eclipse plugin] ( https://github.com/google/google-java-format/releases/download/google-java-format-1.6/google-java-format-eclipse-plugin_1.6.0.jar )
60- can be downloaded from the releases page. Drop it into the Eclipse
70+ A palantir-java-format Eclipse plugin is not currently published but can be built individually.
71+ Once built, drop it into the Eclipse
6172[ drop-ins folder] ( http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fp2_dropins_format.html )
6273to activate the plugin.
6374
64- The plugin adds a ` google -java-format` formatter implementation that can be
75+ The plugin adds a ` palantir -java-format` formatter implementation that can be
6576configured in `Window > Preferences > Java > Code Style > Formatter > Formatter
6677Implementation`.
6778
@@ -90,48 +101,64 @@ configuration.
90101
91102``` xml
92103<dependency >
93- <groupId >com.google.googlejavaformat</groupId >
94- <artifactId >google-java-format</artifactId >
95- <version >1.7</version >
104+ <groupId >com.palantir.javaformat</groupId >
105+ <artifactId >palantir-java-format</artifactId >
96106</dependency >
97107```
98108
99109#### Gradle
100110
101111``` groovy
102112dependencies {
103- compile 'com.google.googlejavaformat:google -java-format:1.7 '
113+ compile 'com.palantir.javaformat:palantir -java-format:<version> '
104114}
105115```
106116
107117You can then use the formatter through the ` formatSource ` methods. E.g.
108118
109119``` java
110- String formattedSource = new Formatter (). formatSource(sourceString);
120+ String formattedSource = new Formatter (JavaFormatterOptions . builder(). style(Style . PALANTIR ). build())
121+ .formatSource(sourceString);
111122```
112123
113124or
114125
115126``` java
116127CharSource source = ...
117128CharSink output = ...
118- new Formatter (). formatSource(source, output);
129+ new Formatter (JavaFormatterOptions . builder(). style(Style . PALANTIR ). build())
130+ .formatSource(source, output);
119131```
120132
121133Your starting point should be the instance methods of
122- ` com.google.googlejavaformat .java.Formatter ` .
134+ ` com.palantir.javaformat .java.Formatter ` .
123135
124136## Building from source
125137
126138```
127- mvn install
139+ ./gradlew publishToMavenLocal
128140```
129141
130- ## Contributing
142+ ## License
131143
132- Please see [ the contributors guide] ( CONTRIBUTING.md ) for details.
144+ ``` text
145+ (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
133146
134- ## License
147+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
148+ use this file except in compliance with the License. You may obtain a copy of
149+ the License at
150+
151+ http://www.apache.org/licenses/LICENSE-2.0
152+
153+ Unless required by applicable law or agreed to in writing, software
154+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
155+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
156+ License for the specific language governing permissions and limitations under
157+ the License.
158+ ```
159+
160+ This is a fork of [ google-java-format] ( https://github.com/google/google-java-format ) .
161+ Original work copyrighted by Google under the same license:
135162
136163``` text
137164Copyright 2015 Google Inc.
@@ -147,4 +174,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
147174WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
148175License for the specific language governing permissions and limitations under
149176the License.
150- ```
177+ ```
0 commit comments