Skip to content

Commit

Permalink
Excavator: Upgrades Baseline to the latest version (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot committed Jun 20, 2023
1 parent 5d11ccc commit b12cf6a
Show file tree
Hide file tree
Showing 24 changed files with 51 additions and 46 deletions.
6 changes: 4 additions & 2 deletions .baseline/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</module>
<module name="LineLength"> <!-- Java Style Guide: No line-wrapping -->
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://|\{@link"/>
</module>
<module name="TreeWalker">
<module name="SuppressionCommentFilter"/> <!-- baseline-gradle: README.md -->
Expand Down Expand Up @@ -402,7 +402,9 @@
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="CyclomaticComplexity"/> <!-- Java Coding Guidelines: Reduce Cyclomatic Complexity -->
<module name="CyclomaticComplexity"> <!-- Java Coding Guidelines: Reduce Cyclomatic Complexity -->
<property name="switchBlockAsSingleDecisionPoint" value="true"/>
</module>
<module name="DesignForExtension"> <!-- Java Coding Guidelines: Design for extension -->
<property name="ignoredAnnotations" value="ParameterizedTest, Test, Before, BeforeEach, After, AfterEach, BeforeClass, BeforeAll, AfterClass, AfterAll"/>
</module>
Expand Down
3 changes: 3 additions & 0 deletions .baseline/idea/intellij-java-palantir-style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
<package name="" withSubpackages="true" static="false" />
</value>
</option>
<!-- Should be a superset of https://github.com/google/error-prone/blob/c481b3f9c2da112db36ccfcbf64e755261a127ab/core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java#L63 -->
<DO_NOT_IMPORT_INNER>
<CLASS name="Builder" />
<CLASS name="BuilderFactory" />
<CLASS name="Callback" />
<CLASS name="Class" />
<CLASS name="Entry" />
Expand All @@ -54,6 +56,7 @@
<CLASS name="Type" />
<CLASS name="Key" />
<CLASS name="Id" />
<CLASS name="Identifier" />
<CLASS name="Provider" />
</DO_NOT_IMPORT_INNER>
</GroovyCodeStyleSettings>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
dependencies {
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.5.0'
classpath 'com.gradle.publish:plugin-publish-plugin:1.2.0'
classpath 'com.palantir.baseline:gradle-baseline-java:4.145.0'
classpath 'com.palantir.baseline:gradle-baseline-java:5.13.0'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.12.0'
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.12.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:3.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void add(DocBuilder builder) {
builder.open(this);
}

/** @see ImmutableOpenOp.Builder#Builder() */
/** Builder @see ImmutableOpenOp.Builder#Builder(). */
public static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/** An {@code OpsBuilder} creates a list of {@link Op}s, which is turned into a {@link Doc} by {@link DocBuilder}. */
public final class OpsBuilder {

/** @return the actual size of the AST node at position, including comments. */
/** Return the actual size of the AST node at position, including comments. */
public int actualSize(int position, int length) {
Input.Token startToken = input.getPositionTokenMap().get(position);
int start = startToken.getTok().getPosition();
Expand All @@ -66,7 +66,7 @@ public int actualSize(int position, int length) {
return end - start;
}

/** @return the start column of the token at {@code position}, including leading comments. */
/** Return the start column of the token at {@code position}, including leading comments. */
public Integer actualStartColumn(int position) {
Input.Token startToken = input.getPositionTokenMap().get(position);
int start = startToken.getTok().getPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class Output extends InputOutput {
/**
* Output a string.
*
* @param state
* @param state the current state
* @param text the string
* @param range the {@link Range} corresponding to the string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ public abstract class Doc extends HasUniqueId {
static final Range<Integer> EMPTY_RANGE = Range.closedOpen(-1, -1);
static final DiscreteDomain<Integer> INTEGERS = DiscreteDomain.integers();

@SuppressWarnings("Immutable") // Effectively immutable
private final ImmutableSupplier<Float> memoizedWidth = Suppliers.memoize(this::computeWidth)::get;

@SuppressWarnings("Immutable") // Effectively immutable
private final ImmutableSupplier<String> memoizedFlat = Suppliers.memoize(this::computeFlat)::get;

@SuppressWarnings("Immutable") // Effectively immutable
private final ImmutableSupplier<Range<Integer>> memoizedRange = Suppliers.memoize(this::computeRange)::get;

/**
Expand All @@ -51,7 +56,7 @@ final float getWidth() {
}

/**
* Return a {@code Doc}'s flat-string value; not defined (and never called) if the (@code Doc} contains forced
* Return a {@code Doc}'s flat-string value; not defined (and never called) if the {@code Doc} contains forced
* breaks.
*
* @return the flat-string value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public final class Level extends Doc {
private static final Collector<Level, ?, Optional<Level>> GET_LAST_COLLECTOR = Collectors.reducing((u, v) -> v);

private final List<Doc> docs = new ArrayList<>(); // The elements of the level.

@SuppressWarnings("Immutable") // Effectively immutable
private final ImmutableSupplier<SplitsBreaks> memoizedSplitsBreaks =
Suppliers.memoize(() -> splitByBreaks(docs))::get;
/** The immutable characteristics of this level determined before the level contents are available. */
Expand Down Expand Up @@ -147,7 +149,7 @@ private Optional<Integer> tryToFitOnOneLine(int maxWidth, State state, Iterable<
column = newWidth.get();
continue;
}
column += doc.getWidth();
column = (int) (column + doc.getWidth());
}
// Make an additional check that widthBeforeLastBreak fits in the column limit
if (getColumnLimitBeforeLastBreak().isPresent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.palantir.javaformat.doc;

import com.google.common.base.Strings;
import com.palantir.javaformat.BreakBehaviours;
import com.palantir.javaformat.Indent;
import com.palantir.javaformat.LastLevelBreakability;
Expand Down Expand Up @@ -94,6 +93,6 @@ public String visitLevel(Level level) {
}

private void generateIndent(StringBuilder builder) {
builder.append(Strings.repeat(" ", indent));
builder.append(" ".repeat(indent));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ FinishExplorationNode startExplorationNode(
Optional<State> incomingState);

/**
* Write the given level node
* @param levelNodeId the unique ID of the {@link LevelNode}. There can be multiple LevelNodes per
* {@link Level}.
* @param parentExplorationId what exploration is this {@link LevelNode} a part of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Options;
import java.io.IOError;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
Expand Down Expand Up @@ -145,7 +144,7 @@ static JavaOutput format(
.getConstructor(OpsBuilder.class, int.class)
.newInstance(opsBuilder, options.indentationMultiplier());
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
} else {
visitor = new JavaInputAstVisitor(opsBuilder, options.indentationMultiplier());
Expand Down Expand Up @@ -185,7 +184,7 @@ static JCCompilationUnit parseJcCompilationUnit(Context context, String sourceTe
fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.of());
} catch (IOException e) {
// impossible
throw new IOError(e);
throw new RuntimeException(e);
}
SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.palantir.javaformat.java;

import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.palantir.javaformat.CommentsHelper;
import com.palantir.javaformat.Input.Tok;
import com.palantir.javaformat.Newlines;
Expand Down Expand Up @@ -83,7 +82,7 @@ private String preserveIndentation(List<String> lines, int column0) {

// output all trailing lines with plausible indentation
for (int i = 1; i < lines.size(); ++i) {
builder.append(lineSeparator).append(Strings.repeat(" ", column0));
builder.append(lineSeparator).append(" ".repeat(column0));
// check that startCol is valid index, e.g. for blank lines
if (lines.get(i).length() >= startCol) {
builder.append(lines.get(i).substring(startCol));
Expand All @@ -99,7 +98,7 @@ private String indentLineComments(List<String> lines, int column0) {
lines = wrapLineComments(lines, column0);
StringBuilder builder = new StringBuilder();
builder.append(lines.get(0).trim());
String indentString = Strings.repeat(" ", column0);
String indentString = " ".repeat(column0);
for (int i = 1; i < lines.size(); ++i) {
builder.append(lineSeparator)
.append(indentString)
Expand All @@ -120,7 +119,7 @@ private List<String> wrapLineComments(List<String> lines, int column0) {
Matcher matcher = LINE_COMMENT_MISSING_SPACE_PREFIX.matcher(line);
if (matcher.find()) {
int length = matcher.group(1).length();
line = Strings.repeat("/", length) + " " + line.substring(length);
line = "/".repeat(length) + " " + line.substring(length);
}
if (line.startsWith("// MOE:")) {
// don't wrap comments for https://github.com/google/MOE
Expand Down Expand Up @@ -150,7 +149,7 @@ private String indentJavadoc(List<String> lines, int column0) {
StringBuilder builder = new StringBuilder();
builder.append(lines.get(0).trim());
int indent = column0 + 1;
String indentString = Strings.repeat(" ", indent);
String indentString = " ".repeat(indent);
for (int i = 1; i < lines.size(); ++i) {
builder.append(lineSeparator).append(indentString);
String line = lines.get(i).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private static ImmutableMap<Integer, Integer> makePositionToColumnMap(List<Tok>
for (Tok tok : toks) {
builder.put(tok.getPosition(), tok.getColumn());
}
return builder.build();
return builder.buildOrThrow();
}

/**
Expand Down Expand Up @@ -552,7 +552,7 @@ private static boolean isParamComment(Tok tok) {
* @param offset the {@code 0}-based offset in characters
* @param length the length in characters
* @return the {@code 0}-based {@link Range} of tokens
* @throws FormatterException
* @throws FormatterException on formatting errors
*/
Range<Integer> characterRangeToTokenRange(int offset, int length) throws FormatterException {
int requiredLength = offset + length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public Void visitClass(ClassTree tree, Void unused) {
visitEnumDeclaration(tree);
break;
default:
throw new AssertionError(tree.getKind());
throw new IllegalArgumentException(tree.getKind().name());
}
return null;
}
Expand Down Expand Up @@ -941,7 +941,7 @@ public Void visitMemberReference(MemberReferenceTree node, Void unused) {
token("new");
break;
default:
throw new AssertionError(node.getMode());
throw new IllegalArgumentException(node.getMode().name());
}
builder.close();
builder.close();
Expand Down Expand Up @@ -1774,7 +1774,7 @@ public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) {
token("void");
break;
default:
throw new AssertionError(node.getPrimitiveTypeKind());
throw new RuntimeException(node.getPrimitiveTypeKind().name());
}
return null;
}
Expand Down Expand Up @@ -3378,6 +3378,7 @@ enum DeclarationKind {
}

/** Declare one variable or variable-like thing. */
@SuppressWarnings("TooManyArguments")
int declareOne(
DeclarationKind kind,
Direction annotationsDirection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private char[] getRawCharactersReflectively(int beginIndex, int endIndex) {
.getMethod("getRawCharacters", int.class, int.class)
.invoke(instance, beginIndex, endIndex);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.io.ByteStreams;
import com.palantir.javaformat.java.JavaFormatterOptions.Style;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -183,7 +182,7 @@ private int formatStdin(CommandLineOptions parameters, JavaFormatterOptions opti
try {
input = new String(ByteStreams.toByteArray(inStream), UTF_8);
} catch (IOException e) {
throw new IOError(e);
throw new RuntimeException(e);
}
String stdinFilename = parameters.assumeFilename().orElse(STDIN_FILENAME);
boolean ok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Void visitCase(CaseTree tree, Void unused) {
try {
scan((List<? extends Tree>) CASE_TREE_GET_LABELS.invoke(tree), null);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
return super.visitCase(tree, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static java.util.stream.Collectors.joining;

import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -316,10 +315,7 @@ private static String reflow(

return lines.stream()
.collect(joining(
"\""
+ separator
+ Strings.repeat(" ", (first0 ? firstLineStartColumn + 4 : textStartColumn - 2))
+ "+ \"",
"\"" + separator + " ".repeat(first0 ? firstLineStartColumn + 4 : textStartColumn - 2) + "+ \"",
"\"",
"\""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.Pretty;
import com.sun.tools.javac.tree.TreeInfo;
import java.io.IOError;
import java.io.IOException;
import javax.lang.model.element.Name;

Expand Down Expand Up @@ -54,7 +53,7 @@ static String getSourceForNode(Tree node, TreePath path) {
try {
source = path.getCompilationUnit().getSourceFile().getCharContent(false);
} catch (IOException e) {
throw new IOError(e);
throw new RuntimeException(e);
}
return source.subSequence(getStartPosition(node), getEndPosition(node, path))
.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) {
Name name = (Name) invoke(BINDING_PATTERN_TREE_GET_BINDING, node);
visitBindingPattern(/* modifiers= */ null, type, name);
} else {
throw new LinkageError(
throw new RuntimeException(
"BindingPatternTree must have either getVariable() or both getType() and getBinding(),"
+ " but does not");
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public Void visitClass(ClassTree tree, Void unused) {
visitRecordDeclaration(tree);
break;
default:
throw new AssertionError(tree.getKind());
throw new IllegalArgumentException(tree.getKind().name());
}
return null;
}
Expand Down Expand Up @@ -305,7 +305,7 @@ public Void visitCase(CaseTree node, Void unused) {
builder.guessToken(";");
break;
default:
throw new AssertionError(node.getCaseKind());
throw new IllegalArgumentException(node.getCaseKind().name());
}
return null;
}
Expand Down Expand Up @@ -337,7 +337,7 @@ private static Object invoke(Method m, Object target) {
try {
return m.invoke(target);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private String render(List<Token> input, int blockIndent) {
case OPTIONAL_LINE_BREAK:
break;
default:
throw new AssertionError(token.getType());
throw new IllegalArgumentException(token.getType().name());
}
}
throw new IllegalStateException();
Expand Down
Loading

0 comments on commit b12cf6a

Please sign in to comment.