Replacer (@NotNull PsiSwitchBlock switchBlock) { if (!(switchBlock instanceof PsiSwitchExpression)) return null; PsiLocalVariable variable = tryCast(switchBlock.getParent(), PsiLocalVariable.class); if (variable == null) return null; return new VariableSavingReplacer(variable); }