@@ -366,8 +366,8 @@ private boolean inExpression() {
366366 public Void scan (Tree tree , Void unused ) {
367367 // Pre-visit AST for preview features, since com.sun.source.tree.AnyPattern can't be
368368 // accessed directly without --enable-preview.
369- if (tree instanceof JCTree .JCAnyPattern ) {
370- visitJcAnyPattern (( JCTree . JCAnyPattern ) tree );
369+ if (tree instanceof JCTree .JCAnyPattern jcAnyPattern ) {
370+ visitJcAnyPattern (jcAnyPattern );
371371 return null ;
372372 }
373373 inExpression .addLast (tree instanceof ExpressionTree || inExpression .peekLast ());
@@ -890,8 +890,8 @@ public boolean visitEnumDeclaration(ClassTree node) {
890890 ArrayList <VariableTree > enumConstants = new ArrayList <>();
891891 ArrayList <Tree > members = new ArrayList <>();
892892 for (Tree member : node .getMembers ()) {
893- if (member instanceof JCTree .JCVariableDecl ) {
894- JCTree . JCVariableDecl variableDecl = ( JCTree . JCVariableDecl ) member ;
893+ if (member instanceof JCTree .JCVariableDecl variableDecl ) {
894+
895895 if ((variableDecl .mods .flags & Flags .ENUM ) == Flags .ENUM ) {
896896 enumConstants .add (variableDecl );
897897 continue ;
@@ -1426,8 +1426,8 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
14261426 builder .breakOp (" " );
14271427 }
14281428 }
1429- if (argument instanceof AssignmentTree ) {
1430- visitAnnotationArgument (( AssignmentTree ) argument );
1429+ if (argument instanceof AssignmentTree assignmentTree ) {
1430+ visitAnnotationArgument (assignmentTree );
14311431 } else {
14321432 scan (argument , null );
14331433 }
@@ -1447,11 +1447,11 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
14471447 }
14481448
14491449 private static boolean isArrayValue (ExpressionTree argument ) {
1450- if (!(argument instanceof AssignmentTree )) {
1450+ if (!(argument instanceof AssignmentTree assignmentTree )) {
14511451 return false ;
14521452 }
1453- ExpressionTree expression = (( AssignmentTree ) argument ) .getExpression ();
1454- return expression instanceof NewArrayTree && (( NewArrayTree ) expression ) .getType () == null ;
1453+ ExpressionTree expression = assignmentTree .getExpression ();
1454+ return expression instanceof NewArrayTree newArrayTree && newArrayTree .getType () == null ;
14551455 }
14561456
14571457 public void visitAnnotationArgument (AssignmentTree node ) {
@@ -1474,8 +1474,8 @@ public void visitAnnotationArgument(AssignmentTree node) {
14741474 public Void visitAnnotatedType (AnnotatedTypeTree node , Void unused ) {
14751475 sync (node );
14761476 ExpressionTree base = node .getUnderlyingType ();
1477- if (base instanceof MemberSelectTree ) {
1478- MemberSelectTree selectTree = ( MemberSelectTree ) base ;
1477+ if (base instanceof MemberSelectTree selectTree ) {
1478+
14791479 scan (selectTree .getExpression (), null );
14801480 token ("." );
14811481 visitAnnotations (node .getAnnotations (), BreakOrNot .NO , BreakOrNot .NO );
@@ -1757,10 +1757,10 @@ private static List<Long> handleStream(List<ExpressionTree> parts) {
17571757 return indexes (
17581758 parts .stream (),
17591759 p -> {
1760- if (!(p instanceof MethodInvocationTree )) {
1760+ if (!(p instanceof MethodInvocationTree methodInvocationTree )) {
17611761 return false ;
17621762 }
1763- Name name = getMethodName (( MethodInvocationTree ) p );
1763+ Name name = getMethodName (methodInvocationTree );
17641764 return Stream .of ("stream" , "parallelStream" , "toBuilder" )
17651765 .anyMatch (name ::contentEquals );
17661766 })
@@ -2119,8 +2119,8 @@ public Void visitTry(TryTree node, Void unused) {
21192119 if (afterFirstToken ) {
21202120 builder .forcedBreak ();
21212121 }
2122- if (resource instanceof VariableTree ) {
2123- VariableTree variableTree = ( VariableTree ) resource ;
2122+ if (resource instanceof VariableTree variableTree ) {
2123+
21242124 declareOne (
21252125 DeclarationKind .PARAMETER ,
21262126 fieldAnnotationDirection (variableTree .getModifiers ()),
@@ -2642,10 +2642,10 @@ private void formatAnnotationOrModifier(Deque<AnnotationOrModifier> modifiers) {
26422642
26432643 boolean isTypeAnnotation (AnnotationTree annotationTree ) {
26442644 Tree annotationType = annotationTree .getAnnotationType ();
2645- if (!(annotationType instanceof IdentifierTree )) {
2645+ if (!(annotationType instanceof IdentifierTree identifierTree )) {
26462646 return false ;
26472647 }
2648- return typeAnnotationSimpleNames .contains ((( IdentifierTree ) annotationType ) .getName ());
2648+ return typeAnnotationSimpleNames .contains (identifierTree .getName ());
26492649 }
26502650
26512651 private static boolean isModifier (String token ) {
@@ -2748,8 +2748,8 @@ private static void walkInfix(
27482748 ExpressionTree expression ,
27492749 List <ExpressionTree > operands ,
27502750 List <String > operators ) {
2751- if (expression instanceof BinaryTree ) {
2752- BinaryTree binaryTree = ( BinaryTree ) expression ;
2751+ if (expression instanceof BinaryTree binaryTree ) {
2752+
27532753 if (precedence (binaryTree ) == precedence ) {
27542754 walkInfix (precedence , binaryTree .getLeftOperand (), operands , operators );
27552755 operators .add (operatorName (expression ));
@@ -3325,9 +3325,11 @@ private static ExpressionTree getArrayBase(ExpressionTree node) {
33253325 return node ;
33263326 }
33273327
3328- private static ExpressionTree getMethodReceiver (MethodInvocationTree methodInvocation ) {
3328+ private static @ Nullable ExpressionTree getMethodReceiver (MethodInvocationTree methodInvocation ) {
33293329 ExpressionTree select = methodInvocation .getMethodSelect ();
3330- return select instanceof MemberSelectTree ? ((MemberSelectTree ) select ).getExpression () : null ;
3330+ return select instanceof MemberSelectTree memberSelectTree
3331+ ? memberSelectTree .getExpression ()
3332+ : null ;
33313333 }
33323334
33333335 private void dotExpressionArgsAndParen (
0 commit comments