private void generateInstanceOfInstructions(@NotNull PsiElement context,
                         @Nullable DfaAnchor instanceofAnchor,
                         @NotNull PsiType checkType,
                         @Nullable PsiType patternType) {
    checkType = TypeConversionUtil.erasure(checkType);
    if (patternType == null ||
        ((checkType instanceof PsiPrimitiveType || patternType instanceof PsiPrimitiveType) &&
         (!PsiUtil.isAvailable(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, context) || !TypeConversionUtil.areTypesConvertible(checkType, patternType)))) {
      addInstruction(new PopInstruction());
      pushUnknown();
      return;
    }
    if (checkType instanceof PsiPrimitiveType && patternType instanceof PsiPrimitiveType) {
      if (checkType.equals(patternType) || JavaPsiPatternUtil.isExactPrimitiveWideningConversion(checkType, patternType)) {
        addInstruction(new PopInstruction());
        addInstruction(new PushValueInstruction(DfTypes.booleanValue(true)));
        if (instanceofAnchor != null) {
          addInstruction(new ResultOfInstruction(instanceofAnchor));
        }
      }
      else {
        generateExactTestingConversion(context, checkType, patternType, instanceofAnchor);
      }
    }
    else if (patternType instanceof PsiPrimitiveType patternPrimitiveType) {
      PsiPrimitiveType unboxedCheckedType = PsiPrimitiveType.getUnboxedType(checkType);
      if (unboxedCheckedType != null) {
        boolean isWideningConversion = JavaPsiPatternUtil.isExactPrimitiveWideningConversion(unboxedCheckedType, patternPrimitiveType) ||
                                       unboxedCheckedType.equals(patternPrimitiveType);
        if (!isWideningConversion) {
          addInstruction(new DupInstruction());
        }
        addInstruction(new PushValueInstruction(DfTypes.NULL));
        addInstruction(new BooleanBinaryInstruction(RelationType.NE, false,
                                                    isWideningConversion ? instanceofAnchor : null));
        if (!isWideningConversion) {
          CFGBuilder builder = new CFGBuilder(this) //checkValue resultNotNull
            .push(DfTypes.booleanValue(false)) //checkValue resultNotNull false
            .ifCondition(RelationType.EQ) //checkValue
            .pop() //
            .push(DfTypes.booleanValue(false)) //false
            .elseBranch(); //checkValue
          generateBoxingUnboxingInstructionFor(context, checkType, unboxedCheckedType, false);
          generateInstanceOfInstructions(context, null, unboxedCheckedType, patternPrimitiveType);
          builder
            .end();
          if (instanceofAnchor != null) {
            addInstruction(new ResultOfInstruction(instanceofAnchor));
          }
        }
      }
      else {
        PsiClassType boxedType = patternPrimitiveType.getBoxedType(context);
        addInstruction(new PushValueInstruction(DfTypes.typedObject(boxedType, Nullability.NOT_NULL)));
        addInstruction(new InstanceofInstruction(instanceofAnchor, false));
      }
    }
    else {
      if (checkType instanceof PsiPrimitiveType checkPrimitiveType) {
        PsiClassType boxedType = checkPrimitiveType.getBoxedType(context);
        generateBoxingUnboxingInstructionFor(context, checkType, boxedType, false);
      }
      addInstruction(new PushValueInstruction(DfTypes.typedObject(patternType, Nullability.NOT_NULL)));
      addInstruction(new InstanceofInstruction(instanceofAnchor, false));
    }
  }
private void generateInstanceOfInstructions(@NotNull PsiElement context,
                         @Nullable DfaAnchor instanceofAnchor,
                         @NotNull PsiType checkType,
                         @Nullable PsiType patternType)