void (@NotNull PsiInstanceOfExpression expression) { if (!(expression.getPattern() instanceof PsiTypeTestPattern typeTestPattern)) { return; } PsiPatternVariable variable = typeTestPattern.getPatternVariable(); if (variable == null) { return; } String text = expression.getText(); text = text.substring(0, text.length() - typeTestPattern.getTextLength()) + variable.getTypeElement().getText(); CommentTracker tracker = new CommentTracker(); for (PsiElement element : expression.getChildren()) { if (element == typeTestPattern) { continue; } tracker.markUnchanged(element); } PsiReplacementUtil.replaceExpression(expression, text, tracker); }