-
Notifications
You must be signed in to change notification settings - Fork 880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix google-java-format reformatting code formatted by Android Studio for Platform when running with AOSP style #1239
base: master
Are you sure you want to change the base?
Conversation
This will be needed for later commits on this branch. Passed the style with which to format into JavaInputAstVisitor when it is created to allow appropriate format selection when formatting with aosp format
…p style Android Studio for Platform has a few differences in how it formats binary expressions. This change matches them when running with --aosp. In ASfP top level binary expressions are double indented. Subexpressions are single indented. Plus operators are always single indented.
…tyle Android Studio for Platform doesn't indent lists of interfaces when breaking them up over multiple lines. This matches that behavior in google-java-format when running with --aosp.
…tyle Android Studio for Platform doesn't add extra indentation to dotted expressions when they are decendents of binary expressions.
…sp style Android Studio for Platform puts braces on different lines. Match that behavior in aosp style.
… style Android Studio for Platform does not insert an extra space between array dimensions and the initializer body. This matches that behavior.
Android Studio for Platform puts newlines in empty classes. Match that behavior in aosp style.
…ng in aosp style When a dot expression wraps to a new line, Android Studio for Platform doesn't wrap it. Add a stack counter for the number of dot expressions visited to be able to match this behavior in aosp style.
…tyle Android Studio for Platform does not collapse empty do-while blocks. Match that behavior in aosp style.
…p style Android Studio for Platform uses an extra level of indentation for array initializers. Match that behavior in aosp style.
Fix a typo lower in the branch that I already pushed :)
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Preserving the formatting of existing code is not a goal of this project, see: https://github.com/google/google-java-format/wiki/FAQ#why-didnt-it-leave-my-perfectly-valid-code-alone The alternatives I'd recommend are to either standardize on one formatter for a particular codebase, or to run google-java-format on changed lines to avoid re-formatting unmodified code that isn't formatted in its style. |
Google-java-format when using AOSP style will reformat code that was already formatted by Google's Android Studio for Platform IDE (and vice versa). Both styles are compliant with the guidelines specified in AOSP Java code style for contributors. This prevents formatters from clobbering each other by updating google-java-format to be compliant with Android Studio for Platform's format when running with
--aosp
. No changes are made to the standard format.Tested by formatting with Android Studio for Platform then google-java-format over multiple projects in AOSP and diffing to confirm no changes. All unit tests pass.