fun processSubscription()

in psi/src/com/intellij/r/psi/psi/RDataTableAnalyzer.kt [98:162]


  fun processSubscription(operandProcessorRunner: ProcessOperandColumnRunner?,
                          @Suppress("UNUSED_PARAMETER") expression: RExpression,
                          callInfo: TableManipulationCallInfo<*>,
                          processor: Processor<TableColumnInfo>): Boolean {
    val collectProcessor = RTableColumnCollectProcessor()
    if (operandProcessorRunner != null ) {
      operandProcessorRunner(collectProcessor)
    }
    val parameterJ = callInfo.argumentInfo.getArgumentPassedToParameter("j")
    val arguments = ArrayList<PsiElement>()

    when (parameterJ) {
      is RIdentifierExpression -> {
        arguments.add(parameterJ)
      }
      is RCallExpression -> {
        if (parameterJ.isFunctionFromLibrarySoft("c", "base") || parameterJ.isFunctionFromLibrarySoft(".", "plyr")) {
          parameterJ.argumentList.expressionList.forEach{ arguments.add(it) }
        }
      }
      is RAssignmentStatement -> {
        val assignee = parameterJ.getAssignee()
        if (assignee != null) {
          arguments.add(assignee)
        }
      }
    }

    val processedColumns = ArrayList<String>()
    for (argument in arguments) {
      if (argument is RIdentifierExpression) {
        processedColumns.add(argument.text)
        if (!processor.process(TableColumnInfo(argument.text, definition = argument))) {
          return false
        }
      }
      else if (argument is RStringLiteralExpression) {
        val stringValue = argument.name
        if (stringValue != null) {
          processedColumns.add(stringValue)
          if (!processor.process(TableColumnInfo(stringValue, definition = argument))) {
            return false
          }
        }
      }
      else if (argument is RAssignmentStatement && argument.assignee is RIdentifierExpression) {
        val columnName = argument.assignee!!.text
        processedColumns.add(columnName)
        if (argument.assignedValue !is RNullLiteral) {
          if (!processor.process(TableColumnInfo(columnName, definition = argument))) {
            return false
          }
        }
      }
    }

    for (column in collectProcessor.results) {
      if (column.name !in processedColumns) {
        if (!processor.process(column)) {
          return false
        }
      }
    }
    return true
  }