PsiExpression (@NotNull PsiExpression expression, @NotNull TypeEvaluator evaluator) { Stack<PsiMethodCallExpression> methodChainStack = new Stack<>(); PsiMethodCallExpression current = (PsiMethodCallExpression) expression; while (current != null) { methodChainStack.add(current); final PsiExpression qualifier = current.getMethodExpression().getQualifierExpression(); current = qualifier instanceof PsiMethodCallExpression ? (PsiMethodCallExpression)qualifier : null; } if (methodChainStack.size() != myMethodDescriptors.size()) { return expression; } PsiExpression converted = null; for (TypeConversionDescriptorBase descriptor : myMethodDescriptors) { final PsiMethodCallExpression toConvert = methodChainStack.pop(); converted = descriptor.replace(toConvert, evaluator); } return converted; }