package jetbrains.mps.kotlin.dataFlow;

/*Generated by MPS */

import jetbrains.mps.lang.dataFlow.framework.DataFlowConstructor;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.dataFlow.framework.Program;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.dataFlow.framework.instructions.Instruction;
import jetbrains.mps.kotlin.api.builtins.BuiltIn;
import jetbrains.mps.smodel.builder.SNodeBuilder;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import org.jetbrains.mps.openapi.language.SContainmentLink;

public class ElvisOperator_SmartCast implements DataFlowConstructor {
  public boolean isApplicable(SNode node) {
    SAbstractConcept concept = SNodeOperations.getConcept(node);
    SAbstractConcept applicableConcept = getApplicableConcept();
    return concept.equals(applicableConcept) || concept.isSubConceptOf(applicableConcept);
  }
  public SAbstractConcept getApplicableConcept() {
    return CONCEPTS.ElvisOperator$j5;
  }
  public void performActions(Program o, SNode node) {
    {
      Object object = SLinkOperations.getTarget(node, LINKS.left$yQgK);
      if (((Program) o).contains(object)) {
        boolean before = false;
        int position = ((Program) (o)).getEnd(object);
        Instruction instruction = new isTypeInstruction(SLinkOperations.getTarget(node, LINKS.left$yQgK), createNullableType_z6xg77_b0a0c0b0a0c(BuiltIn.NOTHING.toClassType()), true);
        instruction.setRuleReference("r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/7914615281050728674");
        instruction.setSource(node);
        ((Program) (o)).insert(instruction, position, true, before);
      }
    }
  }
  private static SNode createNullableType_z6xg77_b0a0c0b0a0c(SNode p0) {
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.NullableType$E0);
    n0.forChild(LINKS.type$Tm0J).initNode(p0, CONCEPTS.IType$Ni, true);
    return n0.getResult();
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept ElvisOperator$j5 = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x11400bb7909561c5L, "jetbrains.mps.kotlin.structure.ElvisOperator");
    /*package*/ static final SConcept NullableType$E0 = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28b83021333e575L, "jetbrains.mps.kotlin.structure.NullableType");
    /*package*/ static final SInterfaceConcept IType$Ni = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af441L, "jetbrains.mps.kotlin.structure.IType");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink left$yQgK = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x11400bb790954edfL, 0x11400bb790954ee0L, "left");
    /*package*/ static final SContainmentLink type$Tm0J = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28b83021333e575L, 0x28b83021333ef14L, "type");
  }
}
