String (PsiExpression expression) { if (expression instanceof PsiMethodCallExpression methodCallExpression) { final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final String name = methodExpression.getReferenceName(); if (name == null) { return null; } if (name.startsWith("to") && name.length() > 2) { return StringUtil.decapitalize(name.substring(2)); } else if (name.startsWith("get") && name.length() > 3) { return StringUtil.decapitalize(name.substring(3)); } else { return name; } } else if (expression instanceof PsiTypeCastExpression castExpression) { final PsiExpression operand = castExpression.getOperand(); return getVariableName(operand); } else if (expression instanceof PsiArrayAccessExpression arrayAccessExpression) { final PsiExpression arrayExpression = arrayAccessExpression.getArrayExpression(); final String name = getVariableName(arrayExpression); return (name == null) ? null : StringUtil.unpluralize(name); } else if (expression instanceof PsiParenthesizedExpression parenthesizedExpression) { final PsiExpression innerExpression = parenthesizedExpression.getExpression(); return getVariableName(innerExpression); } else if (expression instanceof PsiJavaCodeReferenceElement referenceElement) { final String referenceName = referenceElement.getReferenceName(); if (referenceName == null) { return expression.getText(); } return referenceName; } return null; }