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 #8

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions .baseline/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@
<module name="AvoidStarImport"/> <!-- Java Style Guide: No wildcard imports -->
<module name="AvoidStaticImport"> <!-- Java Style Guide: No static imports -->
<property name="excludes" value="
com.google.common.base.Preconditions.*,
com.palantir.logsafe.Preconditions.*,
java.util.Collections.*,
java.util.stream.Collectors.*,
com.palantir.logsafe.Preconditions.*,
com.google.common.base.Preconditions.*,
org.apache.commons.lang3.Validate.*"/>
org.apache.commons.lang3.Validate.*,
org.assertj.core.api.Assertions.*,
org.mockito.Mockito.*"/>
</module>
<module name="ClassTypeParameterName"> <!-- Java Style Guide: Type variable names -->
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.netflix.nebula:nebula-publishing-plugin:14.0.0'
classpath 'com.netflix.nebula:gradle-info-plugin:5.1.1'
classpath 'com.palantir.baseline:gradle-baseline-java:2.13.0'
classpath 'com.palantir.baseline:gradle-baseline-java:2.20.1'
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 @@ -16,7 +16,6 @@

package com.palantir.javaformat.intellij;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Comparator.comparing;

import com.github.benmanes.caffeine.cache.Caffeine;
Expand Down Expand Up @@ -103,7 +102,8 @@ private static Collection<Range<Integer>> toRanges(Collection<TextRange> textRan
}

private static TextRange toTextRange(Range<Integer> range) {
checkState(range.lowerBoundType().equals(BoundType.CLOSED) && range.upperBoundType().equals(BoundType.OPEN));
com.palantir.logsafe.Preconditions.checkState(
range.lowerBoundType().equals(BoundType.CLOSED) && range.upperBoundType().equals(BoundType.OPEN));
return new TextRange(range.lowerEndpoint(), range.upperEndpoint());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.intellij.uiDesigner.core.Spacer;
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.EnabledState;
import com.palantir.javaformat.java.FormatterService;
import com.palantir.logsafe.exceptions.SafeRuntimeException;
import java.awt.Insets;
import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -125,7 +126,7 @@ private String computeFormatterVersion(List<URI> implementationClassPath) {
}
})
.findFirst()
.orElseThrow(() -> new RuntimeException("Couldn't find implementation JAR"));
.orElseThrow(() -> new SafeRuntimeException("Couldn't find implementation JAR"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package com.palantir.javaformat.java;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.palantir.logsafe.Preconditions;

/** An error that prevented formatting from succeeding. */
public class FormatterDiagnostic {
Expand All @@ -30,9 +29,9 @@ public static FormatterDiagnostic create(String message) {
}

public static FormatterDiagnostic create(int lineNumber, int column, String message) {
checkArgument(lineNumber >= 0);
checkArgument(column >= 0);
checkNotNull(message);
Preconditions.checkArgument(lineNumber >= 0);
Preconditions.checkArgument(column >= 0);
Preconditions.checkNotNull(message);
return new FormatterDiagnostic(lineNumber, column, message);
}

Expand Down Expand Up @@ -60,6 +59,7 @@ public String message() {
return message;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (lineNumber >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,25 @@

package com.palantir.javaformat.java;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.Range;
import com.palantir.logsafe.Preconditions;
import java.util.Objects;

/** Data class representing a range in the original source and replacement text for that range. */
public final class Replacement {

public static Replacement create(int startPosition, int endPosition, String replaceWith) {
checkArgument(startPosition >= 0, "startPosition must be non-negative");
checkArgument(startPosition <= endPosition, "startPosition cannot be after endPosition");
Preconditions.checkArgument(startPosition >= 0, "startPosition must be non-negative");
Preconditions.checkArgument(startPosition <= endPosition, "startPosition cannot be after endPosition");
return new Replacement(Range.closedOpen(startPosition, endPosition), replaceWith);
}

private final Range<Integer> replaceRange;
private final String replacementString;

private Replacement(Range<Integer> replaceRange, String replacementString) {
this.replaceRange = checkNotNull(replaceRange, "Null replaceRange");
this.replacementString = checkNotNull(replacementString, "Null replacementString");
this.replaceRange = Preconditions.checkNotNull(replaceRange, "Null replaceRange");
this.replacementString = Preconditions.checkNotNull(replacementString, "Null replacementString");
}

/** The range of characters in the original source to replace. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void add(Op op) {
} else if (op instanceof CloseOp) {
depth--;
if (depth < 0) {
throw new AssertionError();
throw new IllegalStateException();
}
}
ops.add(op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.palantir.javaformat.Indent;
import com.palantir.javaformat.Output;
import com.palantir.javaformat.doc.StartsWithBreakVisitor.Result;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -167,7 +168,7 @@ public State computeBreaks(CommentsHelper commentsHelper, int maxWidth, State st
Level firstLevel = innerLevels.stream()
.filter(doc -> StartsWithBreakVisitor.INSTANCE.visit(doc) != Result.EMPTY)
.findFirst()
.orElseThrow(() -> new IllegalStateException(
.orElseThrow(() -> new SafeIllegalStateException(
"Levels were broken so expected to find at least a non-empty level"));

// Add the width of tokens, breaks before the firstLevel. We must always have space for
Expand Down Expand Up @@ -239,7 +240,7 @@ private Optional<State> tryBreakLastLevel(
splitByBreaks(leadingDocs, splits, breaks);

state = tryToLayOutLevelOnOneLine(commentsHelper, maxWidth, state);
Preconditions.checkState(
com.palantir.logsafe.Preconditions.checkState(
!state.mustBreak, "We messed up, it wants to break a bunch of splits that shouldn't be broken");

// manually add the last level to the last split
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.palantir.javaformat.java.JavaInput.buildToks;

import com.google.common.base.CharMatcher;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -357,7 +356,7 @@ private ImportsAndIndex scanImports(int i) throws FormatterException {

// Produces the sorted output based on the imports we have scanned.
private String reorderedImportsString(ImmutableSortedSet<Import> imports) {
Preconditions.checkArgument(!imports.isEmpty(), "imports");
com.palantir.logsafe.Preconditions.checkArgument(!imports.isEmpty(), "imports");

// Pretend that the first import was preceded by another import of the same kind, so we don't
// insert a newline there.
Expand Down Expand Up @@ -402,7 +401,7 @@ private StringAndIndex scanImported(int start) throws FormatterException {
// At the start of each iteration of this loop, i points to an identifier.
// On exit from the loop, i points to a token after an identifier or after *.
while (true) {
Preconditions.checkState(isIdentifierToken(i));
com.palantir.logsafe.Preconditions.checkState(isIdentifierToken(i));
imported.append(tokenAt(i));
i++;
if (!tokenAt(i).equals(".")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.palantir.javaformat.java;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.getLast;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -33,6 +32,7 @@
import com.palantir.javaformat.Input;
import com.palantir.javaformat.Newlines;
import com.palantir.javaformat.java.JavacTokens.RawTok;
import com.palantir.logsafe.Preconditions;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -260,7 +260,7 @@ public String toString() {
* @throws FormatterException if the input cannot be parsed
*/
public JavaInput(String text) throws FormatterException {
this.text = checkNotNull(text);
this.text = Preconditions.checkNotNull(text);
setLines(ImmutableList.copyOf(Newlines.lineIterator(text)));
ImmutableList<Tok> toks = buildToks(text);
positionToColumnMap = makePositionToColumnMap(toks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;
import com.google.common.collect.PeekingIterator;
import com.google.common.collect.Streams;
Expand All @@ -72,6 +73,7 @@
import com.palantir.javaformat.doc.Token;
import com.palantir.javaformat.java.DimensionHelpers.SortedDims;
import com.palantir.javaformat.java.DimensionHelpers.TypeWithDims;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -483,7 +485,7 @@ public boolean visitArrayInitializer(List<? extends ExpressionTree> expressions)
token("{");
builder.forcedBreak();
boolean first = true;
for (Iterable<? extends ExpressionTree> row : Iterables.partition(expressions, cols)) {
for (Iterable<? extends ExpressionTree> row : Lists.partition(expressions, cols)) {
if (!first) {
builder.forcedBreak();
}
Expand Down Expand Up @@ -1953,7 +1955,7 @@ public Void visitTypeParameter(TypeParameterTree node, Void unused) {

@Override
public Void visitUnionType(UnionTypeTree node, Void unused) {
throw new IllegalStateException("expected manual descent into union types");
throw new SafeIllegalStateException("expected manual descent into union types");
}

@Override
Expand Down Expand Up @@ -2101,7 +2103,7 @@ void visitAndBreakModifiers(

@Override
public Void visitModifiers(ModifiersTree node, Void unused) {
throw new IllegalStateException("expected manual descent into modifiers");
throw new SafeIllegalStateException("expected manual descent into modifiers");
}

/** Output combined modifiers and annotations and returns the trailing break. */
Expand Down Expand Up @@ -2188,7 +2190,7 @@ boolean nextIsModifier() {

@Override
public Void visitCatch(CatchTree node, Void unused) {
throw new IllegalStateException("expected manual descent into catch trees");
throw new SafeIllegalStateException("expected manual descent into catch trees");
}

/** Helper method for {@link CatchTree}s. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
import com.google.common.collect.TreeRangeSet;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -97,7 +98,7 @@ public ImmutableList<Replacement> format(
}
if (includeComments) {
if (kind != SnippetKind.COMPILATION_UNIT) {
throw new IllegalArgumentException("comment formatting is only supported for compilation units");
throw new SafeIllegalArgumentException("comment formatting is only supported for compilation units");
}
return formatter.getFormatReplacements(source, ranges);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static ClassTree getEnclosingTypeDeclaration(TreePath path) {
break;
}
}
throw new AssertionError();
throw new IllegalStateException();
}

/** Skips a single parenthesized tree. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public TyParseState next(JavaCaseFormat n) {
case UPPER_CAMEL:
return TyParseState.TYPE;
}
throw new AssertionError();
throw new IllegalStateException();
}
},

Expand All @@ -59,7 +59,7 @@ public TyParseState next(JavaCaseFormat n) {
case UPPER_CAMEL:
return TyParseState.TYPE;
}
throw new AssertionError();
throw new IllegalStateException();
}
},

Expand Down Expand Up @@ -92,7 +92,7 @@ public TyParseState next(JavaCaseFormat n) {
case UPPER_CAMEL:
return TyParseState.TYPE;
}
throw new AssertionError();
throw new IllegalStateException();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

package com.palantir.javaformat.java;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Joiner;
import com.palantir.logsafe.Preconditions;

/** Checked exception class for formatter command-line usage errors. */
final class UsageException extends Exception {
Expand Down Expand Up @@ -79,7 +78,7 @@ final class UsageException extends Exception {
}

UsageException(String message) {
super(buildMessage(checkNotNull(message)));
super(buildMessage(Preconditions.checkNotNull(message)));
}

private static String buildMessage(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

package com.palantir.javaformat.java.javadoc;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.palantir.logsafe.Preconditions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -31,7 +29,7 @@ final class CharStream {
int toConsume;

CharStream(String input) {
this.remaining = checkNotNull(input);
this.remaining = Preconditions.checkNotNull(input);
}

boolean tryConsume(String expected) {
Expand All @@ -50,7 +48,7 @@ boolean tryConsumeRegex(Pattern pattern) {
if (!matcher.find()) {
return false;
}
checkArgument(matcher.start() == 0);
Preconditions.checkArgument(matcher.start() == 0);
toConsume = matcher.end();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private String render(List<Token> input, int blockIndent) {
throw new AssertionError(token.getType());
}
}
throw new AssertionError();
throw new IllegalStateException();
}

/*
Expand Down
Loading