3333import org .sonar .plugins .java .api .tree .MemberSelectExpressionTree ;
3434import org .sonar .plugins .java .api .tree .MethodInvocationTree ;
3535import org .sonar .plugins .java .api .tree .MethodTree ;
36+ import org .sonar .plugins .java .api .tree .PatternInstanceOfTree ;
3637import org .sonar .plugins .java .api .tree .Tree ;
3738import org .sonar .plugins .java .api .tree .TypeCastTree ;
3839
@@ -146,7 +147,14 @@ private static class ExpressionVisitor extends BaseTreeVisitor {
146147
147148 @ Override
148149 public void visitInstanceOf (InstanceOfTree tree ) {
149- if (isArgument (tree .expression (), parameterSymbol )) {
150+ if (isParameter (tree .expression ())) {
151+ typeChecked = true ;
152+ }
153+ }
154+
155+ @ Override
156+ public void visitPatternInstanceOf (PatternInstanceOfTree tree ) {
157+ if (isParameter (tree .expression ())) {
150158 typeChecked = true ;
151159 }
152160 }
@@ -171,7 +179,7 @@ public void visitMethodInvocation(MethodInvocationTree tree) {
171179 }
172180 }
173181 for (ExpressionTree argument : tree .arguments ()) {
174- if (isArgument (argument , parameterSymbol )) {
182+ if (isParameter (argument )) {
175183 typeChecked = true ;
176184 return ;
177185 }
@@ -189,6 +197,10 @@ private boolean isGetClassOnArgument(ExpressionTree tree) {
189197 private boolean isInvocationOnArgument (MethodInvocationTree tree ) {
190198 return tree .methodSelect ().is (Tree .Kind .MEMBER_SELECT ) && isArgument (((MemberSelectExpressionTree ) tree .methodSelect ()).expression (), parameterSymbol );
191199 }
200+
201+ private boolean isParameter (ExpressionTree expressionTree ) {
202+ return isArgument (expressionTree , parameterSymbol );
203+ }
192204 }
193205
194206}
0 commit comments