Skip to content
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

Excavator: Upgrades Baseline to the latest version #83

Merged
merged 1 commit into from
Nov 25, 2019
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
1 change: 0 additions & 1 deletion .baseline/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@
<property name="format" value="^_?[a-z][a-zA-Z0-9]+$"/>
<message key="name.invalidPattern" value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc"/> <!-- Java Style Guide: General form -->
<module name="SummaryJavadocCheck"> <!-- Java Coding Guidelines: Javadoc -->
<property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.netflix.nebula:nebula-publishing-plugin:14.1.1'
classpath 'com.netflix.nebula:gradle-info-plugin:5.2.0'
classpath 'com.palantir.baseline:gradle-baseline-java:2.31.0'
classpath 'com.palantir.baseline:gradle-baseline-java:2.35.2'
classpath 'gradle.plugin.org.inferred:gradle-processors:3.1.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.2'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:1.12.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ public OpsOutput build() {
if (tokAfter.isComment()) {
boolean breakAfter = tokAfter.isJavadocComment()
|| (tokAfter.isSlashStarComment()
&& tokenOp.breakAndIndentTrailingComment().isPresent());
&& tokenOp.breakAndIndentTrailingComment()
.isPresent());
if (breakAfter) {
tokOps.put(tokAfterPos, Break.make(
FillMode.FORCED,
Expand Down Expand Up @@ -636,7 +637,10 @@ public OpsOutput build() {
afterForcedBreak = isForcedBreak(op);
}
}
return ImmutableOpsOutput.builder().ops(newOps.build()).inputMetadata(inputMetadataBuilder.build()).build();
return ImmutableOpsOutput.builder()
.ops(newOps.build())
.inputMetadata(inputMetadataBuilder.build())
.build();
}

private static boolean isNonNlsComment(Input.Tok tokAfter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public static Break make(FillMode fillMode, String flat, Indent plusIndent) {
* @return the new {@code Break}
*/
public static Break make(FillMode fillMode, String flat, Indent plusIndent, Optional<BreakTag> optTag) {
return builder().fillMode(fillMode).flat(flat).plusIndent(plusIndent).optTag(optTag).build();
return builder()
.fillMode(fillMode)
.flat(flat)
.plusIndent(plusIndent)
.optTag(optTag)
.build();
}

/**
Expand All @@ -69,7 +74,11 @@ public static Break make(FillMode fillMode, String flat, Indent plusIndent, Opti
* @return the new forced {@code Break}
*/
public static Break makeForced() {
return builder().fillMode(FillMode.FORCED).flat("").plusIndent(Indent.Const.ZERO).build();
return builder()
.fillMode(FillMode.FORCED)
.flat("")
.plusIndent(Indent.Const.ZERO)
.build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ State breakTaken(BreakTag breakTag, boolean broken) {
* not commit to the indent just yet though, so lastIndent stays the same.
*/
State withIndentIncrementedBy(Indent plusIndent) {
return builder().from(this).indent(indent() + plusIndent.eval(this)).mustBreak(false).build();
return builder()
.from(this)
.indent(indent() + plusIndent.eval(this))
.mustBreak(false)
.build();
}

/** Reset any accumulated indent to the same value as {@code lastIndent}. */
Expand Down Expand Up @@ -177,15 +181,24 @@ State withMustBreak(boolean mustBreak) {
}

State withNewBranch() {
return builder().from(this).branchingCoefficient(branchingCoefficient() + 1).build();
return builder()
.from(this)
.branchingCoefficient(branchingCoefficient() + 1)
.build();
}

State withLevelState(Level level, LevelState levelState) {
return builder().from(this).levelStates(levelStates().set(level, levelState)).build();
return builder()
.from(this)
.levelStates(levelStates().set(level, levelState))
.build();
}

State withTokState(Comment comment, TokState tokState) {
return builder().from(this).tokStates(tokStates().set(comment, tokState)).build();
return builder()
.from(this)
.tokStates(tokStates().set(comment, tokState))
.build();
}

public static class Builder extends ImmutableState.Builder {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@ Range<Integer> characterRangeToTokenRange(int offset, int length) throws Formatt
// 0 stands for "format the line under the cursor"
length = 1;
}
ImmutableCollection<Token> enclosed =
getPositionTokenMap().subRangeMap(Range.closedOpen(offset, offset + length)).asMapOfRanges().values();
ImmutableCollection<Token> enclosed = getPositionTokenMap()
.subRangeMap(Range.closedOpen(offset, offset + length))
.asMapOfRanges()
.values();
if (enclosed.isEmpty()) {
return EMPTY_RANGE;
}
Expand Down Expand Up @@ -611,7 +613,10 @@ public ImmutableRangeMap<Integer, Token> getPositionTokenMap() {

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("tokens", tokens).add("super", super.toString()).toString();
return MoreObjects.toStringHelper(this)
.add("tokens", tokens)
.add("super", super.toString())
.toString();
}

private JCCompilationUnit unit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,9 @@ public Void visitModule(ModuleTree node, Void unused) {
for (DirectiveTree directiveTree : node.getDirectives()) {
markForPartialFormat();
builder.blankLineWanted(
previousDirective.map(k -> !k.equals(directiveTree.getKind())).orElse(false)
previousDirective
.map(k -> !k.equals(directiveTree.getKind()))
.orElse(false)
? BlankLineWanted.YES
: BlankLineWanted.NO);
builder.forcedBreak();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public int format(String... args) throws UsageException {
}

// TODO(someone): update this to always use Style.PALANTIR
JavaFormatterOptions options =
JavaFormatterOptions.builder().style(parameters.aosp() ? Style.AOSP : Style.GOOGLE).build();
JavaFormatterOptions options = JavaFormatterOptions.builder()
.style(parameters.aosp() ? Style.AOSP : Style.GOOGLE)
.build();

if (parameters.stdin()) {
return formatStdin(parameters, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ private static RangeMap<Integer, String> buildReplacements(
endPosition = Math.max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition);
String sep = Newlines.guessLineSeparator(contents);
if (endPosition + sep.length() < contents.length()
&& contents.subSequence(endPosition, endPosition + sep.length()).toString().equals(sep)) {
&& contents.subSequence(endPosition, endPosition + sep.length())
.toString()
.equals(sep)) {
endPosition += sep.length();
}
replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), "");
Expand All @@ -258,7 +260,9 @@ private static RangeMap<Integer, String> buildReplacements(
private static String getSimpleName(JCImport importTree) {
return importTree.getQualifiedIdentifier() instanceof JCIdent
? ((JCIdent) importTree.getQualifiedIdentifier()).getName().toString()
: ((JCFieldAccess) importTree.getQualifiedIdentifier()).getIdentifier().toString();
: ((JCFieldAccess) importTree.getQualifiedIdentifier())
.getIdentifier()
.toString();
}

private static boolean isUnused(
Expand All @@ -275,7 +279,9 @@ private static boolean isUnused(
return true;
}
if (importTree.getQualifiedIdentifier() instanceof JCFieldAccess
&& ((JCFieldAccess) importTree.getQualifiedIdentifier()).getIdentifier().contentEquals("*")) {
&& ((JCFieldAccess) importTree.getQualifiedIdentifier())
.getIdentifier()
.contentEquals("*")) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static String getSourceForNode(Tree node, TreePath path) {
} catch (IOException e) {
throw new IOError(e);
}
return source.subSequence(getStartPosition(node), getEndPosition(node, path)).toString();
return source.subSequence(getStartPosition(node), getEndPosition(node, path))
.toString();
}

/** Returns the simple name of a (possibly qualified) method invocation expression. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,38 @@
public class NewlinesTest {
@Test
public void offsets() {
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar\n"))).containsExactly(0, 4, 8);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar"))).containsExactly(0, 4);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar\n")))
.containsExactly(0, 4, 8);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar")))
.containsExactly(0, 4);

Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar\r"))).containsExactly(0, 4, 8);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar"))).containsExactly(0, 4);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar\r")))
.containsExactly(0, 4, 8);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar")))
.containsExactly(0, 4);

Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar\r\n"))).containsExactly(0, 5, 10);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar"))).containsExactly(0, 5);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar\r\n")))
.containsExactly(0, 5, 10);
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar")))
.containsExactly(0, 5);
}

@Test
public void lines() {
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar\n"))).containsExactly("foo\n", "bar\n");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar"))).containsExactly("foo\n", "bar");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar\n")))
.containsExactly("foo\n", "bar\n");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar")))
.containsExactly("foo\n", "bar");

Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar\r"))).containsExactly("foo\r", "bar\r");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar"))).containsExactly("foo\r", "bar");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar\r")))
.containsExactly("foo\r", "bar\r");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar")))
.containsExactly("foo\r", "bar");

Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar\r\n")))
.containsExactly("foo\r\n", "bar\r\n");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar"))).containsExactly("foo\r\n", "bar");
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar")))
.containsExactly("foo\r\n", "bar");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ public void stdin() {

@Test
public void aosp() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-aosp")).aosp()).isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-aosp")).aosp())
.isTrue();
}

@Test
public void help() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-help")).help()).isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-help")).help())
.isTrue();
}

@Test
Expand Down Expand Up @@ -104,17 +106,20 @@ public void offset() {

@Test
public void inPlace() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-i", "A.java")).inPlace()).isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-i", "A.java")).inPlace())
.isTrue();
}

@Test
public void version() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-v")).version()).isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-v")).version())
.isTrue();
}

@Test
public void skipSortingImports() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-sorting-imports")).sortImports()).isFalse();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-sorting-imports")).sortImports())
.isFalse();
}

@Test
Expand All @@ -126,13 +131,15 @@ public void skipRemovingUnusedImports() {

@Test
public void dryRun() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--dry-run")).dryRun()).isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--dry-run")).dryRun())
.isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-n")).dryRun()).isTrue();
}

@Test
public void setExitIfChanged() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--set-exit-if-changed")).setExitIfChanged()).isTrue();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--set-exit-if-changed")).setExitIfChanged())
.isTrue();
}

// TODO(cushon): consider handling this in the parser and reporting a more detailed error
Expand Down Expand Up @@ -166,7 +173,8 @@ public void paramsFile() throws IOException {
public void assumeFilename() {
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--assume-filename", "Foo.java")).assumeFilename())
.hasValue("Foo.java");
assertThat(CommandLineOptionsParser.parse(Arrays.asList("Foo.java")).assumeFilename()).isEmpty();
assertThat(CommandLineOptionsParser.parse(Arrays.asList("Foo.java")).assumeFilename())
.isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public void preserveOriginalFile() throws Exception {
@Test
public void testMain() throws Exception {
Process process = new ProcessBuilder(ImmutableList.of(
Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(),
Paths.get(System.getProperty("java.home"))
.resolve("bin/java")
.toString(),
"-cp",
System.getProperty("java.class.path"),
Main.class.getName()))
Expand Down Expand Up @@ -400,7 +402,9 @@ public void exitIfChangedStdin() throws Exception {
Path path = Files.createFile(testFolder.resolve("Test.java"));
Files.write(path, "class Test {\n}\n".getBytes(UTF_8));
Process process = new ProcessBuilder(ImmutableList.of(
Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(),
Paths.get(System.getProperty("java.home"))
.resolve("bin/java")
.toString(),
"-cp",
System.getProperty("java.class.path"),
Main.class.getName(),
Expand All @@ -423,7 +427,9 @@ public void exitIfChangedFiles() throws Exception {
Path path = Files.createFile(testFolder.resolve("Test.java"));
Files.write(path, "class Test {\n}\n".getBytes(UTF_8));
Process process = new ProcessBuilder(ImmutableList.of(
Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(),
Paths.get(System.getProperty("java.home"))
.resolve("bin/java")
.toString(),
"-cp",
System.getProperty("java.class.path"),
Main.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ public void typePrefixLength() {

@Test
public void ambiguousClass() {
assertThat(getPrefix("com.google.security.acl.proto2api.ACL.Entry.newBuilder")).hasValue(7);
assertThat(getPrefix("com.google.security.acl.proto2api.ACL.Entry.newBuilder"))
.hasValue(7);
// A human would probably identify this as "class-shaped", but just looking
// at the case we have to assume it could be something like `field1.field2.CONST`.
assertThat(getPrefix("com.google.security.acl.proto2api.ACL.newBuilder")).isEmpty();
assertThat(getPrefix("com.google.security.acl.proto2api.ACL.newBuilder"))
.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ private static String findStringFormatTemplate(ExtensionContext extensionContext

Method method = methods.get(0);

return AnnotationUtils.findAnnotation(method, Parameters.class).get().name();
return AnnotationUtils.findAnnotation(method, Parameters.class)
.get()
.name();
},
String.class);
}
Expand Down