@@ -1130,7 +1130,17 @@ deprecated class ParExpr extends Expr, @parexpr {
11301130/** An `instanceof` expression. */
11311131class InstanceOfExpr extends Expr , @instanceofexpr {
11321132 /** Gets the expression on the left-hand side of the `instanceof` operator. */
1133- Expr getExpr ( ) { result .isNthChildOf ( this , 0 ) }
1133+ Expr getExpr ( ) {
1134+ if isPattern ( )
1135+ then result = getLocalVariableDeclExpr ( ) .getInit ( )
1136+ else result .isNthChildOf ( this , 0 )
1137+ }
1138+
1139+ /** Holds if this `instanceof` expression uses pattern matching. */
1140+ predicate isPattern ( ) { exists ( getLocalVariableDeclExpr ( ) ) }
1141+
1142+ /** Gets the local variable declaration of this `instanceof` expression if pattern matching is used. */
1143+ LocalVariableDeclExpr getLocalVariableDeclExpr ( ) { result .isNthChildOf ( this , 0 ) }
11341144
11351145 /** Gets the access to the type on the right-hand side of the `instanceof` operator. */
11361146 Expr getTypeName ( ) { result .isNthChildOf ( this , 1 ) }
@@ -1161,6 +1171,8 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
11611171 exists ( ForStmt fs | fs .getAnInit ( ) = this | result .isNthChildOf ( fs , 0 ) )
11621172 or
11631173 exists ( EnhancedForStmt efs | efs .getVariable ( ) = this | result .isNthChildOf ( efs , - 1 ) )
1174+ or
1175+ exists ( InstanceOfExpr ioe | this .getParent ( ) = ioe | result .isNthChildOf ( ioe , 1 ) )
11641176 }
11651177
11661178 /** Gets the name of the variable declared by this local variable declaration expression. */
0 commit comments