@@ -1130,7 +1130,17 @@ deprecated class ParExpr extends Expr, @parexpr {
1130
1130
/** An `instanceof` expression. */
1131
1131
class InstanceOfExpr extends Expr , @instanceofexpr {
1132
1132
/** 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 ) }
1134
1144
1135
1145
/** Gets the access to the type on the right-hand side of the `instanceof` operator. */
1136
1146
Expr getTypeName ( ) { result .isNthChildOf ( this , 1 ) }
@@ -1161,6 +1171,8 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
1161
1171
exists ( ForStmt fs | fs .getAnInit ( ) = this | result .isNthChildOf ( fs , 0 ) )
1162
1172
or
1163
1173
exists ( EnhancedForStmt efs | efs .getVariable ( ) = this | result .isNthChildOf ( efs , - 1 ) )
1174
+ or
1175
+ exists ( InstanceOfExpr ioe | this .getParent ( ) = ioe | result .isNthChildOf ( ioe , 1 ) )
1164
1176
}
1165
1177
1166
1178
/** Gets the name of the variable declared by this local variable declaration expression. */
0 commit comments