Skip to content

Commit 340605d

Browse files
Excavator: Upgrades Baseline to the latest version (palantir#1359)
1 parent a950ca3 commit 340605d

7 files changed

Lines changed: 37 additions & 44 deletions

File tree

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
dependencies {
88
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
99
classpath 'com.gradle.publish:plugin-publish-plugin:1.3.1'
10-
classpath 'com.palantir.baseline:gradle-baseline-java:6.41.0'
10+
classpath 'com.palantir.baseline:gradle-baseline-java:6.42.0'
1111
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.35.0'
1212
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.19.0'
1313
classpath 'com.palantir.gradle.failure-reports:gradle-failure-reports:1.14.0'

‎palantir-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static Tree extractDims(Deque<List<AnnotationTree>> dims, Tree node) {
107107
return extractDims(dims, ((ArrayTypeTree) node).getType());
108108
case ANNOTATED_TYPE:
109109
AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree) node;
110-
if (annotatedTypeTree.getUnderlyingType().getKind() != Tree.Kind.ARRAY_TYPE) {
110+
if (!(annotatedTypeTree.getUnderlyingType() instanceof ArrayTypeTree)) {
111111
return node;
112112
}
113113
node = extractDims(dims, annotatedTypeTree.getUnderlyingType());

‎palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ public String toString() {
253253
* output.
254254
*/
255255

256+
@SuppressWarnings("for-rollout:AlmostJavadoc")
256257
private final ImmutableMap<Integer, Integer> positionToColumnMap; // Map Tok position to column.
258+
257259
private final ImmutableList<Token> tokens; // The Tokens for this input.
258260
private final ImmutableRangeMap<Integer, Token> positionTokenMap; // Map position to Token.
259261

‎palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java‎

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,10 @@
3030
import static com.palantir.javaformat.java.Trees.precedence;
3131
import static com.palantir.javaformat.java.Trees.skipParen;
3232
import static com.sun.source.tree.Tree.Kind.ANNOTATION;
33-
import static com.sun.source.tree.Tree.Kind.ARRAY_ACCESS;
34-
import static com.sun.source.tree.Tree.Kind.ASSIGNMENT;
3533
import static com.sun.source.tree.Tree.Kind.BLOCK;
3634
import static com.sun.source.tree.Tree.Kind.EXTENDS_WILDCARD;
37-
import static com.sun.source.tree.Tree.Kind.IF;
3835
import static com.sun.source.tree.Tree.Kind.METHOD_INVOCATION;
39-
import static com.sun.source.tree.Tree.Kind.NEW_ARRAY;
40-
import static com.sun.source.tree.Tree.Kind.NEW_CLASS;
4136
import static com.sun.source.tree.Tree.Kind.STRING_LITERAL;
42-
import static com.sun.source.tree.Tree.Kind.UNION_TYPE;
43-
import static com.sun.source.tree.Tree.Kind.VARIABLE;
4437
import static java.util.stream.Collectors.toList;
4538

4639
import com.google.common.base.MoreObjects;
@@ -370,7 +363,7 @@ public Void visitCompilationUnit(CompilationUnitTree node, Void unused) {
370363
}
371364
dropEmptyDeclarations();
372365
for (Tree type : node.getTypeDecls()) {
373-
if (type.getKind() == Tree.Kind.IMPORT) {
366+
if (type instanceof ImportTree) {
374367
// javac treats extra semicolons in the import list as type declarations
375368
// TODO(cushon): remove this if https://bugs.openjdk.java.net/browse/JDK-8027682 is fixed
376369
continue;
@@ -501,7 +494,7 @@ public boolean visitArrayInitializer(List<? extends ExpressionTree> expressions)
501494
if (!first) {
502495
builder.forcedBreak();
503496
}
504-
builder.open(row.iterator().next().getKind() == NEW_ARRAY || cols == 1 ? ZERO : plusFour);
497+
builder.open(row.iterator().next() instanceof NewArrayTree || cols == 1 ? ZERO : plusFour);
505498
boolean firstInRow = true;
506499
for (ExpressionTree item : row) {
507500
if (!firstInRow) {
@@ -753,7 +746,7 @@ public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
753746
token("do");
754747
visitStatement(
755748
node.getStatement(), CollapseEmptyOrNot.YES, AllowLeadingBlankLine.YES, AllowTrailingBlankLine.YES);
756-
if (node.getStatement().getKind() == BLOCK) {
749+
if (node.getStatement() instanceof BlockTree) {
757750
builder.space();
758751
} else {
759752
builder.breakOp(" ");
@@ -1006,12 +999,11 @@ public Void visitForLoop(ForLoopTree node, Void unused) {
1006999
token("(");
10071000
builder.open(plusFour);
10081001
builder.open(
1009-
node.getInitializer().size() > 1
1010-
&& node.getInitializer().get(0).getKind() == Tree.Kind.EXPRESSION_STATEMENT
1002+
node.getInitializer().size() > 1 && node.getInitializer().get(0) instanceof ExpressionStatementTree
10111003
? plusFour
10121004
: ZERO);
10131005
if (!node.getInitializer().isEmpty()) {
1014-
if (node.getInitializer().get(0).getKind() == VARIABLE) {
1006+
if (node.getInitializer().get(0) instanceof VariableTree) {
10151007
PeekingIterator<StatementTree> it =
10161008
Iterators.peekingIterator(node.getInitializer().iterator());
10171009
visitVariables(variableFragments(it, it.next()), DeclarationKind.NONE, Direction.HORIZONTAL);
@@ -1071,7 +1063,7 @@ public Void visitIf(IfTree node, Void unused) {
10711063
while (true) {
10721064
expressions.add(node.getCondition());
10731065
statements.add(node.getThenStatement());
1074-
if (node.getElseStatement() != null && node.getElseStatement().getKind() == IF) {
1066+
if (node.getElseStatement() != null && node.getElseStatement() instanceof IfTree) {
10751067
node = (IfTree) node.getElseStatement();
10761068
} else {
10771069
break;
@@ -1105,7 +1097,7 @@ public Void visitIf(IfTree node, Void unused) {
11051097
CollapseEmptyOrNot.valueOf(onlyClause),
11061098
AllowLeadingBlankLine.YES,
11071099
AllowTrailingBlankLine.valueOf(trailingClauses));
1108-
followingBlock = statements.get(i).getKind() == BLOCK;
1100+
followingBlock = statements.get(i) instanceof BlockTree;
11091101
first = false;
11101102
}
11111103
if (node.getElseStatement() != null) {
@@ -1269,7 +1261,7 @@ protected void visitLambdaExpression(LambdaExpressionTree node, boolean statemen
12691261
builder.breakOp(" ");
12701262
}
12711263

1272-
if (node.getBody().getKind() == Tree.Kind.BLOCK) {
1264+
if (node.getBody() instanceof BlockTree) {
12731265
visitBlock(
12741266
(BlockTree) node.getBody(),
12751267
CollapseEmptyOrNot.YES,
@@ -1339,7 +1331,7 @@ private static boolean isArrayValue(ExpressionTree argument) {
13391331
}
13401332

13411333
public void visitAnnotationArgument(AssignmentTree node) {
1342-
boolean isArrayInitializer = node.getExpression().getKind() == NEW_ARRAY;
1334+
boolean isArrayInitializer = node.getExpression() instanceof NewArrayTree;
13431335
sync(node);
13441336
builder.open(
13451337
isArrayInitializer ? ZERO : plusFour,
@@ -1494,7 +1486,7 @@ public Void visitMethod(MethodTree node, Void unused) {
14941486
if (node.getDefaultValue() != null) {
14951487
builder.space();
14961488
token("default");
1497-
if (node.getDefaultValue().getKind() == Tree.Kind.NEW_ARRAY) {
1489+
if (node.getDefaultValue() instanceof NewArrayTree) {
14981490
builder.open(minusFour);
14991491
{
15001492
builder.space();
@@ -1810,10 +1802,10 @@ boolean visitSingleMemberAnnotation(AnnotationTree node) {
18101802
return false;
18111803
}
18121804
ExpressionTree value = getOnlyElement(node.getArguments());
1813-
if (value.getKind() == ASSIGNMENT) {
1805+
if (value instanceof AssignmentTree) {
18141806
return false;
18151807
}
1816-
boolean isArrayInitializer = value.getKind() == NEW_ARRAY;
1808+
boolean isArrayInitializer = value instanceof NewArrayTree;
18171809
builder.open(
18181810
isArrayInitializer ? ZERO : plusFour,
18191811
BreakBehaviours.preferBreakingLastInnerLevel(true),
@@ -1845,7 +1837,7 @@ public Void visitCase(CaseTree node, Void unused) {
18451837
token(":");
18461838
}
18471839
boolean isBlock =
1848-
node.getStatements().size() == 1 && node.getStatements().get(0).getKind() == BLOCK;
1840+
node.getStatements().size() == 1 && node.getStatements().get(0) instanceof BlockTree;
18491841
builder.open(isBlock ? ZERO : plusTwo);
18501842
if (isBlock) {
18511843
builder.space();
@@ -2318,7 +2310,7 @@ private void visitCatchClause(CatchTree node, AllowTrailingBlankLine allowTraili
23182310
token("(");
23192311
builder.open(plusFour);
23202312
VariableTree ex = node.getParameter();
2321-
if (ex.getType().getKind() == UNION_TYPE) {
2313+
if (ex.getType() instanceof UnionTypeTree) {
23222314
builder.open(ZERO);
23232315
visitUnionType(ex);
23242316
builder.close();
@@ -2641,7 +2633,7 @@ void visitDot(ExpressionTree node0) {
26412633
LOOP:
26422634
do {
26432635
stack.addFirst(node);
2644-
if (node.getKind() == ARRAY_ACCESS) {
2636+
if (node instanceof ArrayAccessTree) {
26452637
node = getArrayBase(node);
26462638
}
26472639
switch (node.getKind()) {
@@ -2671,7 +2663,7 @@ void visitDot(ExpressionTree node0) {
26712663
if (node != null) {
26722664
// Exception: if it's an anonymous class declaration, we don't need to
26732665
// break and indent after the trailing '}'.
2674-
if (node.getKind() == NEW_CLASS && ((NewClassTree) node).getClassBody() != null) {
2666+
if (node instanceof NewClassTree && ((NewClassTree) node).getClassBody() != null) {
26752667
builder.open(ZERO);
26762668
scan(getArrayBase(node), null);
26772669
token(".");
@@ -2707,7 +2699,7 @@ void visitDot(ExpressionTree node0) {
27072699
{
27082700
for (int i = 0; i < items.size(); i++) {
27092701
ExpressionTree expression = items.get(i);
2710-
if (expression.getKind() == METHOD_INVOCATION) {
2702+
if (expression instanceof MethodInvocationTree) {
27112703
if (i > 0 || node != null) {
27122704
// we only want dereference invocations
27132705
invocationCount++;
@@ -2832,7 +2824,7 @@ private boolean fillFirstArgument(ExpressionTree e, List<ExpressionTree> items,
28322824
return false;
28332825
}
28342826
// don't special-case calls nested inside expressions
2835-
if (e.getKind() != METHOD_INVOCATION) {
2827+
if (!(e instanceof MethodInvocationTree)) {
28362828
return false;
28372829
}
28382830
MethodInvocationTree methodInvocation = (MethodInvocationTree) e;
@@ -2869,7 +2861,7 @@ private void visitDotWithPrefix(
28692861
@SuppressWarnings("for-rollout:NullAway")
28702862
boolean trailingDereferences = !prefixes.isEmpty() && getLast(prefixes) < items.size() - 1;
28712863

2872-
boolean hasMethodInvocations = items.stream().anyMatch(expr -> expr.getKind() == METHOD_INVOCATION);
2864+
boolean hasMethodInvocations = items.stream().anyMatch(expr -> expr instanceof MethodInvocationTree);
28732865

28742866
builder.open(OpenOp.builder()
28752867
.debugName("visitDotWithPrefix")
@@ -2939,15 +2931,15 @@ private void visitDotWithPrefix(
29392931
* Whereas an expression like a name {@code com.palantir.foo.bar.Baz} would not.
29402932
*/
29412933
private boolean shouldHaveColumnLimit(ExpressionTree expr) {
2942-
return getArrayBase(expr).getKind() == METHOD_INVOCATION;
2934+
return getArrayBase(expr) instanceof MethodInvocationTree;
29432935
}
29442936

29452937
/** Returns the simple names of expressions in a "." chain. */
29462938
private List<String> simpleNames(Deque<ExpressionTree> stack) {
29472939
ImmutableList.Builder<String> simpleNames = ImmutableList.builder();
29482940
OUTER:
29492941
for (ExpressionTree expression : stack) {
2950-
boolean isArray = expression.getKind() == ARRAY_ACCESS;
2942+
boolean isArray = expression instanceof ArrayAccessTree;
29512943
expression = getArrayBase(expression);
29522944
switch (expression.getKind()) {
29532945
case MEMBER_SELECT:
@@ -3327,7 +3319,7 @@ private int argumentsAreTabular(List<? extends ExpressionTree> arguments) {
33273319
static int rowLength(List<? extends ExpressionTree> row) {
33283320
int size = 0;
33293321
for (ExpressionTree tree : row) {
3330-
if (tree.getKind() != NEW_ARRAY) {
3322+
if (!(tree instanceof NewArrayTree)) {
33313323
size++;
33323324
continue;
33333325
}
@@ -3482,8 +3474,7 @@ int declareOne(
34823474
if (initializer.isPresent()) {
34833475
builder.space();
34843476
token(equals);
3485-
if (initializer.get().getKind() == Tree.Kind.NEW_ARRAY
3486-
&& ((NewArrayTree) initializer.get()).getType() == null) {
3477+
if (initializer.get() instanceof NewArrayTree && ((NewArrayTree) initializer.get()).getType() == null) {
34873478
builder.open(minusFour);
34883479
builder.space();
34893480
initializer.get().accept(this, null);
@@ -3659,15 +3650,15 @@ protected void addBodyDeclarations(
36593650
builder.forcedBreak();
36603651
@SuppressWarnings("for-rollout:NullAway")
36613652
boolean thisOneGetsBlankLineBefore =
3662-
bodyDeclaration.getKind() != VARIABLE || hasJavaDoc(bodyDeclaration);
3653+
!(bodyDeclaration instanceof VariableTree) || hasJavaDoc(bodyDeclaration);
36633654
if (first) {
36643655
builder.blankLineWanted(PRESERVE);
36653656
} else if (!first && (thisOneGetsBlankLineBefore || lastOneGotBlankLineBefore)) {
36663657
builder.blankLineWanted(YES);
36673658
}
36683659
markForPartialFormat();
36693660

3670-
if (bodyDeclaration.getKind() == VARIABLE) {
3661+
if (bodyDeclaration instanceof VariableTree) {
36713662
visitVariables(
36723663
variableFragments(it, bodyDeclaration),
36733664
DeclarationKind.FIELD,
@@ -3727,10 +3718,10 @@ private void classDeclarationTypeList(String token, List<? extends Tree> types)
37273718
@SuppressWarnings("for-rollout:NullAway")
37283719
private List<VariableTree> variableFragments(PeekingIterator<? extends Tree> it, Tree first) {
37293720
List<VariableTree> fragments = new ArrayList<>();
3730-
if (first.getKind() == VARIABLE) {
3721+
if (first instanceof VariableTree) {
37313722
int start = getStartPosition(first);
37323723
fragments.add((VariableTree) first);
3733-
while (it.hasNext() && it.peek().getKind() == VARIABLE && getStartPosition(it.peek()) == start) {
3724+
while (it.hasNext() && it.peek() instanceof VariableTree && getStartPosition(it.peek()) == start) {
37343725
fragments.add((VariableTree) it.next());
37353726
}
37363727
}

‎palantir-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.palantir.javaformat.java.java14;
1818

1919
import static com.google.common.collect.ImmutableList.toImmutableList;
20-
import static com.sun.source.tree.Tree.Kind.BLOCK;
2120

2221
import com.google.common.base.Verify;
2322
import com.google.common.collect.ImmutableList;
@@ -38,7 +37,6 @@
3837
import com.sun.source.tree.ModuleTree;
3938
import com.sun.source.tree.SwitchExpressionTree;
4039
import com.sun.source.tree.Tree;
41-
import com.sun.source.tree.Tree.Kind;
4240
import com.sun.source.tree.VariableTree;
4341
import com.sun.source.tree.YieldTree;
4442
import com.sun.tools.javac.code.Flags;
@@ -301,8 +299,8 @@ public Void visitCase(CaseTree node, Void unused) {
301299
switch (node.getCaseKind()) {
302300
case STATEMENT:
303301
token(":");
304-
boolean isBlock = node.getStatements().size() == 1
305-
&& node.getStatements().get(0).getKind() == BLOCK;
302+
boolean isBlock =
303+
node.getStatements().size() == 1 && node.getStatements().get(0) instanceof BlockTree;
306304
builder.open(isBlock ? ZERO : plusTwo);
307305
if (isBlock) {
308306
builder.space();
@@ -315,7 +313,7 @@ public Void visitCase(CaseTree node, Void unused) {
315313
builder.space();
316314
token("-");
317315
token(">");
318-
if (node.getBody().getKind() == BLOCK) {
316+
if (node.getBody() instanceof BlockTree) {
319317
builder.close();
320318
builder.space();
321319
// Explicit call with {@link CollapseEmptyOrNot.YES} to handle empty case blocks.
@@ -348,7 +346,7 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) {
348346
sync(node);
349347
// Also format switch expressions as statement body instead of inlining them
350348
boolean statementBody = node.getBodyKind() == LambdaExpressionTree.BodyKind.STATEMENT
351-
|| node.getBody().getKind() == Kind.SWITCH_EXPRESSION;
349+
|| node.getBody() instanceof SwitchExpressionTree;
352350
visitLambdaExpression(node, statementBody);
353351
return null;
354352
}

‎palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ boolean tryConsume(String expected) {
4545
/*
4646
* @param pattern the pattern to search for, which must be anchored to match only at position 0
4747
*/
48+
@SuppressWarnings("for-rollout:AlmostJavadoc")
4849
boolean tryConsumeRegex(Pattern pattern) {
4950
Matcher matcher = pattern.matcher(remaining);
5051
if (!matcher.find()) {

‎palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ private static boolean hasMultipleNewlines(String s) {
552552
* with matching only one character here. That would eliminate the need for the regex entirely.
553553
* That might be faster or slower than what we do now.
554554
*/
555+
@SuppressWarnings("for-rollout:AlmostJavadoc")
555556
private static final Pattern LITERAL_PATTERN = compile("^.[^ \t\n@<{}*]*", DOTALL);
556557

557558
private static Pattern fullCommentPattern() {

0 commit comments

Comments
 (0)