package jetbrains.mps.kotlin.dataFlow;

/*Generated by MPS */

import jetbrains.mps.lang.dataFlow.DataFlowBuilder;
import jetbrains.mps.lang.dataFlow.DataFlowBuilderContext;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.kotlin.behavior.MemberReceiver;
import jetbrains.mps.kotlin.behavior.IFunctionCall__BehaviorDescriptor;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.kotlin.behavior.InferredTypeReference;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class IFunctionCall_DataFlow extends DataFlowBuilder {
  public void build(final DataFlowBuilderContext _context) {
    // Overloaded operators: receiver is included (if your function is in the same case, override this rule)
    if (SNodeOperations.isInstanceOf(_context.getNode(), CONCEPTS.IOverloadableOperator$Wi)) {
      MemberReceiver receiver = IFunctionCall__BehaviorDescriptor.getReceiver_id5D4bOjrrgiZ.invoke(_context.getNode());
      if (receiver != null) {
        Sequence.fromIterable(receiver.getTypeReferences()).visitAll((it) -> {
          if (it instanceof InferredTypeReference) {
            _context.getBuilder().build((SNode) ((InferredTypeReference) it).getNode());
          }
        });
      }
    }

    // Regular function call
    Sequence.fromIterable(IFunctionCall__BehaviorDescriptor.getArguments_id1VI7K1jROBX.invoke(_context.getNode())).select((it) -> it.getExpression()).visitAll((it) -> _context.getBuilder().build((SNode) it));
  }

  private static final class CONCEPTS {
    /*package*/ static final SInterfaceConcept IOverloadableOperator$Wi = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x45d70ebd55a93439L, "jetbrains.mps.kotlin.structure.IOverloadableOperator");
  }
}
