void (@NotNull List<PsiExpression> accesses, @NotNull String typeText, @NonNls String variableName, @NotNull ReplacementMode mode) { final String keyAccess = '(' + typeText + ')' + variableName + ".getKey()"; for (PsiExpression access : accesses) { if (access instanceof PsiMethodCallExpression) { if (!access.isValid()) continue; String replacement = mode == ReplacementMode.VALUES ? variableName : variableName + ".getValue()"; PsiReplacementUtil.replaceExpression(access, replacement); } else { assert mode == ReplacementMode.ENTRY_SET; final PsiTypeCastExpression typeCastExpression = (PsiTypeCastExpression) PsiReplacementUtil.replaceExpressionAndShorten(access, keyAccess); if (RedundantCastUtil.isCastRedundant(typeCastExpression)) { final PsiExpression operand = typeCastExpression.getOperand(); assert operand != null; PsiElement parent = typeCastExpression.getParent(); typeCastExpression.replace(operand); if (parent instanceof PsiParenthesizedExpression) { ParenthesesUtils.removeParentheses((PsiExpression)parent, false); } } } } }