fun transformExpression()

in psi/src/com/intellij/r/psi/psi/TableManipulationAnalyzer.kt [276:325]


  fun transformExpression(expression: RExpression,
                          command: StringBuilder,
                          runtimeInfo: RConsoleRuntimeInfo,
                          preserveRows: Boolean = false) {
    val callInfo = getCallInfo(expression, runtimeInfo)
    if (callInfo != null && callInfo.function.havePassedTableArguments(callInfo.argumentInfo)) {
      val function = callInfo.function
      if (function.ignoreInTransform) {
        callInfo.passedTableArguments.firstOrNull()?.let { transformExpression(it, command, runtimeInfo, preserveRows) }
        return
      }

      val preserveRowsInArgs = if (function.rowsOmittingUnavailable) true else preserveRows
      val transformArguments = { arguments: List<RExpression> ->
        arguments.forEachIndexed { index, argument ->
          if (index != 0) command.append(",")
          if (callInfo.isTableArgument(argument)) {
            transformExpression(argument, command, runtimeInfo, preserveRowsInArgs)
          }
          else {
            if (argument is RNamedArgument) {
              val argumentValue = argument.assignedValue
              val argumentText =
                if (argumentValue != null && isSafe(argumentValue, runtimeInfo)) argumentValue.text
                else "NA"
              command.append(argument.identifyingElement?.text).append("=").append(argumentText)
            }
            else {
              command.append(if (isSafe(argument, runtimeInfo)) argument.text else "")
            }
          }
        }
      }

      if (function == subscriptionOperator || function == doubleSubscriptionOperator) {
        transformExpression(callInfo.argumentInfo.expressionListWithPipeExpression[0], command, runtimeInfo, preserveRowsInArgs)
        command.append(if (function == subscriptionOperator) "[" else "[[")
        transformArguments(callInfo.argumentInfo.expressionListWithPipeExpression.drop(1))
        command.append(if (function == subscriptionOperator) "]" else "]]")
      }
      else {
        command.append("$packageName::")
        command.append(function.functionName)
        command.append("(")
        transformArguments(callInfo.argumentInfo.expressionListWithPipeExpression)
        command.append(")")
      }
    }
    else transformNotCall(expression, command, runtimeInfo, preserveRows)
  }