Format all Java files with google-java-format

Having a standard tool for formatting saves reviewers' valuable time.
google-java-format is Google's standard formatter and is somewhat
inspired by gofmt[1]. This commit formats everything using
google-java-format version 1.2.

The downside of this one-off formatting is breaking blame. This can be
somewhat hacked around with a tool like git-hyper-blame[2], but it's
definitely not optimal until/unless this kind of feature makes its way
to git core.

Not in this change:
* Tool support, e.g. Eclipse. The command must be run manually [3].
* Documentation of best practice, e.g. new 100-column default.

[1] https://talks.golang.org/2015/gofmt-en.slide#3
[2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
[3] git ls-files | grep java$ | xargs google-java-format -i

Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
Dave Borowitz
2016-11-13 09:56:32 -08:00
committed by David Pursehouse
parent 6723b6d0fa
commit 292fa154c1
2443 changed files with 54816 additions and 57825 deletions

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.common;
import static com.google.common.truth.Truth.assertThat;
import com.google.auto.value.AutoValue;
import org.junit.Test;
public class AutoValueTest {

View File

@@ -30,5 +30,4 @@ public class EncodePathSeparatorTest {
gitwebType.setPathSeparator('!');
assertEquals("a!b", gitwebType.replacePathSeparator("a/b"));
}
}

View File

@@ -23,43 +23,30 @@ public class FilenameComparatorTest {
@Test
public void basicPaths() {
assertThat(comparator.compare(
"abc/xyz/FileOne.java", "xyz/abc/FileTwo.java")).isLessThan(0);
assertThat(comparator.compare(
"abc/xyz/FileOne.java", "abc/xyz/FileOne.java")).isEqualTo(0);
assertThat(comparator.compare(
"zzz/yyy/FileOne.java", "abc/xyz/FileOne.java")).isGreaterThan(0);
assertThat(comparator.compare("abc/xyz/FileOne.java", "xyz/abc/FileTwo.java")).isLessThan(0);
assertThat(comparator.compare("abc/xyz/FileOne.java", "abc/xyz/FileOne.java")).isEqualTo(0);
assertThat(comparator.compare("zzz/yyy/FileOne.java", "abc/xyz/FileOne.java")).isGreaterThan(0);
}
@Test
public void specialPaths() {
assertThat(comparator.compare(
"ABC/xyz/FileOne.java", "/COMMIT_MSG")).isGreaterThan(0);
assertThat(comparator.compare(
"/COMMIT_MSG", "ABC/xyz/FileOne.java")).isLessThan(0);
assertThat(comparator.compare("ABC/xyz/FileOne.java", "/COMMIT_MSG")).isGreaterThan(0);
assertThat(comparator.compare("/COMMIT_MSG", "ABC/xyz/FileOne.java")).isLessThan(0);
assertThat(comparator.compare(
"ABC/xyz/FileOne.java", "/MERGE_LIST")).isGreaterThan(0);
assertThat(comparator.compare(
"/MERGE_LIST", "ABC/xyz/FileOne.java")).isLessThan(0);
assertThat(comparator.compare("ABC/xyz/FileOne.java", "/MERGE_LIST")).isGreaterThan(0);
assertThat(comparator.compare("/MERGE_LIST", "ABC/xyz/FileOne.java")).isLessThan(0);
assertThat(comparator.compare(
"/COMMIT_MSG", "/MERGE_LIST")).isLessThan(0);
assertThat(comparator.compare(
"/MERGE_LIST", "/COMMIT_MSG")).isGreaterThan(0);
assertThat(comparator.compare("/COMMIT_MSG", "/MERGE_LIST")).isLessThan(0);
assertThat(comparator.compare("/MERGE_LIST", "/COMMIT_MSG")).isGreaterThan(0);
assertThat(comparator.compare(
"/COMMIT_MSG", "/COMMIT_MSG")).isEqualTo(0);
assertThat(comparator.compare(
"/MERGE_LIST", "/MERGE_LIST")).isEqualTo(0);
assertThat(comparator.compare("/COMMIT_MSG", "/COMMIT_MSG")).isEqualTo(0);
assertThat(comparator.compare("/MERGE_LIST", "/MERGE_LIST")).isEqualTo(0);
}
@Test
public void cppExtensions() {
assertThat(comparator.compare("abc/file.h", "abc/file.cc")).isLessThan(0);
assertThat(comparator.compare("abc/file.c", "abc/file.hpp"))
.isGreaterThan(0);
assertThat(comparator.compare("abc..xyz.file.h", "abc.xyz.file.cc"))
.isLessThan(0);
assertThat(comparator.compare("abc/file.c", "abc/file.hpp")).isGreaterThan(0);
assertThat(comparator.compare("abc..xyz.file.h", "abc.xyz.file.cc")).isLessThan(0);
}
}
}

View File

@@ -19,11 +19,9 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
public class ParameterizedStringTest {
@Test
@@ -196,13 +194,13 @@ public class ParameterizedStringTest {
assertEquals("FIRSTNAME LASTNAME", p.bind(a)[0]);
assertEquals("firstname.lastname", p.bind(a)[1]);
assertEquals("hi, FIRSTNAME LASTNAME,your eamil address is 'firstname.lastname'.right?", p.replace(a));
assertEquals(
"hi, FIRSTNAME LASTNAME,your eamil address is 'firstname.lastname'.right?", p.replace(a));
}
@Test
public void replaceToUpperCaseToLowerCase() {
final ParameterizedString p =
new ParameterizedString("${a.toUpperCase.toLowerCase}");
final ParameterizedString p = new ParameterizedString("${a.toUpperCase.toLowerCase}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -223,8 +221,7 @@ public class ParameterizedStringTest {
@Test
public void replaceToUpperCaseLocalName() {
final ParameterizedString p =
new ParameterizedString("${a.toUpperCase.localPart}");
final ParameterizedString p = new ParameterizedString("${a.toUpperCase.localPart}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -245,8 +242,7 @@ public class ParameterizedStringTest {
@Test
public void replaceToUpperCaseAnUndefinedMethod() {
final ParameterizedString p =
new ParameterizedString("${a.toUpperCase.anUndefinedMethod}");
final ParameterizedString p = new ParameterizedString("${a.toUpperCase.anUndefinedMethod}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -267,8 +263,7 @@ public class ParameterizedStringTest {
@Test
public void replaceLocalNameToUpperCase() {
final ParameterizedString p =
new ParameterizedString("${a.localPart.toUpperCase}");
final ParameterizedString p = new ParameterizedString("${a.localPart.toUpperCase}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -289,8 +284,7 @@ public class ParameterizedStringTest {
@Test
public void replaceLocalNameToLowerCase() {
final ParameterizedString p =
new ParameterizedString("${a.localPart.toLowerCase}");
final ParameterizedString p = new ParameterizedString("${a.localPart.toLowerCase}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -311,8 +305,7 @@ public class ParameterizedStringTest {
@Test
public void replaceLocalNameAnUndefinedMethod() {
final ParameterizedString p =
new ParameterizedString("${a.localPart.anUndefinedMethod}");
final ParameterizedString p = new ParameterizedString("${a.localPart.anUndefinedMethod}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -333,8 +326,7 @@ public class ParameterizedStringTest {
@Test
public void replaceToLowerCaseToUpperCase() {
final ParameterizedString p =
new ParameterizedString("${a.toLowerCase.toUpperCase}");
final ParameterizedString p = new ParameterizedString("${a.toLowerCase.toUpperCase}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -355,8 +347,7 @@ public class ParameterizedStringTest {
@Test
public void replaceToLowerCaseLocalName() {
final ParameterizedString p =
new ParameterizedString("${a.toLowerCase.localPart}");
final ParameterizedString p = new ParameterizedString("${a.toLowerCase.localPart}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -377,8 +368,7 @@ public class ParameterizedStringTest {
@Test
public void replaceToLowerCaseAnUndefinedMethod() {
final ParameterizedString p =
new ParameterizedString("${a.toLowerCase.anUndefinedMethod}");
final ParameterizedString p = new ParameterizedString("${a.toLowerCase.anUndefinedMethod}");
assertEquals(1, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("a"));
@@ -399,14 +389,14 @@ public class ParameterizedStringTest {
@Test
public void replaceSubmitTooltipWithVariables() {
ParameterizedString p = new ParameterizedString(
"Submit patch set ${patchSet} into ${branch}");
ParameterizedString p = new ParameterizedString("Submit patch set ${patchSet} into ${branch}");
assertEquals(2, p.getParameterNames().size());
assertTrue(p.getParameterNames().contains("patchSet"));
Map<String, String> params = ImmutableMap.of(
"patchSet", "42",
"branch", "foo");
Map<String, String> params =
ImmutableMap.of(
"patchSet", "42",
"branch", "foo");
assertNotNull(p.bind(params));
assertEquals(2, p.bind(params).length);
assertEquals("42", p.bind(params)[0]);
@@ -416,11 +406,11 @@ public class ParameterizedStringTest {
@Test
public void replaceSubmitTooltipWithoutVariables() {
ParameterizedString p = new ParameterizedString(
"Submit patch set 40 into master");
Map<String, String> params = ImmutableMap.of(
"patchSet", "42",
"branch", "foo");
ParameterizedString p = new ParameterizedString("Submit patch set 40 into master");
Map<String, String> params =
ImmutableMap.of(
"patchSet", "42",
"branch", "foo");
assertEquals(0, p.bind(params).length);
assertEquals("Submit patch set 40 into master", p.replace(params));
}