@@ -273,14 +273,14 @@ private static String prettyPrint(
273273 } else if (caseIr .instanceOfOptional ().isPresent ()) {
274274 InstanceOfIr instanceOfIr = caseIr .instanceOfOptional ().get ();
275275 sb .append ("case " );
276- if (instanceOfIr .patternVariable () != null ) {
276+ if (instanceOfIr .patternVariable (). isPresent () ) {
277277 sb .append (
278278 printRawTypesAsWildcards (
279- getType (instanceOfIr .patternVariable ()), state , suggestedFixBuilder ));
279+ getType (instanceOfIr .patternVariable (). get () ), state , suggestedFixBuilder ));
280280
281- Symbol sym = ASTHelpers .getSymbol (instanceOfIr .patternVariable ());
281+ Symbol sym = ASTHelpers .getSymbol (instanceOfIr .patternVariable (). get () );
282282 sb .append (" " ).append (sym .getSimpleName ()).append (" " );
283- } else if (instanceOfIr .type () != null && instanceOfIr . expression () != null ) {
283+ } else if (instanceOfIr .expression (). isPresent () ) {
284284 sb .append (
285285 printRawTypesAsWildcards (getType (instanceOfIr .type ()), state , suggestedFixBuilder ));
286286 // It's possible that "unused" could conflict with an existing local variable name;
@@ -441,6 +441,7 @@ private Optional<List<CaseIr>> maybeFixDefaultNullAndUnconditional(
441441
442442 boolean hasDefault = cases .stream ().anyMatch (CaseIr ::hasDefault );
443443 boolean hasCaseNull = cases .stream ().anyMatch (CaseIr ::hasCaseNull );
444+ // NOMUTANTS -- this is a performance optimization
444445 boolean recheckDominanceNeeded = false ;
445446
446447 boolean switchOnNullWouldImplicitlyThrow = switchOnNullWouldImplicitlyThrow (subject , cases );
@@ -1062,7 +1063,9 @@ private static Optional<ExpressionTree> validateInstanceofForSubject(
10621063 /* hasDefault= */ false ,
10631064 /* instanceOfOptional= */ Optional .of (
10641065 new InstanceOfIr (
1065- instanceOfTree .getExpression (), bpt .getVariable (), instanceOfTree .getType ())),
1066+ Optional .ofNullable (instanceOfTree .getExpression ()),
1067+ Optional .ofNullable (bpt .getVariable ()),
1068+ instanceOfTree .getType ())),
10661069 /* guardOptional= */ Optional .empty (),
10671070 /* expressionsOptional= */ Optional .empty (),
10681071 /* arrowRhsOptional= */ arrowRhsOptional ,
@@ -1099,7 +1102,10 @@ private static Optional<ExpressionTree> validateInstanceofForSubject(
10991102 /* hasCaseNull= */ false ,
11001103 /* hasDefault= */ false ,
11011104 /* instanceOfOptional= */ Optional .of (
1102- new InstanceOfIr (instanceOfTree .getExpression (), null , instanceOfTree .getType ())),
1105+ new InstanceOfIr (
1106+ Optional .ofNullable (instanceOfTree .getExpression ()),
1107+ Optional .empty (),
1108+ instanceOfTree .getType ())),
11031109 /* guardOptional= */ Optional .empty (),
11041110 /* expressionsOptional= */ Optional .empty (),
11051111 /* arrowRhsOptional= */ arrowRhsOptional ,
@@ -1520,8 +1526,8 @@ public static boolean isDominatedBy(
15201526 // Cannot unbox LHS pattern, so RHS primitive constant should come before it
15211527 return true ;
15221528 }
1523- } else if (instanceOfIr .patternVariable () != null ) {
1524- VariableTree patternVariable = instanceOfIr .patternVariable ();
1529+ } else if (instanceOfIr .patternVariable (). isPresent () ) {
1530+ VariableTree patternVariable = instanceOfIr .patternVariable (). get () ;
15251531 Type patternType = getType (patternVariable );
15261532 if (isSubtype (getType (constantExpression ), patternType , state )) {
15271533 // RHS constant can be assigned to LHS pattern
@@ -1598,12 +1604,12 @@ public static boolean isDominatedBy(
15981604 Type lhsType =
15991605 lhs .instanceOfOptional ().get ().type () != null
16001606 ? getType (lhs .instanceOfOptional ().get ().type ())
1601- : getType (lhs .instanceOfOptional ().get ().patternVariable ().getType ());
1607+ : getType (lhs .instanceOfOptional ().get ().patternVariable ().get (). getType ());
16021608 var rhsInstanceOf = rhs .instanceOfOptional ().get ();
16031609 Type rhsType =
16041610 rhsInstanceOf .type () != null
16051611 ? getType (rhsInstanceOf .type ())
1606- : getType (rhsInstanceOf .patternVariable ().getType ());
1612+ : getType (rhsInstanceOf .patternVariable ().get (). getType ());
16071613 if (isSubtype (rhsType , lhsType , state )) {
16081614 // The LHS type is a subtype of the RHS type, so the LHS dominates the RHS
16091615 return true ;
@@ -1620,9 +1626,9 @@ public static boolean isDominatedBy(
16201626 */
16211627 record InstanceOfIr (
16221628 // In the example above, the expression would be `y`.
1623- @ Nullable ExpressionTree expression ,
1629+ Optional < ExpressionTree > expression ,
16241630 // In the example above, the variable tree would be `Y y`.
1625- @ Nullable VariableTree patternVariable ,
1631+ Optional < VariableTree > patternVariable ,
16261632 // In the example above, the type would be `Y`.
16271633 Tree type ) {
16281634
0 commit comments