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.dataFlow.framework.instructions.Instruction;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SProperty;

public class TypeTest_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.TypeTest$U8;
  }
  public void performActions(Program o, SNode node) {
    {
      Object object = node;
      if (((Program) o).contains(object)) {
        boolean before = false;
        int position = ((Program) (o)).getEnd(object);
        Instruction instruction = new isTypeInstruction(SLinkOperations.getTarget(SNodeOperations.getNodeAncestor(node, CONCEPTS.WhenExpression$iN, false, false), LINKS.target$I2XO), SLinkOperations.getTarget(node, LINKS.type$_0jF), SPropertyOperations.getBoolean(node, PROPS.negation$i74L));
        instruction.setRuleReference("r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/7914615281050753137");
        instruction.setSource(node);
        ((Program) (o)).insert(instruction, position, true, before);
      }
    }
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept TypeTest$U8 = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af41fL, "jetbrains.mps.kotlin.structure.TypeTest");
    /*package*/ static final SConcept WhenExpression$iN = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af532L, "jetbrains.mps.kotlin.structure.WhenExpression");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink target$I2XO = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af532L, 0x11400bb790af49eaL, "target");
    /*package*/ static final SContainmentLink type$_0jF = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af41fL, 0x28bef6d7551af6fcL, "type");
  }

  private static final class PROPS {
    /*package*/ static final SProperty negation$i74L = MetaAdapterFactory.getProperty(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af41fL, 0x11400bb7909c9e30L, "negation");
  }
}
